def test_independent_topics(self): listener_a = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['1'])) listener_b = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['2'])) a = listener_a.notifier('pub-1', topic='1') b = listener_b.notifier('pub-2', topic='2') a_out = [('test-1-%s' % c, 'payload-1-%s' % c) for c in 'abcdefgh'] for event_type, payload in a_out: a.info({}, event_type, payload) b_out = [('test-2-%s' % c, 'payload-2-%s' % c) for c in 'ijklmnop'] for event_type, payload in b_out: b.info({}, event_type, payload) for expected in a_out: actual = listener_a.events.get(timeout=0.5) self.assertEqual('info', actual[0]) self.assertEqual(expected[0], actual[1]) self.assertEqual(expected[1], actual[2]) self.assertEqual('pub-1', actual[3]) for expected in b_out: actual = listener_b.events.get(timeout=0.5) self.assertEqual('info', actual[0]) self.assertEqual(expected[0], actual[1]) self.assertEqual(expected[1], actual[2]) self.assertEqual('pub-2', actual[3])
def test_multiple_servers(self): if self.url.startswith("amqp:"): self.skipTest("QPID-6307") if self.url.startswith("zmq"): self.skipTest("ZeroMQ-PUB-SUB") if self.url.startswith("kafka"): self.skipTest("Kafka: Need to be fixed") listener_a = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['test-topic'])) listener_b = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['test-topic'])) n = listener_a.notifier('pub') events_out = [('test-%s' % c, 'payload-%s' % c) for c in 'abcdefgh'] for event_type, payload in events_out: n.info({}, event_type, payload) events_in = [[(e[1], e[2]) for e in listener_a.get_events()], [(e[1], e[2]) for e in listener_b.get_events()]] self.assertThat(events_in, utils.IsValidDistributionOf(events_out)) for stream in events_in: self.assertThat(len(stream), matchers.GreaterThan(0))
def test_multiple_servers(self): timeout = 0.5 if self.url.startswith("amqp:"): self.skipTest("QPID-6307") if self.url.startswith("kafka://"): self.skipTest("Kafka: needs to be fixed") timeout = 5 self.conf.set_override('consumer_group', 'test_multiple_servers', group='oslo_messaging_kafka') listener_a = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['test-topic'])) listener_b = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['test-topic'])) n = listener_a.notifier('pub') events_out = [('test-%s' % c, 'payload-%s' % c) for c in 'abcdefgh'] for event_type, payload in events_out: n.info({}, event_type, payload) events_in = [[(e[1], e[2]) for e in listener_a.get_events(timeout)], [(e[1], e[2]) for e in listener_b.get_events(timeout)]] self.assertThat(events_in, utils.IsValidDistributionOf(events_out)) for stream in events_in: self.assertThat(len(stream), matchers.GreaterThan(0))
def test_independent_topics(self): listener_a = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['1'])) listener_b = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['2'])) a = listener_a.notifier('pub-1', topics=['1']) b = listener_b.notifier('pub-2', topics=['2']) a_out = [('test-1-%s' % c, 'payload-1-%s' % c) for c in 'abcdefgh'] for event_type, payload in a_out: a.info({}, event_type, payload) b_out = [('test-2-%s' % c, 'payload-2-%s' % c) for c in 'ijklmnop'] for event_type, payload in b_out: b.info({}, event_type, payload) def check_received(listener, publisher, messages): actuals = sorted( [listener.events.get(timeout=0.5) for __ in range(len(a_out))]) expected = sorted([['info', m[0], m[1], publisher] for m in messages]) self.assertEqual(expected, actuals) check_received(listener_a, "pub-1", a_out) check_received(listener_b, "pub-2", b_out)
def test_logging(self): # NOTE(gtt): Using different topic to make tests run in parallel topic = 'test_logging_%s_driver_%s' % (self.priority, self.driver) self.config(driver=[self.driver], topics=[topic], group='oslo_messaging_notifications') listener = self.useFixture( utils.NotificationFixture(self.conf, self.url, [topic])) log_notify = oslo_messaging.LoggingNotificationHandler(self.url) log = logging.getLogger(topic) log.setLevel(logging.DEBUG) log.addHandler(log_notify) log_method = getattr(log, self.priority) log_method('Test logging at priority: %s' % self.priority) events = listener.get_events(timeout=1) self.assertEqual(len(events), 1) info_event = events[0] self.assertEqual(info_event[0], self.priority) self.assertEqual(info_event[1], 'logrecord') for key in ['name', 'thread', 'extra', 'process', 'funcName', 'levelno', 'processName', 'pathname', 'lineno', 'msg', 'exc_info', 'levelname']: self.assertTrue(key in info_event[2])
def test_all_categories(self): get_timeout = 1 if self.url.startswith("kafka://"): get_timeout = 5 self.conf.set_override('consumer_group', 'test_all_categories', group='oslo_messaging_kafka') listener = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['test_all_categories'])) n = listener.notifier('abc') cats = ['debug', 'audit', 'info', 'warn', 'error', 'critical'] events = [(getattr(n, c), c, 'type-' + c, c + '-data') for c in cats] for e in events: e[0]({}, e[2], e[3]) # order between events with different categories is not guaranteed received = {} for expected in events: e = listener.events.get(timeout=get_timeout) received[e[0]] = e for expected in events: actual = received[expected[1]] self.assertEqual(expected[1], actual[0]) self.assertEqual(expected[2], actual[1]) self.assertEqual(expected[3], actual[2])
def test_multiple_topics(self): get_timeout = 1 if self.url.startswith("kafka://"): get_timeout = 5 self.conf.set_override('consumer_group', 'test_multiple_topics', group='oslo_messaging_kafka') listener = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['a', 'b'])) a = listener.notifier('pub-a', topics=['a']) b = listener.notifier('pub-b', topics=['b']) sent = { 'pub-a': [a, 'test-a', 'payload-a'], 'pub-b': [b, 'test-b', 'payload-b'] } for e in sent.values(): e[0].info({}, e[1], e[2]) received = {} while len(received) < len(sent): e = listener.events.get(timeout=get_timeout) received[e[3]] = e for key in received: actual = received[key] expected = sent[key] self.assertEqual('info', actual[0]) self.assertEqual(expected[1], actual[1]) self.assertEqual(expected[2], actual[2])
def test_compression(self): get_timeout = 1 if self.notify_url.startswith("amqp:"): self.conf.set_override('kombu_compression', 'gzip', group='oslo_messaging_rabbit') if self.notify_url.startswith("kafka://"): get_timeout = 5 self.conf.set_override('compression_codec', 'gzip', group='oslo_messaging_kafka') self.conf.set_override('consumer_group', 'test_compression', group='oslo_messaging_kafka') listener = self.useFixture( utils.NotificationFixture(self.conf, self.notify_url, ['test_compression'])) notifier = listener.notifier('abc') notifier.info({}, 'test', 'Hello World!') event = listener.events.get(timeout=get_timeout) self.assertEqual('info', event[0]) self.assertEqual('test', event[1]) self.assertEqual('Hello World!', event[2]) self.assertEqual('abc', event[3])
def test_multiple_topics(self): transport = self.useFixture(utils.TransportFixture(self.url)) listener = self.useFixture( utils.NotificationFixture(transport.transport, ['a', 'b'])) transport.wait() a = listener.notifier('pub-a', topic='a') b = listener.notifier('pub-b', topic='b') sent = { 'pub-a': [a, 'test-a', 'payload-a'], 'pub-b': [b, 'test-b', 'payload-b'] } for e in sent.values(): e[0].info({}, e[1], e[2]) received = {} while len(received) < len(sent): e = listener.events.get(timeout=1) received[e[3]] = e for key in received: actual = received[key] expected = sent[key] self.assertEqual('info', actual[0]) self.assertEqual(expected[1], actual[1]) self.assertEqual(expected[2], actual[2])
def test_simple(self): listener = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['test_simple'])) notifier = listener.notifier('abc') notifier.info({}, 'test', 'Hello World!') event = listener.events.get(timeout=1) self.assertEqual('info', event[0]) self.assertEqual('test', event[1]) self.assertEqual('Hello World!', event[2]) self.assertEqual('abc', event[3])
def test_multiple_servers(self): transport = self.useFixture(utils.TransportFixture(self.url)) listener_a = self.useFixture( utils.NotificationFixture(transport.transport, ['test-topic'])) listener_b = self.useFixture( utils.NotificationFixture(transport.transport, ['test-topic'])) transport.wait() n = listener_a.notifier('pub') events_out = [('test-%s' % c, 'payload-%s' % c) for c in 'abcdefgh'] for event_type, payload in events_out: n.info({}, event_type, payload) events_in = [[(e[1], e[2]) for e in listener_a.get_events()], [(e[1], e[2]) for e in listener_b.get_events()]] self.assertThat(events_in, utils.IsValidDistributionOf(events_out)) for stream in events_in: self.assertThat(len(stream), matchers.GreaterThan(0))
def test_independent_topics(self): get_timeout = 0.5 if self.url.startswith("kafka://"): get_timeout = 5 self.conf.set_override('consumer_group', 'test_independent_topics_a', group='oslo_messaging_kafka') listener_a = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['1'])) if self.url.startswith("kafka://"): self.conf.set_override('consumer_group', 'test_independent_topics_b', group='oslo_messaging_kafka') listener_b = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['2'])) a = listener_a.notifier('pub-1', topics=['1']) b = listener_b.notifier('pub-2', topics=['2']) a_out = [('test-1-%s' % c, 'payload-1-%s' % c) for c in 'abcdefgh'] for event_type, payload in a_out: a.info({}, event_type, payload) b_out = [('test-2-%s' % c, 'payload-2-%s' % c) for c in 'ijklmnop'] for event_type, payload in b_out: b.info({}, event_type, payload) def check_received(listener, publisher, messages): actuals = sorted([ listener.events.get(timeout=get_timeout) for __ in range(len(a_out)) ]) expected = sorted([['info', m[0], m[1], publisher] for m in messages]) self.assertEqual(expected, actuals) check_received(listener_a, "pub-1", a_out) check_received(listener_b, "pub-2", b_out)
def test_simple(self): transport = self.useFixture(utils.TransportFixture(self.url)) listener = self.useFixture( utils.NotificationFixture(transport.transport, ['test_simple'])) transport.wait() notifier = listener.notifier('abc') notifier.info({}, 'test', 'Hello World!') event = listener.events.get(timeout=1) self.assertEqual('info', event[0]) self.assertEqual('test', event[1]) self.assertEqual('Hello World!', event[2]) self.assertEqual('abc', event[3])
def test_simple(self): if self.url.startswith("kafka://"): self.conf.set_override('consumer_group', 'test_simple', group='oslo_messaging_kafka') listener = self.useFixture( utils.NotificationFixture(self.conf, self.url, ['test_simple'])) notifier = listener.notifier('abc') notifier.info({}, 'test', 'Hello World!') event = listener.events.get(timeout=1) self.assertEqual('info', event[0]) self.assertEqual('test', event[1]) self.assertEqual('Hello World!', event[2]) self.assertEqual('abc', event[3])
def test_all_categories(self): listener = self.useFixture(utils.NotificationFixture( self.conf, self.url, ['test_all_categories'])) n = listener.notifier('abc') cats = ['debug', 'audit', 'info', 'warn', 'error', 'critical'] events = [(getattr(n, c), c, 'type-' + c, c + '-data') for c in cats] for e in events: e[0]({}, e[2], e[3]) # order between events with different categories is not guaranteed received = {} for expected in events: e = listener.events.get(timeout=0.5) received[e[0]] = e for expected in events: actual = received[expected[1]] self.assertEqual(expected[1], actual[0]) self.assertEqual(expected[2], actual[1]) self.assertEqual(expected[3], actual[2])
def test_logging(self): # NOTE(gtt): Using different topic to make tests run in parallel topic = 'test_logging_%s_driver_%s' % (self.priority, self.driver) if self.notify_url.startswith("kafka://"): self.conf.set_override('consumer_group', str(uuid.uuid4()), group='oslo_messaging_kafka') self.config(driver=[self.driver], topics=[topic], group='oslo_messaging_notifications') listener = self.useFixture( utils.NotificationFixture(self.conf, self.notify_url, [topic])) log_notify = oslo_messaging.LoggingNotificationHandler(self.notify_url) log = logging.getLogger(topic) log.setLevel(logging.DEBUG) log.addHandler(log_notify) log_method = getattr(log, self.priority) log_method('Test logging at priority: %s' % self.priority) events = listener.get_events(timeout=15) self.assertEqual(1, len(events)) info_event = events[0] self.assertEqual(self.priority, info_event[0]) self.assertEqual('logrecord', info_event[1]) for key in [ 'name', 'thread', 'extra', 'process', 'funcName', 'levelno', 'processName', 'pathname', 'lineno', 'msg', 'exc_info', 'levelname' ]: self.assertIn(key, info_event[2])