예제 #1
0
    def test_sorted_strategy_static_cache(self):
        self.metric_cache.store('foo', (123456, 1.0))
        self.metric_cache.store('foo', (123457, 2.0))
        self.metric_cache.store('foo', (123458, 3.0))
        self.metric_cache.store('bar', (123459, 4.0))
        self.metric_cache.store('bar', (123460, 5.0))
        self.metric_cache.store('baz', (123461, 6.0))

        sorted_strategy = SortedStrategy(self.metric_cache)
        # In order from most to least
        self.assertEqual('foo', sorted_strategy.choose_item())
        self.assertEqual('bar', sorted_strategy.choose_item())
        self.assertEqual('baz', sorted_strategy.choose_item())
예제 #2
0
파일: test_cache.py 프로젝트: maraev/carbon
  def test_sorted_strategy_static_cache(self):
    self.metric_cache.store('foo', (123456, 1.0))
    self.metric_cache.store('foo', (123457, 2.0))
    self.metric_cache.store('foo', (123458, 3.0))
    self.metric_cache.store('bar', (123459, 4.0))
    self.metric_cache.store('bar', (123460, 5.0))
    self.metric_cache.store('baz', (123461, 6.0))

    sorted_strategy = SortedStrategy(self.metric_cache)
    # In order from most to least
    self.assertEqual('foo', sorted_strategy.choose_item())
    self.assertEqual('bar', sorted_strategy.choose_item())
    self.assertEqual('baz', sorted_strategy.choose_item())
예제 #3
0
파일: test_cache.py 프로젝트: maraev/carbon
  def test_sorted_strategy_changing_sizes(self):
    self.metric_cache.store('foo', (123456, 1.0))
    self.metric_cache.store('foo', (123457, 2.0))
    self.metric_cache.store('foo', (123458, 3.0))
    self.metric_cache.store('bar', (123459, 4.0))
    self.metric_cache.store('bar', (123460, 5.0))
    self.metric_cache.store('baz', (123461, 6.0))

    sorted_strategy = SortedStrategy(self.metric_cache)
    # In order from most to least foo, bar, baz
    self.assertEqual('foo', sorted_strategy.choose_item())

    # 'baz' gets 2 more, now greater than 'bar'
    self.metric_cache.store('baz', (123461, 6.0))
    self.metric_cache.store('baz', (123461, 6.0))
    # But 'bar' is popped anyway, because sort has already happened
    self.assertEqual('bar', sorted_strategy.choose_item())
    self.assertEqual('baz', sorted_strategy.choose_item())

    # Sort happens again
    self.assertEqual('foo', sorted_strategy.choose_item())
    self.assertEqual('bar', sorted_strategy.choose_item())
    self.assertEqual('baz', sorted_strategy.choose_item())
예제 #4
0
    def test_sorted_strategy_changing_sizes(self):
        self.metric_cache.store('foo', (123456, 1.0))
        self.metric_cache.store('foo', (123457, 2.0))
        self.metric_cache.store('foo', (123458, 3.0))
        self.metric_cache.store('bar', (123459, 4.0))
        self.metric_cache.store('bar', (123460, 5.0))
        self.metric_cache.store('baz', (123461, 6.0))

        sorted_strategy = SortedStrategy(self.metric_cache)
        # In order from most to least foo, bar, baz
        self.assertEqual('foo', sorted_strategy.choose_item())

        # 'baz' gets 2 more, now greater than 'bar'
        self.metric_cache.store('baz', (123461, 6.0))
        self.metric_cache.store('baz', (123461, 6.0))
        # But 'bar' is popped anyway, because sort has already happened
        self.assertEqual('bar', sorted_strategy.choose_item())
        self.assertEqual('baz', sorted_strategy.choose_item())

        # Sort happens again
        self.assertEqual('foo', sorted_strategy.choose_item())
        self.assertEqual('bar', sorted_strategy.choose_item())
        self.assertEqual('baz', sorted_strategy.choose_item())