1 # Copyright (c) 2018 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from oslo_config import cfg
19 from yardstick.common import messaging
20 from yardstick.common.messaging import producer
21 from yardstick.tests.unit import base as ut_base
24 class _MessagingProducer(producer.MessagingProducer):
28 class MessagingProducerTestCase(ut_base.BaseUnitTestCase):
31 with mock.patch.object(oslo_messaging, 'RPCClient') as \
33 mock.patch.object(oslo_messaging, 'get_rpc_transport') as \
34 mock_get_rpc_transport, \
35 mock.patch.object(oslo_messaging, 'Target') as \
37 mock_get_rpc_transport.return_value = 'test_rpc_transport'
38 mock_Target.return_value = 'test_Target'
40 _MessagingProducer('test_topic', 'test_pid', fanout=True)
41 mock_get_rpc_transport.assert_called_once_with(
42 cfg.CONF, url=messaging.TRANSPORT_URL)
43 mock_Target.assert_called_once_with(
44 topic='test_topic', fanout=True, server=messaging.SERVER)
45 mock_RPCClient.assert_called_once_with('test_rpc_transport',
49 with mock.patch.object(oslo_messaging, 'RPCClient'), \
50 mock.patch.object(oslo_messaging, 'get_rpc_transport'), \
51 mock.patch.object(oslo_messaging, 'Target'):
52 msg_producer = _MessagingProducer('topic', 'id_to_check')
53 self.assertEqual('id_to_check', msg_producer.id)