def test_fetch_all_failed(self):
        # all finds failed
        store = Store(finders=[TestFinder()])

        message = r'All requests failed for fetch for \[\'a\'\] \(1\)'
        with patch('graphite.storage.log.info') as log_info:
            with self.assertRaisesRegexp(Exception, message):
                list(store.fetch(['a'], 1, 2, 3, {}))
            self.assertEqual(log_info.call_count, 1)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                r'Exception during fetch for \[\'a\'\] after [-.e0-9]+s: TestFinder.find_nodes'
            )

        store = Store(finders=[TestFinder(), TestFinder()])

        message = r'All requests failed for fetch for \[\'a\'\] \(2\)'
        with patch('graphite.storage.log.info') as log_info:
            with self.assertRaisesRegexp(Exception, message):
                list(store.fetch(['a'], 1, 2, 3, {}))
            self.assertEqual(log_info.call_count, 2)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                r'Exception during fetch for \[\'a\'\] after [-.e0-9]+s: TestFinder.find_nodes'
            )
Beispiel #2
0
    def test_fetch_all_failed(self):
        # all finds failed
        store = Store(finders=[TestFinder()])

        with patch('graphite.storage.log.info') as log_info:
            with self.assertRaisesRegexp(
                    Exception,
                    'Fetch for \[\'a\'\] failed: TestFinder.find_nodes'):
                list(store.fetch(['a'], 1, 2, 3, {}))
            self.assertEqual(log_info.call_count, 1)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                'Fetch for \[\'a\'\] failed 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 fetches failed for \[\'a\'\]'):
                list(store.fetch(['a'], 1, 2, 3, {}))
            self.assertEqual(log_info.call_count, 2)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                'Fetch for \[\'a\'\] failed after [-.e0-9]+s: TestFinder.find_nodes'
            )
Beispiel #3
0
    def test_fetch_some_failed_hard_fail_enabled(self):
        # all finds failed
        store = Store(finders=[TestFinder(), RemoteFinder()])

        with patch('graphite.storage.log.info') as log_info:
            with self.assertRaisesRegexp(
                    Exception,
                    '1 request\(s\) failed for fetch for \[\'a\'\] \(2\)'):
                list(store.fetch(['a'], 1, 2, 3, {}))
            self.assertEqual(log_info.call_count, 1)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                'Exception during fetch for \[\'a\'\] 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 fetch for \[\'a\'\] \(2\)'):
                list(store.fetch(['a'], 1, 2, 3, {}))
            self.assertEqual(log_info.call_count, 2)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                'Exception during fetch for \[\'a\'\] after [-.e0-9]+s: TestFinder.find_nodes'
            )
    def test_fetch(self):
        disabled_finder = DisabledFinder()
        legacy_finder = LegacyFinder()
        test_finder = TestFinder()
        remote_finder = RemoteFinder()

        store = Store(finders=[
            disabled_finder, legacy_finder, test_finder, remote_finder
        ],
                      tagdb='graphite.tags.localdatabase.LocalDatabaseTagDB')

        # tagb is properly initialized
        self.assertIsInstance(store.tagdb, LocalDatabaseTagDB)

        # get all enabled finders
        finders = store.get_finders()
        self.assertEqual(list(finders),
                         [legacy_finder, test_finder, remote_finder])

        # get only local finders
        finders = store.get_finders(local=True)
        self.assertEqual(list(finders), [legacy_finder, test_finder])

        # fetch with empty patterns
        result = store.fetch([], 1, 2, 3, {})
        self.assertEqual(result, [])
