Blob Blame Raw
From e4149280e2e72e73985fdd7e040c833fc61a88a2 Mon Sep 17 00:00:00 2001
From: Brian Bouterse <bmbouter@gmail.com>
Date: Tue, 16 Feb 2016 14:56:23 -0500
Subject: [PATCH] Updates Qpid transport with updated names of Qpid async
 interface

---
 kombu/tests/transport/test_qpid.py | 38 +++++++++++++++++++++++++++++---------
 kombu/transport/qpid.py            | 16 +++++++++-------
 2 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/kombu/tests/transport/test_qpid.py b/kombu/tests/transport/test_qpid.py
index a3894e4..4340443 100644
--- a/kombu/tests/transport/test_qpid.py
+++ b/kombu/tests/transport/test_qpid.py
@@ -1706,13 +1706,29 @@ def test_transport_establish_conn_uses_hostname_if_not_default(self):
             transport='tcp',
         )
 
-    def test_transport_sets_qpid_message_received_handler(self):
+    def test_transport_sets_qpid_message_ready_handler(self):
         self.transport.establish_connection()
-        qpid_conn = self.mock_conn.return_value.get_qpid_connection
-        new_mock_session = qpid_conn.return_value.session.return_value
-        mock_set_callback = new_mock_session.set_message_received_handler
-        expected_callback = self.transport._qpid_session_ready
-        mock_set_callback.assert_called_once_with(expected_callback)
+        qpid_conn_call = self.mock_conn.return_value.get_qpid_connection
+        mock_session = qpid_conn_call.return_value.session.return_value
+        mock_set_callback = mock_session.set_message_received_notify_handler
+        expected_msg_callback = self.transport._qpid_message_ready_handler
+        mock_set_callback.assert_called_once_with(expected_msg_callback)
+
+    def test_transport_sets_session_exception_handler(self):
+        self.transport.establish_connection()
+        qpid_conn_call = self.mock_conn.return_value.get_qpid_connection
+        mock_session = qpid_conn_call.return_value.session.return_value
+        mock_set_callback = mock_session.set_async_exception_notify_handler
+        exc_callback = self.transport._qpid_async_exception_notify_handler
+        mock_set_callback.assert_called_once_with(exc_callback)
+
+    def test_transport_sets_connection_exception_handler(self):
+        self.transport.establish_connection()
+        qpid_conn_call = self.mock_conn.return_value.get_qpid_connection
+        qpid_conn = qpid_conn_call.return_value
+        mock_set_callback = qpid_conn.set_async_exception_notify_handler
+        exc_callback = self.transport._qpid_async_exception_notify_handler
+        mock_set_callback.assert_called_once_with(exc_callback)
 
 
 @case_no_python3
@@ -1766,7 +1782,7 @@ def test_transport_register_with_event_loop_calls_add_reader(self):
 @case_no_python3
 @case_no_pypy
 @disable_runtime_dependency_check
-class TestTransportQpidSessionReady(Case):
+class TestTransportQpidCallbackHandlers(Case):
 
     def setUp(self):
         self.patch_a = patch(QPID_MODULE + '.os.write')
@@ -1776,10 +1792,14 @@ def setUp(self):
     def tearDown(self):
         self.patch_a.stop()
 
-    def test_transport__qpid_session_ready_writes_symbol_to_fd(self):
-        self.transport._qpid_session_ready()
+    def test__qpid_message_ready_handler_writes_symbol_to_fd(self):
+        self.transport._qpid_message_ready_handler(Mock())
         self.mock_os_write.assert_called_once_with(self.transport._w, '0')
 
+    def test__qpid_async_exception_notify_handler_writes_symbol_to_fd(self):
+        self.transport._qpid_async_exception_notify_handler(Mock(), Mock())
+        self.mock_os_write.assert_called_once_with(self.transport._w, 'e')
+
 
 @case_no_python3
 @case_no_pypy
diff --git a/kombu/transport/qpid.py b/kombu/transport/qpid.py
index 081c6c6..55cafdd 100644
--- a/kombu/transport/qpid.py
+++ b/kombu/transport/qpid.py
@@ -1434,10 +1434,10 @@ def verify_runtime_environment(self):
                 'with your package manager. You can also try `pip install '
                 'qpid-python`.')
 
-    def _qpid_session_ready(self):
+    def _qpid_message_ready_handler(self, session):
         os.write(self._w, '0')
 
-    def _qpid_exception(self, obj_with_exception):
+    def _qpid_async_exception_notify_handler(self, obj_with_exception, exc):
         os.write(self._w, 'e')
 
     def on_readable(self, connection, loop):
@@ -1596,12 +1596,14 @@ def establish_connection(self):
         conn = self.Connection(**opts)
         conn.client = self.client
         self.session = conn.get_qpid_connection().session()
-        self.session.set_message_received_handler(self._qpid_session_ready)
-        conn.get_qpid_connection().set_exception_notify_handler(
-            self._qpid_exception
+        self.session.set_message_received_notify_handler(
+            self._qpid_message_ready_handler
         )
-        self.session.set_exception_notify_handler(
-            self._qpid_exception
+        conn.get_qpid_connection().set_async_exception_notify_handler(
+            self._qpid_async_exception_notify_handler
+        )
+        self.session.set_async_exception_notify_handler(
+            self._qpid_async_exception_notify_handler
         )
         return conn