def test_when_eventlet_module_is_available_then_return_GreenExecutor(self): zmq_async.eventletutils.is_monkey_patched = lambda _: True executor = zmq_async.get_executor('any method') self.assertIsInstance(executor, green_poller.GreenExecutor) self.assertEqual('any method', executor._method)
def __init__(self, driver): self.driver = driver self.listener = None self.executor = zmq_async.get_executor(self._run) self._stop = threading.Event() self._received = threading.Event() self.message = None
def __init__(self, conf): self.conf = conf self._lock = threading.Lock() self._requests = {} self._poller = zmq_async.get_poller() self._executor = zmq_async.get_executor(self._run_loop) self._executor.execute()
def __init__(self, conf, matchmaker, update_method, sleep_for): self.conf = conf self.matchmaker = matchmaker self.update_method = update_method self._sleep_for = sleep_for self.executor = zmq_async.get_executor(method=self._update_loop) self.executor.execute()
def test_poll_blocking(self): rep = self.ctx.socket(zmq.REP) rep.bind(self.ADDR_REQ) reply_poller = zmq_async.get_reply_poller() reply_poller.register(rep) def listener(): incoming, socket = reply_poller.poll() self.assertEqual(b'Hello', incoming[0]) socket.send_string('Reply') reply_poller.resume_polling(socket) executor = zmq_async.get_executor(listener) executor.execute() req1 = self.ctx.socket(zmq.REQ) req1.connect(self.ADDR_REQ) req2 = self.ctx.socket(zmq.REQ) req2.connect(self.ADDR_REQ) req1.send_string('Hello') req2.send_string('Hello') reply = req1.recv_string() self.assertEqual('Reply', reply) reply = req2.recv_string() self.assertEqual('Reply', reply)
def test_when_eventlet_module_is_available_then_return_GreenExecutor(self): zmq_async._is_eventlet_zmq_available = lambda: True executor = zmq_async.get_executor('any method', 'eventlet') self.assertTrue(isinstance(executor, green_poller.GreenExecutor)) self.assertEqual('any method', executor._method)
def test_default_executor_is_GreenExecutor(self): zmq_async._is_eventlet_zmq_available = lambda: True executor = zmq_async.get_executor('any method') self.assertTrue(isinstance(executor, green_poller.GreenExecutor)) self.assertEqual('any method', executor._method)
def __init__(self, conf): self.conf = conf self._lock = threading.Lock() self._requests = {} self._poller = zmq_async.get_poller() self._executor = zmq_async.get_executor(method=self._run_loop) self._executor.execute()
def __init__(self, conf): self.conf = conf self.replies = {} self.poller = zmq_async.get_poller() self.executor = zmq_async.get_executor(self.run_loop) self.executor.execute() self._lock = threading.Lock()
def test_when_eventlet_is_unavailable_then_return_ThreadingExecutor(self): zmq_async.eventletutils.is_monkey_patched = lambda _: False executor = zmq_async.get_executor('any method') self.assertIsInstance(executor, threading_poller.ThreadingExecutor) self.assertEqual('any method', executor._method)
def __init__(self, conf, matchmaker, update_method): self.conf = conf self.matchmaker = matchmaker self.update_method = update_method # make first update immediately self.update_method() self.executor = zmq_async.get_executor(method=self._update_loop) self.executor.execute()
def __init__(self, conf, matchmaker, update_method): self.conf = conf self.matchmaker = matchmaker self.update_method = update_method self._sleep_for = self.conf.oslo_messaging_zmq.zmq_target_update self.update_method() self.executor = zmq_async.get_executor(method=self._update_loop) self.executor.execute()
def __init__(self, conf, matchmaker, target, host, socket_type): self.conf = conf self.matchmaker = matchmaker self.target = target self.host = host self.socket_type = socket_type self.executor = zmq_async.get_executor(method=self._update_target) self.executor.execute()
def __init__(self, conf, matchmaker, reply_waiter): sockets_manager = zmq_publisher_base.SocketsManager( conf, matchmaker, zmq.ROUTER, zmq.DEALER) super(RequestSender, self).__init__(sockets_manager) self.reply_waiter = reply_waiter self.queue, self.empty_except = zmq_async.get_queue() self.executor = zmq_async.get_executor(self.run_loop) self.executor.execute()
def test_when_eventlet_is_unavailable_then_return_ThreadingExecutor(self): zmq_async._is_eventlet_zmq_available = lambda: False executor = zmq_async.get_executor('any method', 'eventlet') self.assertTrue(isinstance(executor, threading_poller.ThreadingExecutor)) self.assertEqual('any method', executor._method)
def __init__(self, conf): self.conf = conf self._lock = threading.Lock() self._requests = {} self._poller = zmq_async.get_poller() self._receive_response_versions = \ zmq_version.get_method_versions(self, 'receive_response') self._executor = zmq_async.get_executor(self._run_loop) self._executor.execute()
def __init__(self, conf, *args, **kwargs): super(MatchmakerDummy, self).__init__(conf, *args, **kwargs) self._cache = collections.defaultdict(list) self._publishers = set() self._routers = set() self._address = {} self.executor = zmq_async.get_executor(method=self._loop) self.executor.execute()
def __init__(self, conf, matchmaker, host, socket_type): self.targets = [] self.conf = conf self.matchmaker = matchmaker self.host = host self.socket_type = socket_type self.targets_lock = threading.Lock() self.updater = zmq_async.get_executor(method=self._update_targets) \ if conf.zmq_target_expire > 0 else None if self.updater: self.updater.execute()
def __init__(self, ttl=None): self._lock = threading.Lock() self._cache = {} self._executor = None if not (ttl is None or isinstance(ttl, (int, float))): raise ValueError('ttl must be None or a number') # no (i.e. infinite) ttl if ttl is None or ttl <= 0: ttl = float('inf') else: self._executor = zmq_async.get_executor(self._update_cache) self._ttl = ttl if self._executor: self._executor.execute()
def __init__(self, conf, matchmaker, reply_waiter): super(RequestSender, self).__init__(conf, matchmaker, zmq.DEALER) self.reply_waiter = reply_waiter self.queue, self.empty_except = zmq_async.get_queue() self.executor = zmq_async.get_executor(self.run_loop) self.executor.execute()
def __init__(self, matchmaker, on_result): self.matchmaker = matchmaker self.executor = zmq_async.get_executor( method=self._poll_for_publishers) self.on_result = on_result self.executor.execute()
def setUp(self): super(TestZmqAckManager, self).setUp() # register and set necessary config opts self.messaging_conf.transport_driver = 'zmq' zmq_options.register_opts(self.conf) kwargs = { 'rpc_zmq_matchmaker': 'dummy', 'use_pub_sub': False, 'use_router_proxy': True, 'rpc_thread_pool_size': 1, 'rpc_use_acks': True, 'rpc_ack_timeout_base': 5, 'rpc_ack_timeout_multiplier': 1, 'rpc_retry_attempts': 2 } self.config(group='oslo_messaging_zmq', **kwargs) self.conf.register_opts(zmq_proxy.zmq_proxy_opts, group='zmq_proxy_opts') # mock set_result method of futures self.set_result_patcher = mock.patch.object( zmq_receivers.futurist.Future, 'set_result', side_effect=zmq_receivers.futurist.Future.set_result, autospec=True) self.set_result = self.set_result_patcher.start() # mock send method of senders self.send_patcher = mock.patch.object( zmq_senders.RequestSenderProxy, 'send', side_effect=zmq_senders.RequestSenderProxy.send, autospec=True) self.send = self.send_patcher.start() # get driver transport = oslo_messaging.get_transport(self.conf) self.driver = transport._driver # prepare and launch proxy self.proxy = zmq_proxy.ZmqProxy(self.conf) vars(self.driver.matchmaker).update(vars(self.proxy.matchmaker)) self.executor = zmq_async.get_executor(self.proxy.run) self.executor.execute() # create listener self.listener = zmq_common.TestServerListener(self.driver) # create target and message self.target = oslo_messaging.Target(topic='topic', server='server') self.message = {'method': 'xyz', 'args': {'x': 1, 'y': 2, 'z': 3}} # start listening to target self.listener.listen(self.target) # get ack manager self.ack_manager = self.driver.client.get().publishers['default'] self.addCleanup( zmq_common.StopRpc(self, [('listener', 'stop'), ('executor', 'stop'), ('proxy', 'close'), ('driver', 'cleanup'), ('send_patcher', 'stop'), ('set_result_patcher', 'stop')])) # wait for all connections to be established # and all parties to be ready for messaging time.sleep(1)
def __init__(self, conf, context): super(BaseProxy, self).__init__() self.conf = conf self.context = context self.executor = zmq_async.get_executor(self.run, zmq_concurrency='native')
def __init__(self): self.poller = zmq_async.get_poller() self.thread = zmq_async.get_executor(self.poll_for_acknowledgements) self.thread.execute()
def test_invalid_config_value_raise_ValueError(self): invalid_opt = 'x' errmsg = 'Invalid zmq_concurrency value: x' with self.assertRaisesRegexp(ValueError, errmsg): zmq_async.get_executor('any method', invalid_opt)
def __init__(self, sockets_manager, _do_send_request): super(QueuedSender, self).__init__(sockets_manager) self._do_send_request = _do_send_request self.queue, self.empty_except = zmq_async.get_queue() self.executor = zmq_async.get_executor(self.run_loop) self.executor.execute()
def setUp(self): super(TestZmqAckManager, self).setUp() # register and set necessary config opts self.messaging_conf.transport_driver = 'zmq' zmq_options.register_opts(self.conf) kwargs = {'rpc_zmq_matchmaker': 'dummy', 'use_pub_sub': False, 'use_router_proxy': True, 'rpc_thread_pool_size': 1, 'rpc_use_acks': True, 'rpc_ack_timeout_base': 5, 'rpc_ack_timeout_multiplier': 1, 'rpc_retry_attempts': 2} self.config(group='oslo_messaging_zmq', **kwargs) self.conf.register_opts(zmq_proxy.zmq_proxy_opts, group='zmq_proxy_opts') # mock set_result method of futures self.set_result_patcher = mock.patch.object( zmq_receivers.futurist.Future, 'set_result', side_effect=zmq_receivers.futurist.Future.set_result, autospec=True ) self.set_result = self.set_result_patcher.start() # mock send method of senders self.send_patcher = mock.patch.object( zmq_senders.RequestSenderProxy, 'send', side_effect=zmq_senders.RequestSenderProxy.send, autospec=True ) self.send = self.send_patcher.start() # get driver transport = oslo_messaging.get_transport(self.conf) self.driver = transport._driver # prepare and launch proxy self.proxy = zmq_proxy.ZmqProxy(self.conf) vars(self.driver.matchmaker).update(vars(self.proxy.matchmaker)) self.executor = zmq_async.get_executor(self.proxy.run) self.executor.execute() # create listener self.listener = zmq_common.TestServerListener(self.driver) # create target and message self.target = oslo_messaging.Target(topic='topic', server='server') self.message = {'method': 'xyz', 'args': {'x': 1, 'y': 2, 'z': 3}} # start listening to target self.listener.listen(self.target) # get ack manager self.ack_manager = self.driver.client.get().publishers['default'] self.addCleanup( zmq_common.StopRpc( self, [('listener', 'stop'), ('executor', 'stop'), ('proxy', 'close'), ('driver', 'cleanup'), ('send_patcher', 'stop'), ('set_result_patcher', 'stop')] ) ) # wait for all connections to be established # and all parties to be ready for messaging time.sleep(1)