aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject aurora git commit: Don't destroy session between requests with TRequestsTransport
Date Wed, 09 Mar 2016 19:59:38 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 3298d38b5 -> 3512cbb98


Don't destroy session between requests with TRequestsTransport

As an API consumer, I want the API client to reuse open connections and not create a new one
for every query.

Reviewed at https://reviews.apache.org/r/42656/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/3512cbb9
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/3512cbb9
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/3512cbb9

Branch: refs/heads/master
Commit: 3512cbb981571c1ea2f4c2768dc5770fbf51e539
Parents: 3298d38
Author: Kunal Thakar <kunalt@gmail.com>
Authored: Wed Mar 9 20:58:13 2016 +0100
Committer: Stephan Erb <stephan@dev.static-void.de>
Committed: Wed Mar 9 20:58:13 2016 +0100

----------------------------------------------------------------------
 .../python/apache/aurora/common/transport.py    |  6 ++---
 .../apache/aurora/common/test_transport.py      | 24 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/3512cbb9/src/main/python/apache/aurora/common/transport.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/common/transport.py b/src/main/python/apache/aurora/common/transport.py
index 909021a..2e38847 100644
--- a/src/main/python/apache/aurora/common/transport.py
+++ b/src/main/python/apache/aurora/common/transport.py
@@ -111,10 +111,8 @@ class TRequestsTransport(TTransportBase):
     self.__wbuf.write(buf)
 
   def flush(self):
-    if self.isOpen():
-      self.close()
-
-    self.open()
+    if not self.isOpen():
+      self.open()
 
     data = self.__wbuf.getvalue()
     self.__wbuf = BytesIO()

http://git-wip-us.apache.org/repos/asf/aurora/blob/3512cbb9/src/test/python/apache/aurora/common/test_transport.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/common/test_transport.py b/src/test/python/apache/aurora/common/test_transport.py
index 1f589a9..0a587f0 100644
--- a/src/test/python/apache/aurora/common/test_transport.py
+++ b/src/test/python/apache/aurora/common/test_transport.py
@@ -176,3 +176,27 @@ def test_auth_type_invalid():
   with pytest.raises(TypeError) as e:
     TRequestsTransport('http://localhost:1', auth="auth")
   assert e.value.message == 'Invalid auth type. Expected: AuthBase but got str'
+
+
+def test_requests_transport_session_reuse():
+  handler = ReadOnlySchedulerHandler()
+  processor = ReadOnlyScheduler.Processor(handler)
+  pfactory = TJSONProtocol.TJSONProtocolFactory()
+  server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
+  server_thread = Thread(target=server.serve)
+  server_thread.start()
+  _, server_port = server.httpd.socket.getsockname()
+
+  try:
+    transport = TRequestsTransport('http://localhost:%d' % server_port)
+    protocol = TJSONProtocol.TJSONProtocol(transport)
+    client = ReadOnlyScheduler.Client(protocol)
+    client.getRoleSummary()
+    old_session = transport._session
+    client.getRoleSummary()
+  finally:
+    server.httpd.shutdown()
+
+  assert old_session == transport._session
+
+  transport.close()


Mime
View raw message