1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
19
Unit Tests for remote procedure calls using kombu
22
from nova import context
23
from nova import log as logging
25
from nova.rpc import impl_kombu
26
from nova.tests import test_rpc_common
29
LOG = logging.getLogger('nova.tests.rpc')
32
class RpcKombuTestCase(test_rpc_common._BaseRpcTestCase):
35
super(RpcKombuTestCase, self).setUp()
38
super(RpcKombuTestCase, self).tearDown()
40
def test_reusing_connection(self):
41
"""Test that reusing a connection returns same one."""
42
conn_context = self.rpc.create_connection(new=False)
43
conn1 = conn_context.connection
45
conn_context = self.rpc.create_connection(new=False)
46
conn2 = conn_context.connection
48
self.assertEqual(conn1, conn2)
50
def test_topic_send_receive(self):
51
"""Test sending to a topic exchange/queue"""
53
conn = self.rpc.create_connection()
54
message = 'topic test message'
56
self.received_message = None
58
def _callback(message):
59
self.received_message = message
61
conn.declare_topic_consumer('a_topic', _callback)
62
conn.topic_send('a_topic', message)
66
self.assertEqual(self.received_message, message)
68
def test_direct_send_receive(self):
69
"""Test sending to a direct exchange/queue"""
70
conn = self.rpc.create_connection()
71
message = 'direct test message'
73
self.received_message = None
75
def _callback(message):
76
self.received_message = message
78
conn.declare_direct_consumer('a_direct', _callback)
79
conn.direct_send('a_direct', message)
83
self.assertEqual(self.received_message, message)
85
@test.skip_test("kombu memory transport seems buggy with fanout queues "
86
"as this test passes when you use rabbit (fake_rabbit=False)")
87
def test_fanout_send_receive(self):
88
"""Test sending to a fanout exchange and consuming from 2 queues"""
90
conn = self.rpc.create_connection()
91
conn2 = self.rpc.create_connection()
92
message = 'fanout test message'
94
self.received_message = None
96
def _callback(message):
97
self.received_message = message
99
conn.declare_fanout_consumer('a_fanout', _callback)
100
conn2.declare_fanout_consumer('a_fanout', _callback)
101
conn.fanout_send('a_fanout', message)
103
conn.consume(limit=1)
105
self.assertEqual(self.received_message, message)
107
self.received_message = None
108
conn2.consume(limit=1)
110
self.assertEqual(self.received_message, message)