def test_get_index_all_failed(self): # all finders failed store = Store(finders=[TestFinder()]) with patch('graphite.storage.log.info') as log_info: with self.assertRaisesRegexp(Exception, 'All requests failed for get_index'): store.get_index() self.assertEqual(log_info.call_count, 1) self.assertRegexpMatches( log_info.call_args[0][0], 'Exception during get_index after [-.e0-9]+s: TestFinder.find_nodes' ) store = Store(finders=[TestFinder(), TestFinder()]) with patch('graphite.storage.log.info') as log_info: with self.assertRaisesRegexp( Exception, r'All requests failed for get_index \(2\)'): store.get_index() self.assertEqual(log_info.call_count, 2) self.assertRegexpMatches( log_info.call_args[0][0], 'Exception during get_index after [-.e0-9]+s: TestFinder.find_nodes' )
def test_get_index_all_failed(self): # all finders failed store = Store(finders=[TestFinder()]) with patch('graphite.storage.log.debug') as log_debug: with self.assertRaisesRegexp(Exception, 'All index lookups failed'): store.get_index() self.assertEqual(log_debug.call_count, 1) self.assertRegexpMatches( log_debug.call_args[0][0], 'Find for <FindQuery: a from \* until \*> failed after [-.e0-9]+s: TestFinder.find_nodes' )
def test_get_index_pool_timeout(self): # pool timeout store = Store(finders=[RemoteFinder()]) def mock_pool_exec(pool, jobs, timeout): raise PoolTimeoutError() with patch('graphite.storage.pool_exec', mock_pool_exec): with patch('graphite.storage.log.info') as log_info: with self.assertRaisesRegexp(Exception, 'Timed out after .*'): store.get_index() self.assertEqual(log_info.call_count, 1) self.assertRegexpMatches(log_info.call_args[0][0], 'Timed out after [-.e0-9]+s')
def test_get_index_pool_timeout(self): # pool timeout store = Store( finders=[RemoteFinder()] ) def mock_pool_exec(pool, jobs, timeout): raise PoolTimeoutError() with patch('graphite.storage.pool_exec', mock_pool_exec): with patch('graphite.storage.log.info') as log_info: with self.assertRaisesRegexp(Exception, 'Timed out after .*'): store.get_index() self.assertEqual(log_info.call_count, 1) self.assertRegexpMatches(log_info.call_args[0][0], 'Timed out after [-.e0-9]+s')
def test_get_index(self): disabled_finder = DisabledFinder() # use get_finders so legacy_finder is patched with get_index legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0] test_finder = TestFinder() remote_finder = RemoteFinder() store = Store(finders=[ disabled_finder, legacy_finder, test_finder, remote_finder ], tagdb='graphite.tags.localdatabase.LocalDatabaseTagDB') # get index result = store.get_index() self.assertEqual(result, ['a.b.c.d', 'a.b.c.e']) # get local index result = store.get_index({'localOnly': True}) self.assertEqual(result, ['a.b.c.d'])
def test_get_index(self): disabled_finder = DisabledFinder() # use get_finders so legacy_finder is patched with get_index legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0] test_finder = TestFinder() remote_finder = RemoteFinder() store = Store( finders=[disabled_finder, legacy_finder, test_finder, remote_finder], tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB') ) # get index result = store.get_index() self.assertEqual(result, ['a.b.c.d', 'a.b.c.e']) # get local index result = store.get_index({'localOnly': True}) self.assertEqual(result, ['a.b.c.d'])
def test_get_index_all_failed(self): # all finders failed store = Store( finders=[TestFinder()] ) with patch('graphite.storage.log.info') as log_info: with self.assertRaisesRegexp(Exception, 'All requests failed for get_index'): store.get_index() self.assertEqual(log_info.call_count, 1) self.assertRegexpMatches(log_info.call_args[0][0], 'Exception during get_index after [-.e0-9]+s: TestFinder.find_nodes') store = Store( finders=[TestFinder(), TestFinder()] ) with patch('graphite.storage.log.info') as log_info: with self.assertRaisesRegexp(Exception, 'All requests failed for get_index \(2\)'): store.get_index() self.assertEqual(log_info.call_count, 2) self.assertRegexpMatches(log_info.call_args[0][0], 'Exception during get_index after [-.e0-9]+s: TestFinder.find_nodes')