diff --git a/test-requirements.txt b/test-requirements.txt index a9c32bec1..718149386 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -12,6 +12,9 @@ testrepository>=0.0.13 testscenarios<0.5 testtools>=0.9.29 +# for test_rabbit +kombu>=2.4.8 + # when we can require tox>= 1.4, this can go into tox.ini: # [testenv:cover] # deps = {[testenv]deps} coverage diff --git a/tests/test_rabbit.py b/tests/test_rabbit.py new file mode 100644 index 000000000..04b90a6ed --- /dev/null +++ b/tests/test_rabbit.py @@ -0,0 +1,59 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo import messaging +from oslo.messaging._drivers import impl_rabbit as rabbit_driver +from oslo.messaging import transport as msg_transport +from tests import utils as test_utils + + +class TestRabbitDriver(test_utils.BaseTestCase): + + def setUp(self): + super(TestRabbitDriver, self).setUp() + self.conf.register_opts(msg_transport._transport_opts) + self.conf.register_opts(rabbit_driver.rabbit_opts) + self.config(rpc_backend='rabbit') + self.config(fake_rabbit=True) + + # FIXME(markmc): this should be a cleanup method on the driver itself + self.addCleanup(rabbit_driver.cleanup) + + def test_driver_load(self): + transport = messaging.get_transport(self.conf) + self.assertTrue(isinstance(transport._driver, + rabbit_driver.RabbitDriver)) + + def test_send_receive(self): + transport = messaging.get_transport(self.conf) + driver = transport._driver + + target = messaging.Target(topic='testtopic') + + listener = driver.listen(target) + + ctxt = {} + message = {'foo': 'bar'} + + driver.send(target, ctxt, message) + + received = listener.poll() + self.assertTrue(received is not None) + self.assertEquals(received.ctxt, {}) + + # FIXME(markmc): this should be done by the driver + received.message.pop('_unique_id') + self.assertEquals(received.message, {'foo': 'bar'})