Exemplo n.º 1
0
    def testEmittedNonMetricSequence(self):
        key = "bogus-test-key"

        metric_utils.updateLastEmittedNonMetricSequence(key, 1)

        # Cleanup
        self.addCleanup(
            collectorsdb.engineFactory().execute,
            schema.emittedNonMetricTracker.delete().where(
                (schema.emittedNonMetricTracker.c.key == key)))

        lastEmittedSample = metric_utils.queryLastEmittedNonMetricSequence(key)

        self.assertEqual(1, lastEmittedSample)
Exemplo n.º 2
0
  def testUpdateLastEmittedNonMetricSequence(self, collectorsdbMock):

    # Test with 0 rows modified as result

    collectorsdbMock.engineFactory.return_value = Mock(
      spec_set=sqlalchemy.engine.Engine)
    collectorsdbMock.engineFactory.return_value.execute.side_effect = (
      iter([Mock(rowcount=0), Mock()]))

    metric_utils.updateLastEmittedNonMetricSequence("twitter-tweets-volume", 0)

    # Assert that an update was called, followed by an insert
    args, _ = (collectorsdbMock
               .engineFactory
               .return_value
               .execute
               .call_args_list[0])
    self.assertTrue(args)
    self.assertIsInstance(args[0], sqlalchemy.sql.dml.Update)

    args, _ = (collectorsdbMock
               .engineFactory
               .return_value
               .execute
               .call_args_list[1])
    self.assertTrue(args)
    self.assertIsInstance(args[0], sqlalchemy.sql.dml.Insert)


    # Test again with 1 row modified as result

    collectorsdbMock.engineFactory.return_value.execute.reset_mock()

    collectorsdbMock.engineFactory.return_value.execute.side_effect = (
      iter([Mock(rowcount=1), Mock()]))

    metric_utils.updateLastEmittedNonMetricSequence("twitter-tweets-volume", 0)

    # Assert that an update was called, not followed by an insert
    args, _ = (collectorsdbMock
               .engineFactory
               .return_value
               .execute
               .call_args_list[0])
    self.assertTrue(args)
    self.assertIsInstance(args[0], sqlalchemy.sql.dml.Update)

    self.assertEqual(
      collectorsdbMock.engineFactory.return_value.execute.call_count, 1)
  def testEmittedNonMetricSequence(self):
    key = "bogus-test-key"

    metric_utils.updateLastEmittedNonMetricSequence(key, 1)

    # Cleanup
    self.addCleanup(collectorsdb.engineFactory().execute,
      schema.emittedNonMetricTracker.delete().where(
        (schema.emittedNonMetricTracker.c.key == key)
      )
    )

    lastEmittedSample = metric_utils.queryLastEmittedNonMetricSequence(key)

    self.assertEqual(1, lastEmittedSample)
Exemplo n.º 4
0
    def testUpdateLastEmittedNonMetricSequence(self, collectorsdbMock):

        # Test with 0 rows modified as result

        collectorsdbMock.engineFactory.return_value = Mock(
            spec_set=sqlalchemy.engine.Engine)
        collectorsdbMock.engineFactory.return_value.execute.side_effect = (
            iter([Mock(rowcount=0), Mock()]))

        metric_utils.updateLastEmittedNonMetricSequence(
            "twitter-tweets-volume", 0)

        # Assert that an update was called, followed by an insert
        args, _ = (collectorsdbMock.engineFactory.return_value.execute.
                   call_args_list[0])
        self.assertTrue(args)
        self.assertIsInstance(args[0], sqlalchemy.sql.dml.Update)

        args, _ = (collectorsdbMock.engineFactory.return_value.execute.
                   call_args_list[1])
        self.assertTrue(args)
        self.assertIsInstance(args[0], sqlalchemy.sql.dml.Insert)

        # Test again with 1 row modified as result

        collectorsdbMock.engineFactory.return_value.execute.reset_mock()

        collectorsdbMock.engineFactory.return_value.execute.side_effect = (
            iter([Mock(rowcount=1), Mock()]))

        metric_utils.updateLastEmittedNonMetricSequence(
            "twitter-tweets-volume", 0)

        # Assert that an update was called, not followed by an insert
        args, _ = (collectorsdbMock.engineFactory.return_value.execute.
                   call_args_list[0])
        self.assertTrue(args)
        self.assertIsInstance(args[0], sqlalchemy.sql.dml.Update)

        self.assertEqual(
            collectorsdbMock.engineFactory.return_value.execute.call_count, 1)