def test_glob_metrics_cached(self): metrics = ["a", "a.b", "x.y.z"] for name in metrics: metric = bg_test_utils.make_metric(name) self.accessor.create_metric(metric) self.flush() cache = bg_accessor_cache.MemoryCache(10, 60) original_cache = self.accessor.cache self.accessor.cache = cache def assert_find(glob, results): res = self.accessor.glob_metric_names(glob) self.assertEqual(set(results), set(res)) # Nothing should be cached here. assert_find('**', metrics) assert_find('a', ['a']) assert_find('{x,y}.*y.[z]', ['x.y.z']) # Things should be cached here. assert_find('**', metrics) assert_find('a', ['a']) assert_find('{x,y}.*y.[z]', ['x.y.z']) # Make sure we use the cache. self.accessor.cache.get = lambda _, version: ['fake'] assert_find('a', ['fake']) assert_find('**', ['fake']) assert_find('{x,y}.*y.[z]', ['fake']) self.accessor.cache = original_cache
def test_glob_metrics_cached(self): if isinstance(self.accessor, bg_elasticsearch._ElasticSearchAccessor): # TODO (t.chataigner) Remove once accessor.cache is implemented. self.skipTest( "accessor.cache is not implemented for _ElasticSearchAccessor." ) metrics = ["a", "a.b", "x.y.z"] for name in metrics: metric = bg_test_utils.make_metric(name) self.accessor.create_metric(metric) self.flush() cache = bg_accessor_cache.MemoryCache(10, 60) original_cache = self.accessor.cache self.accessor.cache = cache def assert_find(glob, results): res = self.accessor.glob_metric_names(glob) self.assertEqual(set(results), set(res)) # Nothing should be cached here. assert_find("**", metrics) assert_find("a", ["a"]) assert_find("{x,y}.*y.[z]", ["x.y.z"]) # Things should be cached here. assert_find("**", metrics) assert_find("a", ["a"]) assert_find("{x,y}.*y.[z]", ["x.y.z"]) # Make sure we use the cache. self.accessor.cache.get = lambda _, version: ["fake.foo.a"] assert_find("fake.foo.a", ["fake.foo.a"]) assert_find("**", ["fake.foo.a"]) assert_find("{fake,feke}.*oo.[a]", ["fake.foo.a"]) self.accessor.cache = original_cache
def setUp(self): self.cache = bg_accessor_cache.MemoryCache(10, 3600)