Пример #1
0
def consume_and_write_monitoring_events():
    for topic, messages in get_consumer().run():
        if topic != TOPIC.SiteAvailabilityMonitoring:
            logger.info('Received not a monitoring event.')
            continue

        get_storage().write_many(messages)
Пример #2
0
    def test__consumer__run__data_validation__logged_exception(self):
        consumer = get_consumer()

        with mock.patch('consumer.consume.logger') as logger_mock:
            batches = list(consumer.run())

        self.assertEqual(len(batches), 1)
        logger_mock.exception.assert_called_once_with(
            f'Validation error for message against {MonitoredEvent}'
        )
Пример #3
0
    def test_consumer_initialized_globally_with_config(self):
        initialize_consumer(
            MockedConsumer,
            **MOCKED_CONSUMER_CONFIG
        )

        consumer = get_consumer()

        self.assertIsInstance(consumer, MockedConsumer)
        self.assertEqual(consumer._configs, {'custom_config_var': 'test'})
        self.assertEqual(consumer._sleep_interval_seconds, SLEEP_INTERVAL)
        self.assertEqual(consumer._timeout_ms, TIMEOUT_CONSUMER_MS)
Пример #4
0
    def test_consumer_poll(self):
        consumer = get_consumer()

        result = consumer.poll()
        self.maxDiff = None
        self.assertEqual(
            result,
            {
                TOPIC.SiteAvailabilityMonitoring: [
                    MockedConsumer.get_fake_payload(),
                ],
            }
        )
Пример #5
0
    def test_consumer__run_success(self):
        consumer = get_consumer()

        batches = list(consumer.run())

        self.assertEqual(len(batches), 1)
        topic, messages = batches[0]
        self.assertEqual(topic, TOPIC.SiteAvailabilityMonitoring)
        self.assertEqual(len(messages), 1)
        self.maxDiff = None
        self.assertEqual(
            messages[0],
            MonitoredEvent(**MockedConsumer.get_fake_payload())
        )