def test_percentile(): histo = _histogram.Histogram() [histo.add(i) for i in range(101, 201)] assert histo.percentile(100) == 200 assert histo.percentile(101) == 200 assert histo.percentile(99) == 199 assert histo.percentile(1) == 101
def test_contains(): histo = _histogram.Histogram() histo.add(10) histo.add(20) assert 10 in histo assert 20 in histo assert 30 not in histo
def test_min(): histo = _histogram.Histogram() assert histo.min == 10 histo.add(60) assert histo.min == 60 histo.add(30) assert histo.min == 30 histo.add(120) assert histo.min == 30
def test_max(): histo = _histogram.Histogram() assert histo.max == 600 histo.add(120) assert histo.max == 120 histo.add(150) assert histo.max == 150 histo.add(20) assert histo.max == 150
def __init__(self, client, subscription, flow_control=types.FlowControl(), histogram_data=None): self._client = client self._subscription = subscription self._consumer = _consumer.Consumer() self._ack_deadline = 10 self._last_histogram_size = 0 self._future = None self.flow_control = flow_control self.histogram = _histogram.Histogram(data=histogram_data) # These are for internal flow control tracking. # They should not need to be used by subclasses. self._bytes = 0 self._ack_on_resume = set()
def __init__(self, client, subscription, flow_control=types.FlowControl(), histogram_data=None): self._client = client self._subscription = subscription self._consumer = _consumer.Consumer() self._ack_deadline = 10 self._last_histogram_size = 0 self._future = None self.flow_control = flow_control self.histogram = _histogram.Histogram(data=histogram_data) """.Histogram: the histogram tracking ack latency.""" self.leased_messages = {} """dict[str, float]: A mapping of ack IDs to the local time when the ack ID was initially leased in seconds since the epoch.""" # These are for internal flow control tracking. # They should not need to be used by subclasses. self._bytes = 0 self._ack_on_resume = set()
def __init__(self, client, subscription, flow_control=types.FlowControl(), histogram_data=None): """Instantiate the policy. Args: client (~.pubsub_v1.subscriber.client): The subscriber client used to create this instance. subscription (str): The name of the subscription. The canonical format for this is ``projects/{project}/subscriptions/{subscription}``. flow_control (~.pubsub_v1.types.FlowControl): The flow control settings. histogram_data (dict): Optional: A structure to store the histogram data for predicting appropriate ack times. If set, this should be a dictionary-like object. .. note:: Additionally, the histogram relies on the assumption that the dictionary will properly sort keys provided that all keys are positive integers. If you are sending your own dictionary class, ensure this assumption holds or you will get strange behavior. """ self._client = client self._subscription = subscription self._consumer = _consumer.Consumer(self) self._ack_deadline = 10 self._last_histogram_size = 0 self._future = None self.flow_control = flow_control self.histogram = _histogram.Histogram(data=histogram_data) # These are for internal flow control tracking. # They should not need to be used by subclasses. self._bytes = 0 self._ack_on_resume = set() self._paused = False
def test_add_upper_limit(): histo = _histogram.Histogram() histo.add(12000) assert 12000 not in histo assert 600 in histo
def test_add_lower_limit(): histo = _histogram.Histogram() histo.add(5) assert 5 not in histo assert 10 in histo
def test_add(): histo = _histogram.Histogram() histo.add(60) assert histo._data[60] == 1 histo.add(60) assert histo._data[60] == 2
def test_init(): data = {} histo = _histogram.Histogram(data=data) assert histo._data is data assert len(histo) == 0
def create_subscriber(flow_control=types.FlowControl()): subscriber_ = mock.create_autospec(subscriber.Subscriber, instance=True) subscriber_.is_active = True subscriber_.flow_control = flow_control subscriber_.ack_histogram = _histogram.Histogram() return subscriber_