diff --git a/LCS/Messaging/python/messaging/messagebus.py b/LCS/Messaging/python/messaging/messagebus.py index 50f51ae1693d86b45c9e7c9dd9a13aaeb613c4c0..a367294f7a43cc41e6fd15c3be99ca90f7a2e123 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 5c86702dba1bdeeb13a8725ee6fba686578dd666..c4a70a0d66dc1df2b6f4930824e659dcf8320333 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