def test_publish_to_host_without_policy(self):
        publisher = kafka.KafkaBrokerPublisher(self.CONF, netutils.urlsplit(
            'kafka://127.0.0.1:9092?topic=ceilometer'))
        self.assertEqual('default', publisher.policy)

        publisher = kafka.KafkaBrokerPublisher(self.CONF, netutils.urlsplit(
            'kafka://127.0.0.1:9092?topic=ceilometer&policy=test'))
        self.assertEqual('default', publisher.policy)
    def test_publish(self):
        publisher = kafka.KafkaBrokerPublisher(
            netutils.urlsplit('kafka://127.0.0.1:9092?topic=ceilometer'))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            publisher.publish_samples(mock.MagicMock(), self.test_data)
            self.assertEqual(5, len(fake_producer.send_messages.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
    def test_publish_without_options(self):
        publisher = kafka.KafkaBrokerPublisher(
            self.CONF, netutils.urlsplit('kafka://127.0.0.1:9092'))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            publisher.publish_samples(self.test_data)
            self.assertEqual(5, len(fake_producer.send.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
예제 #4
0
    def test_publish_without_options(self):
        publisher = kafka.KafkaBrokerPublisher(
            netutils.urlsplit('kafka://127.0.0.1:9092'))

        with mock.patch.object(publisher, '_send') as fake_send:
            publisher.publish_samples(mock.MagicMock(), self.test_data)
            self.assertEqual(1, len(fake_send.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
    def test_publish_to_host_with_queue_policy(self):
        publisher = kafka.KafkaBrokerPublisher(self.CONF, netutils.urlsplit(
            'kafka://127.0.0.1:9092?topic=ceilometer&policy=queue'))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            fake_producer.send.side_effect = Exception("test")
            publisher.publish_samples(self.test_data)
            self.assertEqual(1, len(fake_producer.send.mock_calls))
            self.assertEqual(1, len(publisher.local_queue))
    def test_publish_to_unreacheable_host_under_queue_policy(self):
        publisher = kafka_publisher.KafkaBrokerPublisher(
            netutils.urlsplit(
                'kafka://127.0.0.1:9092?topic=ceilometer&policy=queue'))

        with mock.patch.object(publisher, '_get_client') as fake_client:
            fake_client.return_value = None
            publisher.publish_samples(mock.MagicMock(), self.test_data)
            self.assertEqual(1, len(publisher.local_queue))
    def test_publish_to_unreacheable_host_under_retry_policy(self):
        publisher = kafka_publisher.KafkaBrokerPublisher(
            netutils.urlsplit(
                'kafka://127.0.0.1:9092?topic=ceilometer&policy=retry'))

        with mock.patch.object(publisher, '_get_client') as fake_client:
            fake_client.return_value = None
            self.assertRaises(TypeError, publisher.publish_samples,
                              (mock.MagicMock(), self.test_data))
예제 #8
0
    def test_publish_to_host_with_drop_policy(self):
        publisher = kafka.KafkaBrokerPublisher(
            netutils.urlsplit(
                'kafka://127.0.0.1:9092?topic=ceilometer&policy=drop'))

        with mock.patch.object(publisher, '_send') as fake_send:
            fake_send.side_effect = Exception("test")
            publisher.publish_samples(mock.MagicMock(), self.test_data)
            self.assertEqual(1, len(fake_send.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
    def test_publish_to_host_with_default_policy(self):
        publisher = kafka.KafkaBrokerPublisher(
            netutils.urlsplit(
                'kafka://127.0.0.1:9092?topic=ceilometer&policy=default'))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            fake_producer.send_messages.side_effect = TypeError
            self.assertRaises(msg_publisher.DeliveryFailure,
                              publisher.publish_samples, self.test_data)
            self.assertEqual(100, len(fake_producer.send_messages.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
예제 #10
0
    def test_publish_to_host_with_default_policy(self):
        publisher = kafka.KafkaBrokerPublisher(
            netutils.urlsplit(
                'kafka://127.0.0.1:9092?topic=ceilometer&policy=default'))

        with mock.patch.object(publisher, '_send') as fake_send:
            fake_send.side_effect = TypeError
            self.assertRaises(TypeError, publisher.publish_samples,
                              mock.MagicMock(), self.test_data)
            self.assertEqual(100, len(fake_send.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
    def test_publish_without_options(self):
        publisher = kafka_publisher.KafkaBrokerPublisher(
            netutils.urlsplit('kafka://127.0.0.1:9092'))
        publisher._get_client = mock.Mock(name="_get_client")
        publisher._get_client.return_value = mock.Mock()

        with mock.patch.object(publisher, '_send') as fake_send:
            fake_send.side_effect = mock.Mock()
            publisher.publish_samples(mock.MagicMock(), self.test_data)
            self.assertEqual(1, len(fake_send.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
    def test_publish_event_with_default_policy(self):
        publisher = kafka.KafkaBrokerPublisher(
            netutils.urlsplit('kafka://127.0.0.1:9092?topic=ceilometer'))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            publisher.publish_events(mock.MagicMock(), self.test_event_data)
            self.assertEqual(5, len(fake_producer.send_messages.mock_calls))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            fake_producer.send_messages.side_effect = Exception("test")
            self.assertRaises(msg_publisher.DeliveryFailure,
                              publisher.publish_events, mock.MagicMock(),
                              self.test_event_data)
            self.assertEqual(100, len(fake_producer.send_messages.mock_calls))
            self.assertEqual(0, len(publisher.local_queue))
    def test_publish_to_down_host_with_default_queue_size(self):
        publisher = kafka.KafkaBrokerPublisher(self.CONF, netutils.urlsplit(
            'kafka://127.0.0.1:9092?topic=ceilometer&policy=queue'))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            fake_producer.send.side_effect = Exception("test")

            for i in range(0, 2000):
                for s in self.test_data:
                    s.name = 'test-%d' % i
                publisher.publish_samples(self.test_data)

            self.assertEqual(1024, len(publisher.local_queue))
            self.assertEqual('test-976',
                             publisher.local_queue[0][1][0]['counter_name'])
            self.assertEqual('test-1999',
                             publisher.local_queue[1023][1][0]['counter_name'])
    def test_publish_to_unreachable_host_with_default_queue_size(self):
        publisher = kafka_publisher.KafkaBrokerPublisher(
            netutils.urlsplit(
                'kafka://127.0.0.1:9092?topic=ceilometer&policy=queue'))

        with mock.patch.object(publisher, '_get_client') as fake_client:
            fake_client.return_value = None
            for i in range(0, 2000):
                for s in self.test_data:
                    s.name = 'test-%d' % i
                publisher.publish_samples(mock.MagicMock(), self.test_data)

            self.assertEqual(1024, len(publisher.local_queue))
            self.assertEqual('test-976',
                             publisher.local_queue[0][0]['counter_name'])
            self.assertEqual('test-1999',
                             publisher.local_queue[1023][0]['counter_name'])
    def test_publish_to_host_from_down_to_up_with_queue(self):
        publisher = kafka.KafkaBrokerPublisher(self.CONF, netutils.urlsplit(
            'kafka://127.0.0.1:9092?topic=ceilometer&policy=queue'))

        with mock.patch.object(publisher, '_producer') as fake_producer:
            fake_producer.send.side_effect = Exception("test")
            for i in range(0, 16):
                for s in self.test_data:
                    s.name = 'test-%d' % i
                publisher.publish_samples(self.test_data)

            self.assertEqual(16, len(publisher.local_queue))

            fake_producer.send.side_effect = None
            for s in self.test_data:
                s.name = 'test-%d' % 16
            publisher.publish_samples(self.test_data)
            self.assertEqual(0, len(publisher.local_queue))
    def test_publish_to_host_from_down_to_up_with_local_queue(self):
        publisher = kafka_publisher.KafkaBrokerPublisher(
            netutils.urlsplit(
                'kafka://127.0.0.1:9092?topic=ceilometer&policy=queue'))

        with mock.patch.object(publisher, "_get_client") as fake_client:
            fake_client.return_value = None
            for i in range(0, 16):
                for s in self.test_data:
                    s.name = 'test-%d' % i
                publisher.publish_samples(mock.MagicMock(), self.test_data)

            self.assertEqual(16, len(publisher.local_queue))

            fake_client.return_value = mock.Mock()

            with mock.patch.object(publisher, '_send') as fake_send:
                fake_send.return_value = mock.Mock()
                for s in self.test_data:
                    s.name = 'test-%d' % 16
                publisher.publish_samples(mock.MagicMock(), self.test_data)
                self.assertEqual(0, len(publisher.local_queue))