def test_time_sorted_strategy_min_lag(self): settings = { 'MIN_TIMESTAMP_LAG': 5, } settings_patch = patch.dict('carbon.conf.settings', settings) settings_patch.start() now = time.time() self.metric_cache.store('old', (now - 10, 1.0)) self.metric_cache.store('new', (now, 2.0)) time_sorted_strategy = TimeSortedStrategy(self.metric_cache) self.assertEqual('old', time_sorted_strategy.choose_item()) self.metric_cache.pop('old') self.assertEqual(None, time_sorted_strategy.choose_item())
def test_time_sorted_strategy(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)) time_sorted_strategy = TimeSortedStrategy(self.metric_cache) # In order: foo, bar, baz self.assertEqual('foo', time_sorted_strategy.choose_item()) # 'baz' gets older points. self.metric_cache.store('baz', (123450, 6.0)) self.metric_cache.store('baz', (123451, 6.0)) # But 'bar' is popped anyway, because sort has already happened self.assertEqual('bar', time_sorted_strategy.choose_item()) self.assertEqual('baz', time_sorted_strategy.choose_item()) # Sort happens again self.assertEqual('baz', time_sorted_strategy.choose_item()) self.assertEqual('foo', time_sorted_strategy.choose_item()) self.assertEqual('bar', time_sorted_strategy.choose_item())