def test_max_value(): time = MockedTime() counter = RollingNumber(time, 200, 10) # TODO: Change tests to use this aproache for events event = RollingNumberEvent.THREAD_MAX_ACTIVE # We start out with 0 buckets in the queue assert counter.buckets.size == 0 # Increment counter.update_rolling_max(event, 10) # Sleep to get to a new bucket time.increment(counter.buckets_size_in_milliseconds()) # Increment counter.update_rolling_max(event, 30) # Sleep to get to a new bucket time.increment(counter.buckets_size_in_milliseconds()) # Increment counter.update_rolling_max(event, 40) # Sleep to get to a new bucket time.increment(counter.buckets_size_in_milliseconds()) # Try Decrement counter.update_rolling_max(event, 15) # The count should be max counter.update_rolling_max(event, 40)
def test_max_value(): _time = MockedTime() counter = RollingNumber(200, 10, _time=_time) # TODO: Change tests to use this aproache for events event = RollingNumberEvent.THREAD_MAX_ACTIVE # We start out with 0 buckets in the queue assert counter.buckets.size == 0 # Increment counter.update_rolling_max(event, 10) # Sleep to get to a new bucket _time.increment(counter.buckets_size_in_milliseconds()) # Increment counter.update_rolling_max(event, 30) # Sleep to get to a new bucket _time.increment(counter.buckets_size_in_milliseconds()) # Increment counter.update_rolling_max(event, 40) # Sleep to get to a new bucket _time.increment(counter.buckets_size_in_milliseconds()) # Try Decrement counter.update_rolling_max(event, 15) # The count should be max counter.update_rolling_max(event, 40)
def test_update_max_1(): time = MockedTime() counter = RollingNumber(time, 200, 10) # We start out with 0 buckets in the queue assert counter.buckets.size == 0 # Increment counter.update_rolling_max(RollingNumberEvent.THREAD_MAX_ACTIVE, 10) # We should have 1 assert counter.buckets.size == 1 # The count should be 10 assert counter.buckets.last().max_updater(RollingNumberEvent.THREAD_MAX_ACTIVE).max() == 10 assert counter.rolling_max(RollingNumberEvent.THREAD_MAX_ACTIVE) == 10 # Sleep to get to a new bucket time.increment(counter.buckets_size_in_milliseconds() * 3) # Increment again is latest bucket counter.update_rolling_max(RollingNumberEvent.THREAD_MAX_ACTIVE, 20) # We should have 4 assert counter.buckets.size == 4 # The max assert counter.buckets.last().max_updater(RollingNumberEvent.THREAD_MAX_ACTIVE).max() == 20 # Count per buckets values = counter.values(RollingNumberEvent.THREAD_MAX_ACTIVE) assert values[0] == 20 # Latest bucket assert values[1] == 0 assert values[2] == 0 assert values[3] == 10 # Oldest bucket