Beispiel #5
0
  def test_fetch_some_failed(self):
    # some finders failed
    store = Store(
      finders=[TestFinder(), RemoteFinder()]
    )

    with patch('graphite.storage.log.info') as log_info:
      list(store.fetch(['a'], 1, 2, 3, {}))
      self.assertEqual(log_info.call_count, 1)

    store = Store(
      finders=[TestFinder(), TestFinder()]
    )

    with patch('graphite.storage.log.info') as log_info:
      with self.assertRaisesRegexp(Exception, 'All requests failed for fetch for \[\'a\'\] \(2\)'):
        list(store.fetch(['a'], 1, 2, 3, {}))
      self.assertEqual(log_info.call_count, 2)
      self.assertRegexpMatches(log_info.call_args[0][0], 'Exception during fetch for \[\'a\'\] after [-.e0-9]+s: TestFinder.find_nodes')
    def test_fetch(self):
        disabled_finder = get_finders('tests.test_storage.DisabledFinder')[0]
        legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0]
        test_finder = get_finders('tests.test_storage.TestFinder')[0]
        remote_finder = get_finders('tests.test_storage.RemoteFinder')[0]

        store = Store(
            finders=[
                disabled_finder, legacy_finder, test_finder, remote_finder
            ],
            tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB'))

        # tagb is properly initialized
        self.assertIsInstance(store.tagdb, LocalDatabaseTagDB)

        # get all enabled finders
        finders = store.get_finders()
        self.assertEqual(list(finders),
                         [legacy_finder, test_finder, remote_finder])

        # get only local finders
        finders = store.get_finders(local=True)
        self.assertEqual(list(finders), [legacy_finder, test_finder])

        # fetch with empty patterns
        result = store.fetch([], 1, 2, 3, {})
        self.assertEqual(result, [])

        # fetch
        result = store.fetch(['a.**'], 1, 2, 3, {})
        self.assertEqual(len(result), 3)
        result.sort(key=lambda node: node['name'])
        self.assertEqual(result[0]['name'], 'a.b.c.d')
        self.assertEqual(result[0]['pathExpression'], 'a.**')
        self.assertEqual(result[1]['name'], 'a.b.c.d')
        self.assertEqual(result[1]['pathExpression'], 'a.**')
        self.assertEqual(result[2]['name'], 'a.b.c.e')
        self.assertEqual(result[2]['pathExpression'], 'a.**')
    def test_fetch_pool_timeout(self):
        # pool timeout
        store = Store(finders=[RemoteFinder()])

        def mock_pool_exec(pool, jobs, timeout):
            raise PoolTimeoutError()

        message = r'Timed out after [-.e0-9]+s for fetch for \[\'a\'\]'
        with patch('graphite.storage.pool_exec', mock_pool_exec):
            with patch('graphite.storage.log.info') as log_info:
                with self.assertRaisesRegexp(Exception, message):
                    list(store.fetch(['a'], 1, 2, 3, {}))
                self.assertEqual(log_info.call_count, 1)
                self.assertRegexpMatches(log_info.call_args[0][0], message)
Beispiel #8
0
  def test_fetch(self):
    disabled_finder = get_finders('tests.test_storage.DisabledFinder')[0]
    legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0]
    test_finder = get_finders('tests.test_storage.TestFinder')[0]
    remote_finder = get_finders('tests.test_storage.RemoteFinder')[0]

    store = Store(
      finders=[disabled_finder, legacy_finder, test_finder, remote_finder],
      tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB')
    )

    # tagb is properly initialized
    self.assertIsInstance(store.tagdb, LocalDatabaseTagDB)

    # get all enabled finders
    finders = store.get_finders()
    self.assertEqual(list(finders), [legacy_finder, test_finder, remote_finder])

    # get only local finders
    finders = store.get_finders(local=True)
    self.assertEqual(list(finders), [legacy_finder, test_finder])

    # fetch with empty patterns
    result = store.fetch([], 1, 2, 3, {})
    self.assertEqual(result, [])

    # fetch
    result = store.fetch(['a.**'], 1, 2, 3, {})
    self.assertEqual(len(result), 3)
    result.sort(key=lambda node: node['name'])
    self.assertEqual(result[0]['name'], 'a.b.c.d')
    self.assertEqual(result[0]['pathExpression'], 'a.**')
    self.assertEqual(result[1]['name'], 'a.b.c.d')
    self.assertEqual(result[1]['pathExpression'], 'a.**')
    self.assertEqual(result[2]['name'], 'a.b.c.e')
    self.assertEqual(result[2]['pathExpression'], 'a.**')
Beispiel #9
0
  def test_fetch_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.debug') as log_debug:
        with self.assertRaisesRegexp(Exception, 'All fetches failed for \[\'a\'\]'):
          list(store.fetch(['a'], 1, 2, 3, {}))
          self.assertEqual(log_debug.call_count, 1)
          self.assertRegexpMatches(log_debug.call_args[0][0], 'Timed out in fetch after [-.e0-9]+s')
Beispiel #10
0
  def test_fetch_pool_timeout(self):
    # pool timeout
    store = Store(
      finders=[RemoteFinder()]
    )

    def mock_pool_exec(pool, jobs, timeout):
      raise PoolTimeoutError()

    message = 'Timed out after [-.e0-9]+s for fetch for \[\'a\'\]'
    with patch('graphite.storage.pool_exec', mock_pool_exec):
      with patch('graphite.storage.log.info') as log_info:
        with self.assertRaisesRegexp(Exception, message):
          list(store.fetch(['a'], 1, 2, 3, {}))
        self.assertEqual(log_info.call_count, 1)
        self.assertRegexpMatches(log_info.call_args[0][0], message)