From ee7cdb49e1b8dedf00a7c9cbb113e809527279bf Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Mon, 11 Jan 2016 21:33:51 +0000 Subject: [PATCH] Task #8899: Allow broker options to be specified in FromBus/ToBus constructor (final final fix for tests without auto-reconnect, hopefully) --- LCS/Messaging/python/messaging/messagebus.py | 14 ++++++++------ .../python/messaging/test/t_messagebus.py | 11 ++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/LCS/Messaging/python/messaging/messagebus.py b/LCS/Messaging/python/messaging/messagebus.py index 50f51ae1693..a367294f7a4 100644 --- a/LCS/Messaging/python/messaging/messagebus.py +++ b/LCS/Messaging/python/messaging/messagebus.py @@ -58,19 +58,20 @@ class FromBus(object): but that of __new__(). """ - def __init__(self, address, options=None, broker=None): + def __init__(self, address, options=None, broker=None, broker_options=None): """ Initializer. :param address: valid Qpid address :param options: valid Qpid address options, e.g. {'create': 'never'} :param broker: valid Qpid broker URL, e.g. "localhost:5672" + :param broker_options: valid Qpid broker options, e.g. {'reconnect': True} """ self.address = address self.options = options if options else DEFAULT_ADDRESS_OPTIONS self.broker = broker if broker else DEFAULT_BROKER + self.broker_options = broker_options if broker_options else DEFAULT_BROKER_OPTIONS - self.connection = qpid.messaging.Connection(self.broker, - **DEFAULT_BROKER_OPTIONS) + self.connection = qpid.messaging.Connection(self.broker, **self.broker_options) self.session = None self.opened=0 @@ -246,19 +247,20 @@ class ToBus(object): but that of __new__(). """ - def __init__(self, address, options=None, broker=None): + def __init__(self, address, options=None, broker=None, broker_options=None): """ Initializer. :param address: valid Qpid address :param options: valid Qpid address options, e.g. {'create': 'never'} :param broker: valid Qpid broker URL, e.g. "localhost:5672" + :param broker_options: valid Qpid broker options, e.g. {'reconnect': True} """ self.address = address self.options = options if options else DEFAULT_ADDRESS_OPTIONS self.broker = broker if broker else DEFAULT_BROKER + self.broker_options = broker_options if broker_options else DEFAULT_BROKER_OPTIONS - self.connection = qpid.messaging.Connection(self.broker, - **DEFAULT_BROKER_OPTIONS) + self.connection = qpid.messaging.Connection(self.broker, **self.broker_options) self.session = None self.opened = 0 diff --git a/LCS/Messaging/python/messaging/test/t_messagebus.py b/LCS/Messaging/python/messaging/test/t_messagebus.py index 5c86702dba1..c4a70a0d66d 100644 --- a/LCS/Messaging/python/messaging/test/t_messagebus.py +++ b/LCS/Messaging/python/messaging/test/t_messagebus.py @@ -35,9 +35,6 @@ from lofar.messaging.exceptions import MessageBusError, InvalidMessage TIMEOUT = 1.0 -# Disable auto reconnect to test behaviour w.r.t. invalid addresses -DEFAULT_BROKER_OPTIONS['reconnect'] = False - # ======== FromBus unit tests ======== # @@ -56,7 +53,7 @@ class FromBusInitFailed(unittest.TestCase): regexp = re.escape(self.error) regexp += '.*' + 'No address associated with hostname' with self.assertRaisesRegexp(MessageBusError, regexp): - with FromBus(QUEUE, broker="foo.bar"): + with FromBus(QUEUE, broker="foo.bar", broker_options={'reconnect': False}): pass def test_connection_refused(self): @@ -65,7 +62,7 @@ class FromBusInitFailed(unittest.TestCase): """ regexp = re.escape(self.error) + '.*' + 'Connection refused' with self.assertRaisesRegexp(MessageBusError, regexp): - with FromBus("fake" + QUEUE, broker="localhost:4"): + with FromBus("fake" + QUEUE, broker="localhost:4", broker_options={'reconnect': False}): pass @@ -167,7 +164,7 @@ class ToBusInitFailed(unittest.TestCase): regexp = re.escape(self.error) regexp += '.*' + 'No address associated with hostname' with self.assertRaisesRegexp(MessageBusError, regexp): - with ToBus(QUEUE, broker="foo.bar"): + with ToBus(QUEUE, broker="foo.bar", broker_options={'reconnect': False}): pass def test_connection_refused(self): @@ -176,7 +173,7 @@ class ToBusInitFailed(unittest.TestCase): """ regexp = re.escape(self.error) + '.*' + 'Connection refused' with self.assertRaisesRegexp(MessageBusError, regexp): - with ToBus(QUEUE, broker="localhost:4"): + with ToBus(QUEUE, broker="localhost:4", broker_options={'reconnect': False}): pass -- GitLab