Esempio n. 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())
Esempio n. 2
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())
Esempio n. 3
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())
Esempio n. 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())