qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [2/2] qpid-proton git commit: PROTON-1080: add alias for reactor when using any Reactor subclass
Date Tue, 15 Dec 2015 22:03:12 GMT
PROTON-1080: add alias for reactor when using any Reactor subclass


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/7ccd6329
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/7ccd6329
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/7ccd6329

Branch: refs/heads/master
Commit: 7ccd632974cc643030a8580ca72da645f6a22766
Parents: 87ece50
Author: Gordon Sim <gsim@redhat.com>
Authored: Tue Dec 15 20:20:28 2015 +0000
Committer: Gordon Sim <gsim@redhat.com>
Committed: Tue Dec 15 21:47:11 2015 +0000

----------------------------------------------------------------------
 proton-c/bindings/python/proton/__init__.py |  7 +++++
 tests/python/proton_tests/reactor.py        | 36 ++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7ccd6329/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index 2a87fe7..f3a8e8d 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -3805,6 +3805,13 @@ class Event(Wrapper, EventBase):
     """Returns the reactor associated with the event."""
     return wrappers.get("pn_reactor", _none)(pn_event_reactor(self._impl))
 
+  def __getattr__(self, name):
+    r = self.reactor
+    if r and hasattr(r, 'subclass') and r.subclass.__name__.lower() == name:
+      return r
+    else:
+      return super(Event, self).__getattr__(name)
+
   @property
   def transport(self):
     """Returns the transport associated with the event, or null if none is associated with
it."""

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7ccd6329/tests/python/proton_tests/reactor.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/reactor.py b/tests/python/proton_tests/reactor.py
index eeddb2f..c58530a 100644
--- a/tests/python/proton_tests/reactor.py
+++ b/tests/python/proton_tests/reactor.py
@@ -19,9 +19,9 @@ from __future__ import absolute_import
 #
 
 import time
-from .common import Test, SkipTest, TestServer
-from proton.reactor import Reactor, ApplicationEvent, EventInjector
-from proton.handlers import CHandshaker
+from .common import Test, SkipTest, TestServer, free_tcp_port
+from proton.reactor import Container, Reactor, ApplicationEvent, EventInjector
+from proton.handlers import CHandshaker, MessagingHandler
 from proton import Handler
 
 class Barf(Exception):
@@ -457,3 +457,33 @@ class ApplicationEventTest(Test):
         self._wait_for(lambda: self.hello_rcvd is not None)
         self.event_injector.trigger(self.goodbye_event)
         self._wait_for(lambda: self.goodbye_rcvd is not None)
+
+
+class ContainerTest(Test):
+    """Test container subclass of reactor."""
+
+    def test_event_container(self):
+        class TestHandler(MessagingHandler):
+            def __init__(self):
+                super(TestHandler, self).__init__()
+                port = free_tcp_port()
+                self.url = "localhost:%i" % port
+
+            def on_start(self, event):
+                self.listener = event.container.listen(self.url)
+
+            def on_connection_closing(self, event):
+                event.connection.close()
+                self.listener.close()
+        test_handler = TestHandler()
+        container = Container(test_handler)
+        class ConnectionHandler(MessagingHandler):
+            def __init__(self):
+                super(ConnectionHandler, self).__init__()
+
+            def on_connection_opened(self, event):
+                event.connection.close()
+                assert event.container == event.reactor
+                assert event.container == container
+        container.connect(test_handler.url, handler=ConnectionHandler())
+        container.run()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message