Repository: qpid-proton
Updated Branches:
  refs/heads/master 4ea3d2625 -> 0c8ba1df7


PROTON-1126: allow setting of various connection fields. Patch from Ganesh 
Murthy.


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

Branch: refs/heads/master
Commit: 0c8ba1df78fac9bebfda6b08f88105ff1b20d219
Parents: 4ea3d26
Author: Gordon Sim <[email protected]>
Authored: Fri Feb 5 16:58:12 2016 +0000
Committer: Gordon Sim <[email protected]>
Committed: Fri Feb 5 16:58:12 2016 +0000

----------------------------------------------------------------------
 proton-c/bindings/python/proton/reactor.py |  6 +++-
 proton-c/bindings/python/proton/utils.py   |  6 ++--
 tests/python/proton_tests/utils.py         | 39 +++++++++++++++++++++++--
 3 files changed, 46 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c8ba1df/proton-c/bindings/python/proton/reactor.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/reactor.py 
b/proton-c/bindings/python/proton/reactor.py
index 195ff28..207690e 100644
--- a/proton-c/bindings/python/proton/reactor.py
+++ b/proton-c/bindings/python/proton/reactor.py
@@ -671,7 +671,11 @@ class Container(Reactor):
         """
         conn = self.connection(handler)
         conn.container = self.container_id or str(generate_uuid())
-
+        
+        conn.offered_capabilities = kwargs.get('offered_capabilities')
+        conn.desired_capabilities = kwargs.get('desired_capabilities')
+        conn.properties = kwargs.get('properties')
+        
         connector = Connector(conn)
         connector.allow_insecure_mechs = kwargs.get('allow_insecure_mechs', 
self.allow_insecure_mechs)
         connector.allowed_mechs = kwargs.get('allowed_mechs', 
self.allowed_mechs)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c8ba1df/proton-c/bindings/python/proton/utils.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/utils.py 
b/proton-c/bindings/python/proton/utils.py
index b97f470..62f965f 100644
--- a/proton-c/bindings/python/proton/utils.py
+++ b/proton-c/bindings/python/proton/utils.py
@@ -196,14 +196,16 @@ class BlockingConnection(Handler):
     """
     A synchronous style connection wrapper.
     """
-    def __init__(self, url, timeout=None, container=None, ssl_domain=None, 
heartbeat=None):
+    def __init__(self, url, timeout=None, container=None, ssl_domain=None, 
heartbeat=None,
+                 properties=None, offered_capabilities=None, 
desired_capabilities=None):
         self.disconnected = False
         self.timeout = timeout or 60
         self.container = container or Container()
         self.container.timeout = self.timeout
         self.container.start()
         self.url = Url(url).defaults()
-        self.conn = self.container.connect(url=self.url, handler=self, 
ssl_domain=ssl_domain, reconnect=False, heartbeat=heartbeat)
+        self.conn = self.container.connect(url=self.url, handler=self, 
ssl_domain=ssl_domain, reconnect=False, heartbeat=heartbeat,
+                                           properties=properties, 
offered_capabilities=offered_capabilities, 
desired_capabilities=desired_capabilities)
         self.wait(lambda: not (self.conn.state & Endpoint.REMOTE_UNINIT),
                   msg="Opening connection")
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0c8ba1df/tests/python/proton_tests/utils.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/utils.py 
b/tests/python/proton_tests/utils.py
index 1ddccc4..0a66ddd 100644
--- a/tests/python/proton_tests/utils.py
+++ b/tests/python/proton_tests/utils.py
@@ -22,11 +22,15 @@ from threading import Thread, Event
 from unittest import TestCase
 from proton_tests.common import Test, free_tcp_port
 from copy import copy
-from proton import Message, Url, generate_uuid
+from proton import Message, Url, generate_uuid, Array, UNDESCRIBED, Data, 
symbol
 from proton.handlers import MessagingHandler
 from proton.reactor import Container
 from proton.utils import SyncRequestResponse, BlockingConnection
 
+CONNECTION_PROPERTIES={u'connection': u'properties'}
+OFFERED_CAPABILITIES = Array(UNDESCRIBED, Data.SYMBOL, symbol("O_one"), 
symbol("O_two"), symbol("O_three"))
+DESIRED_CAPABILITIES = Array(UNDESCRIBED, Data.SYMBOL, symbol("D_one"), 
symbol("D_two"), symbol("D_three"))
+
 
 class EchoServer(MessagingHandler, Thread):
     """
@@ -48,7 +52,7 @@ class EchoServer(MessagingHandler, Thread):
         self.acceptor = event.container.listen(self.url)
         self.container = event.container
         self.event.set()
-
+        
     def on_link_opening(self, event):
         if event.link.is_sender:
             if event.link.remote_source and event.link.remote_source.dynamic:
@@ -72,6 +76,23 @@ class EchoServer(MessagingHandler, Thread):
         self.event.wait(self.timeout)
 
 
+class ConnPropertiesServer(EchoServer):
+     def __init__(self, url, timeout):
+        EchoServer.__init__(self, url, timeout)
+        self.properties_received = False
+        self.offered_capabilities_received = False
+        self.desired_capabilities_received = False
+
+     def on_connection_opening(self, event):
+        conn = event.connection
+                   
+        if conn.remote_properties == CONNECTION_PROPERTIES:
+            self.properties_received = True
+        if conn.remote_offered_capabilities == OFFERED_CAPABILITIES:
+            self.offered_capabilities_received = True
+        if conn.remote_desired_capabilities == DESIRED_CAPABILITIES:
+            self.desired_capabilities_received = True
+        
 class SyncRequestResponseTest(Test):
     """Test SyncRequestResponse"""
 
@@ -93,3 +114,17 @@ class SyncRequestResponseTest(Test):
         finally:
             client.connection.close()
         server.join(timeout=self.timeout)
+
+
+    def test_connection_properties(self):
+        server = ConnPropertiesServer(Url(host="127.0.0.1", 
port=free_tcp_port()), timeout=self.timeout)
+        server.start()
+        server.wait()
+        connection = BlockingConnection(server.url, timeout=self.timeout, 
properties=CONNECTION_PROPERTIES, offered_capabilities=OFFERED_CAPABILITIES, 
desired_capabilities=DESIRED_CAPABILITIES)
+        client = SyncRequestResponse(connection)
+        client.connection.close()
+        server.join(timeout=self.timeout)
+        self.assertEquals(server.properties_received, True)
+        self.assertEquals(server.offered_capabilities_received, True)
+        self.assertEquals(server.desired_capabilities_received, True)
+


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to