You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/02/14 14:48:19 UTC

[1/8] thrift git commit: THRIFT-3624 Fix lib/cpp/test/TServerSocketTest.cpp to use ephemeral ports. Client: Test (C++) Patch: John Sirois

Repository: thrift
Updated Branches:
  refs/heads/master d4722d9c4 -> ea5845a2f


THRIFT-3624 Fix lib/cpp/test/TServerSocketTest.cpp to use ephemeral ports.
Client: Test (C++)
Patch: John Sirois

Instead of using a fixed port, use an ephemeral port to improve
robustness and make way for parallelizability.

This closes #855


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

Branch: refs/heads/master
Commit: cab56006633f9a21da2c390998984660d0dde593
Parents: b867b27
Author: John Sirois <js...@apache.org>
Authored: Fri Feb 12 17:58:14 2016 -0700
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:18 2016 +0900

----------------------------------------------------------------------
 lib/cpp/test/TServerSocketTest.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/cab56006/lib/cpp/test/TServerSocketTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TServerSocketTest.cpp b/lib/cpp/test/TServerSocketTest.cpp
index ae87ba8..1da5d36 100644
--- a/lib/cpp/test/TServerSocketTest.cpp
+++ b/lib/cpp/test/TServerSocketTest.cpp
@@ -20,7 +20,6 @@
 #include <boost/test/auto_unit_test.hpp>
 #include <thrift/transport/TSocket.h>
 #include <thrift/transport/TServerSocket.h>
-#include "TestPortFixture.h"
 #include "TTransportCheckThrow.h"
 #include <iostream>
 
@@ -29,19 +28,20 @@ using apache::thrift::transport::TSocket;
 using apache::thrift::transport::TTransport;
 using apache::thrift::transport::TTransportException;
 
-BOOST_FIXTURE_TEST_SUITE(TServerSocketTest, TestPortFixture)
+BOOST_AUTO_TEST_SUITE(TServerSocketTest)
 
 BOOST_AUTO_TEST_CASE(test_bind_to_address) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.listen();
-  TSocket clientSock("localhost", m_serverPort);
+  int port = sock1.getPort();
+  TSocket clientSock("localhost", port);
   clientSock.open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   accepted->close();
   sock1.close();
 
   std::cout << "An error message from getaddrinfo on the console is expected:" << std::endl;
-  TServerSocket sock2("257.258.259.260", m_serverPort);
+  TServerSocket sock2("257.258.259.260", 0);
   BOOST_CHECK_THROW(sock2.listen(), TTransportException);
   sock2.close();
 }
@@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(test_listen_valid_port) {
 }
 
 BOOST_AUTO_TEST_CASE(test_close_before_listen) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.close();
 }
 


[4/8] thrift git commit: THRIFT-3626 Fix lib/cpp/test/TSocketInterruptTest.cpp to use ephemeral ports. Client: Test (C++) Patch: John Sirois

Posted by ns...@apache.org.
THRIFT-3626 Fix lib/cpp/test/TSocketInterruptTest.cpp to use ephemeral ports.
Client: Test (C++)
Patch: John Sirois

Instead of using a fixed port, use an ephemeral port to improve
robustness and make way for parallelizability.

This change has an undesirable amount of repeated code but this fact is
not different from the prior so being a bit expedient here. Ideally
setup of a `TServerSocket` listening on an ephemeral port would be DRYed
up into a helper of some sort.

This closes #857


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/9bd3530b
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/9bd3530b
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/9bd3530b

Branch: refs/heads/master
Commit: 9bd3530b977dd422c3deff73c4577b55f9c3d23c
Parents: cab5600
Author: John Sirois <js...@apache.org>
Authored: Fri Feb 12 21:07:49 2016 -0700
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:19 2016 +0900

----------------------------------------------------------------------
 lib/cpp/test/TSocketInterruptTest.cpp | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/9bd3530b/lib/cpp/test/TSocketInterruptTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TSocketInterruptTest.cpp b/lib/cpp/test/TSocketInterruptTest.cpp
index 02da3ee..27b89eb 100644
--- a/lib/cpp/test/TSocketInterruptTest.cpp
+++ b/lib/cpp/test/TSocketInterruptTest.cpp
@@ -26,14 +26,13 @@
 #include <boost/thread/thread.hpp>
 #include <thrift/transport/TSocket.h>
 #include <thrift/transport/TServerSocket.h>
-#include "TestPortFixture.h"
 
 using apache::thrift::transport::TServerSocket;
 using apache::thrift::transport::TSocket;
 using apache::thrift::transport::TTransport;
 using apache::thrift::transport::TTransportException;
 
-BOOST_FIXTURE_TEST_SUITE(TSocketInterruptTest, TestPortFixture)
+BOOST_AUTO_TEST_SUITE(TSocketInterruptTest)
 
 void readerWorker(boost::shared_ptr<TTransport> tt, uint32_t expectedResult) {
   uint8_t buf[4];
@@ -51,9 +50,10 @@ void readerWorkerMustThrow(boost::shared_ptr<TTransport> tt) {
 }
 
 BOOST_AUTO_TEST_CASE(test_interruptable_child_read) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.listen();
-  TSocket clientSock("localhost", m_serverPort);
+  int port = sock1.getPort();
+  TSocket clientSock("localhost", port);
   clientSock.open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted));
@@ -68,10 +68,11 @@ BOOST_AUTO_TEST_CASE(test_interruptable_child_read) {
 }
 
 BOOST_AUTO_TEST_CASE(test_non_interruptable_child_read) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior
   sock1.listen();
-  TSocket clientSock("localhost", m_serverPort);
+  int port = sock1.getPort();
+  TSocket clientSock("localhost", port);
   clientSock.open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   boost::thread readThread(boost::bind(readerWorker, accepted, 0));
@@ -89,7 +90,7 @@ BOOST_AUTO_TEST_CASE(test_non_interruptable_child_read) {
 }
 
 BOOST_AUTO_TEST_CASE(test_cannot_change_after_listen) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.listen();
   BOOST_CHECK_THROW(sock1.setInterruptableChildren(false), std::logic_error);
   sock1.close();
@@ -100,9 +101,10 @@ void peekerWorker(boost::shared_ptr<TTransport> tt, bool expectedResult) {
 }
 
 BOOST_AUTO_TEST_CASE(test_interruptable_child_peek) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.listen();
-  TSocket clientSock("localhost", m_serverPort);
+  int port = sock1.getPort();
+  TSocket clientSock("localhost", port);
   clientSock.open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   // peek() will return false if child is interrupted
@@ -118,10 +120,11 @@ BOOST_AUTO_TEST_CASE(test_interruptable_child_peek) {
 }
 
 BOOST_AUTO_TEST_CASE(test_non_interruptable_child_peek) {
-  TServerSocket sock1("localhost", m_serverPort);
+  TServerSocket sock1("localhost", 0);
   sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior
   sock1.listen();
-  TSocket clientSock("localhost", m_serverPort);
+  int port = sock1.getPort();
+  TSocket clientSock("localhost", port);
   clientSock.open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   // peek() will return false when remote side is closed


[2/8] thrift git commit: THRIFT-3621 Fix cpp/lib/test/TSSLSocketInterruptTest.cpp to use ephemeral ports. Client: Test (C++) Patch: John Sirois

Posted by ns...@apache.org.
THRIFT-3621 Fix cpp/lib/test/TSSLSocketInterruptTest.cpp to use ephemeral ports.
Client: Test (C++)
Patch: John Sirois

Instead of using a fixed port, use an ephemeral port to improve
robustness and make way for parallelizability.

This change has an undesirable amount of repeated code but this fact is
not different from the prior so being a bit expedient here.  Ideally
setup of a `TSSLServerSocket` listening on an ephemeral port would be
DRYed up into a helper of some sort.

This closes #854


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

Branch: refs/heads/master
Commit: b867b27c5d50800930e0f1f03db59c1f04ce748a
Parents: d4722d9
Author: John Sirois <js...@apache.org>
Authored: Fri Feb 12 17:44:01 2016 -0700
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:18 2016 +0900

----------------------------------------------------------------------
 lib/cpp/test/TSSLSocketInterruptTest.cpp | 32 +++++++++++++++------------
 1 file changed, 18 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/b867b27c/lib/cpp/test/TSSLSocketInterruptTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TSSLSocketInterruptTest.cpp b/lib/cpp/test/TSSLSocketInterruptTest.cpp
index f19b159..cf75c16 100644
--- a/lib/cpp/test/TSSLSocketInterruptTest.cpp
+++ b/lib/cpp/test/TSSLSocketInterruptTest.cpp
@@ -28,7 +28,6 @@
 #include <boost/shared_ptr.hpp>
 #include <thrift/transport/TSSLSocket.h>
 #include <thrift/transport/TSSLServerSocket.h>
-#include "TestPortFixture.h"
 #ifdef __linux__
 #include <signal.h>
 #endif
@@ -39,6 +38,8 @@ using apache::thrift::transport::TTransport;
 using apache::thrift::transport::TTransportException;
 using apache::thrift::transport::TSSLSocketFactory;
 
+BOOST_AUTO_TEST_SUITE(TSSLSocketInterruptTest)
+
 boost::filesystem::path keyDir;
 boost::filesystem::path certFile(const std::string& filename)
 {
@@ -91,8 +92,6 @@ BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL);
 BOOST_GLOBAL_FIXTURE(GlobalFixtureSSL)
 #endif
 
-BOOST_FIXTURE_TEST_SUITE(TSSLSocketInterruptTest, TestPortFixture)
-
 void readerWorker(boost::shared_ptr<TTransport> tt, uint32_t expectedResult) {
   uint8_t buf[4];
   try {
@@ -138,10 +137,11 @@ boost::shared_ptr<TSSLSocketFactory> createClientSocketFactory() {
 
 BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read_while_handshaking) {
   boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
-  TSSLServerSocket sock1("localhost", m_serverPort, pServerSocketFactory);
+  TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
   sock1.listen();
+  int port = sock1.getPort();
   boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
-  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", m_serverPort);
+  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
   clientSock->open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted));
@@ -157,10 +157,11 @@ BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read_while_handshaking) {
 
 BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read) {
   boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
-  TSSLServerSocket sock1("localhost", m_serverPort, pServerSocketFactory);
+  TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
   sock1.listen();
+  int port = sock1.getPort();
   boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
-  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", m_serverPort);
+  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
   clientSock->open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   boost::thread readThread(boost::bind(readerWorkerMustThrow, accepted));
@@ -178,11 +179,12 @@ BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_read) {
 BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_read) {
   std::cout << "An error message from SSL_Shutdown on the console is expected:" << std::endl;
   boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
-  TSSLServerSocket sock1("localhost", m_serverPort, pServerSocketFactory);
+  TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
   sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior
   sock1.listen();
+  int port = sock1.getPort();
   boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
-  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", m_serverPort);
+  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
   clientSock->open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   boost::thread readThread(boost::bind(readerWorker, accepted, 0));
@@ -202,7 +204,7 @@ BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_read) {
 
 BOOST_AUTO_TEST_CASE(test_ssl_cannot_change_after_listen) {
   boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
-  TSSLServerSocket sock1("localhost", m_serverPort, pServerSocketFactory);
+  TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
   sock1.listen();
   BOOST_CHECK_THROW(sock1.setInterruptableChildren(false), std::logic_error);
   sock1.close();
@@ -228,10 +230,11 @@ void peekerWorkerInterrupt(boost::shared_ptr<TTransport> tt) {
 BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_peek) {
   std::cout << "An error message from SSL_Shutdown on the console is expected:" << std::endl;
   boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
-  TSSLServerSocket sock1("localhost", m_serverPort, pServerSocketFactory);
+  TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
   sock1.listen();
+  int port = sock1.getPort();
   boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
-  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", m_serverPort);
+  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
   clientSock->open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   // peek() will return false if child is interrupted
@@ -253,11 +256,12 @@ BOOST_AUTO_TEST_CASE(test_ssl_interruptable_child_peek) {
 BOOST_AUTO_TEST_CASE(test_ssl_non_interruptable_child_peek) {
   std::cout << "An error message from SSL_Shutdown on the console is expected:" << std::endl;
   boost::shared_ptr<TSSLSocketFactory> pServerSocketFactory = createServerSocketFactory();
-  TSSLServerSocket sock1("localhost", m_serverPort, pServerSocketFactory);
+  TSSLServerSocket sock1("localhost", 0, pServerSocketFactory);
   sock1.setInterruptableChildren(false); // returns to pre-THRIFT-2441 behavior
   sock1.listen();
+  int port = sock1.getPort();
   boost::shared_ptr<TSSLSocketFactory> pClientSocketFactory = createClientSocketFactory();
-  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", m_serverPort);
+  boost::shared_ptr<TSSLSocket> clientSock = pClientSocketFactory->createSocket("localhost", port);
   clientSock->open();
   boost::shared_ptr<TTransport> accepted = sock1.accept();
   // peek() will return false when remote side is closed


[7/8] thrift git commit: THRIFT-3628 Fix lib/cpp/test/TServerIntegrationTest.cpp to use ephemeral ports. Client: Test (C++) Patch: John Sirois

Posted by ns...@apache.org.
THRIFT-3628 Fix lib/cpp/test/TServerIntegrationTest.cpp to use ephemeral ports.
Client: Test (C++)
Patch: John Sirois

This was already the case for most of the suite, which, besides the one
fixed constructor, retrieved the port to dynamically already.

This closes #859


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/919752ca
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/919752ca
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/919752ca

Branch: refs/heads/master
Commit: 919752ca2fa7e64f8854729aebbd91d4cbd50a57
Parents: 9bd3530
Author: John Sirois <js...@apache.org>
Authored: Sat Feb 13 12:35:58 2016 -0700
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:19 2016 +0900

----------------------------------------------------------------------
 lib/cpp/test/TServerIntegrationTest.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/919752ca/lib/cpp/test/TServerIntegrationTest.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/test/TServerIntegrationTest.cpp b/lib/cpp/test/TServerIntegrationTest.cpp
index f530771..ce1cbd3 100644
--- a/lib/cpp/test/TServerIntegrationTest.cpp
+++ b/lib/cpp/test/TServerIntegrationTest.cpp
@@ -33,7 +33,6 @@
 #include <thrift/transport/TSocket.h>
 #include <thrift/transport/TTransport.h>
 #include "gen-cpp/ParentService.h"
-#include "TestPortFixture.h"
 #include <vector>
 
 using apache::thrift::concurrency::Guard;
@@ -145,12 +144,12 @@ void autoSocketCloser(TSocket* pSock) {
 }
 
 template <class TServerType>
-class TServerIntegrationTestFixture : public TestPortFixture {
+class TServerIntegrationTestFixture {
 public:
   TServerIntegrationTestFixture(const boost::shared_ptr<TProcessorFactory>& _processorFactory)
     : pServer(new TServerType(_processorFactory,
                               boost::shared_ptr<TServerTransport>(
-                                  new TServerSocket("localhost", m_serverPort)),
+                                  new TServerSocket("localhost", 0)),
                               boost::shared_ptr<TTransportFactory>(new TTransportFactory),
                               boost::shared_ptr<TProtocolFactory>(new TBinaryProtocolFactory))),
       pEventHandler(boost::shared_ptr<TServerReadyEventHandler>(new TServerReadyEventHandler)) {


[8/8] thrift git commit: THRIFT-3614 Improve logging of test_sslsocket.py

Posted by ns...@apache.org.
THRIFT-3614 Improve logging of test_sslsocket.py

Suppress server exception log for expected connection failures
Client: Test (Python)
Patch: Nobuaki Sukegawa

This closes #866


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/66f50531
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/66f50531
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/66f50531

Branch: refs/heads/master
Commit: 66f50531405ac558d78725eaf01c95eb55621540
Parents: 8b411a0
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Feb 14 21:47:38 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:19 2016 +0900

----------------------------------------------------------------------
 lib/py/test/test_sslsocket.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/66f50531/lib/py/test/test_sslsocket.py
----------------------------------------------------------------------
diff --git a/lib/py/test/test_sslsocket.py b/lib/py/test/test_sslsocket.py
index 259945f..93d34d0 100644
--- a/lib/py/test/test_sslsocket.py
+++ b/lib/py/test/test_sslsocket.py
@@ -17,6 +17,7 @@
 # under the License.
 #
 
+import inspect
 import logging
 import os
 import platform
@@ -47,7 +48,7 @@ TEST_CIPHERS = 'DES-CBC3-SHA'
 
 
 class ServerAcceptor(threading.Thread):
-    def __init__(self, server):
+    def __init__(self, server, expect_failure=False):
         super(ServerAcceptor, self).__init__()
         self.daemon = True
         self._server = server
@@ -56,6 +57,10 @@ class ServerAcceptor(threading.Thread):
         self._port_bound = threading.Event()
         self._client = None
         self._client_accepted = threading.Event()
+        self._expect_failure = expect_failure
+        frame = inspect.stack(3)[2]
+        self.name = frame[3]
+        del frame
 
     def run(self):
         self._server.listen()
@@ -72,6 +77,10 @@ class ServerAcceptor(threading.Thread):
 
         try:
             self._client = self._server.accept()
+        except Exception:
+            logging.exception('error on server side (%s):' % self.name)
+            if not self._expect_failure:
+                raise
         finally:
             self._client_accepted.set()
 
@@ -108,14 +117,14 @@ class TSSLSocketTest(unittest.TestCase):
         return TSSLServerSocket(port=0, **kwargs)
 
     @contextmanager
-    def _connectable_client(self, server, path=None, **client_kwargs):
-        acc = ServerAcceptor(server)
+    def _connectable_client(self, server, expect_failure=False, path=None, **client_kwargs):
+        acc = ServerAcceptor(server, expect_failure)
         try:
             acc.start()
             acc.await_listening()
 
             host, port = ('localhost', acc.port) if path is None else (None, None)
-            client = TSSLSocket(host, port, path, **client_kwargs)
+            client = TSSLSocket(host, port, unix_socket=path, **client_kwargs)
             yield acc, client
         finally:
             if acc.client:
@@ -123,9 +132,9 @@ class TSSLSocketTest(unittest.TestCase):
             server.close()
 
     def _assert_connection_failure(self, server, path=None, **client_args):
-        with self._connectable_client(server, path=path, **client_args) as (acc, client):
+        logging.disable(logging.CRITICAL)
+        with self._connectable_client(server, True, path=path, **client_args) as (acc, client):
             try:
-                logging.disable(logging.CRITICAL)
                 # We need to wait for a connection failure, but not too long.  20ms is a tunable
                 # compromise between test speed and stability
                 client.setTimeout(20)


[5/8] thrift git commit: THRIFT-3632 c_glib testserialization fails with glib assertion Client: c_glib Patch: Nobuaki Sukegawa

Posted by ns...@apache.org.
THRIFT-3632 c_glib testserialization fails with glib assertion
Client: c_glib
Patch: Nobuaki Sukegawa

This closes #865


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8b411a0c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8b411a0c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8b411a0c

Branch: refs/heads/master
Commit: 8b411a0c8f9f6dc4fa7f6660b5b15fe27a76741d
Parents: 949e242
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Feb 14 20:22:11 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:19 2016 +0900

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_c_glib_generator.cc | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/8b411a0c/compiler/cpp/src/generate/t_c_glib_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_c_glib_generator.cc b/compiler/cpp/src/generate/t_c_glib_generator.cc
index 6a349c4..3a3fe54 100644
--- a/compiler/cpp/src/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/generate/t_c_glib_generator.cc
@@ -3773,7 +3773,6 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
   scope_up(out);
 
   if (ttype->is_map()) {
-    string length = "g_hash_table_size ((GHashTable *) " + prefix + ")";
     t_type* tkey = ((t_map*)ttype)->get_key_type();
     t_type* tval = ((t_map*)ttype)->get_val_type();
     string tkey_name = type_name(tkey);
@@ -3806,13 +3805,15 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
         << indent() << "int i = 0, key_count;" << endl
         << endl
         << indent() << "if ((ret = thrift_protocol_write_map_begin (protocol, "
-        << type_to_enum(tkey) << ", " << type_to_enum(tval) << ", (gint32) "
-        << length << ", error)) < 0)" << endl;
+        << type_to_enum(tkey) << ", " << type_to_enum(tval) << ", " << prefix << " ? "
+        << "(gint32) g_hash_table_size ((GHashTable *) " << prefix << ") : 0"
+        << ", error)) < 0)" << endl;
     indent_up();
     out << indent() << "return " << error_ret << ";" << endl;
     indent_down();
     out << indent() << "xfer += ret;" << endl
-        << indent() << "g_hash_table_foreach ((GHashTable *) " << prefix
+        << indent() << "if (" << prefix << ")" << endl
+        << indent() << "  g_hash_table_foreach ((GHashTable *) " << prefix
         << ", thrift_hash_table_get_keys, &key_list);" << endl
         << indent() << "key_count = g_list_length (key_list);" << endl
         << indent() << "keys = g_newa (" << tkey_name << tkey_ptr
@@ -3845,7 +3846,6 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
     indent_down();
     out << indent() << "xfer += ret;" << endl;
   } else if (ttype->is_set()) {
-    string length = "g_hash_table_size ((GHashTable *) " + prefix + ")";
     t_type* telem = ((t_set*)ttype)->get_elem_type();
     string telem_name = type_name(telem);
     string telem_ptr = telem->is_string() || !telem->is_base_type() ? "" : "*";
@@ -3857,13 +3857,15 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
         << indent() << "THRIFT_UNUSED_VAR (value);" << endl
         << endl
         << indent() << "if ((ret = thrift_protocol_write_set_begin (protocol, "
-        << type_to_enum(telem) << ", (gint32) " << length << ", error)) < 0)"
-        << endl;
+        << type_to_enum(telem) << ", " << prefix << " ? "
+        << "(gint32) g_hash_table_size ((GHashTable *) " << prefix << ") : 0"
+        << ", error)) < 0)" << endl;
     indent_up();
     out << indent() << "return " << error_ret << ";" << endl;
     indent_down();
     out << indent() << "xfer += ret;" << endl
-        << indent() << "g_hash_table_foreach ((GHashTable *) " << prefix
+        << indent() << "if (" << prefix << ")" << endl
+        << indent() << "  g_hash_table_foreach ((GHashTable *) " << prefix
         << ", thrift_hash_table_get_keys, &key_list);" << endl
         << indent() << "key_count = g_list_length (key_list);" << endl
         << indent() << "keys = g_newa (" << telem_name << telem_ptr
@@ -3894,7 +3896,7 @@ void t_c_glib_generator::generate_serialize_container(ofstream& out,
     indent_down();
     out << indent() << "xfer += ret;" << endl;
   } else if (ttype->is_list()) {
-    string length = prefix + "->len";
+    string length = "(" + prefix + " ? " + prefix + "->len : 0)";
     string i = tmp("i");
     out << indent() << "guint " << i << ";" << endl
         << endl


[3/8] thrift git commit: THRIFT-3633 Travis "C C++ - GCC" build was using clang Client: Build Patch: Nobuaki Sukegawa

Posted by ns...@apache.org.
THRIFT-3633 Travis "C C++ - GCC" build was using clang
Client: Build
Patch: Nobuaki Sukegawa

This closes #868


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

Branch: refs/heads/master
Commit: ea5845a2f53de0f7891b5fc293897407d59824a1
Parents: 66f5053
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Feb 14 21:56:53 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:19 2016 +0900

----------------------------------------------------------------------
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/ea5845a2/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 2f77254..adcd0da 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -62,6 +62,7 @@ env:
     - TEST_NAME="C C++ - GCC (automake)"
       BUILD_CMD="../autotools.sh"
       BUILD_ARG="--without-csharp --without-java --without-erlang --without-nodejs --without-lua --without-python --without-perl --without-php --without-php_extension --without-dart --without-ruby --without-haskell --without-go --without-haxe --without-d"
+      BUILD_ENV="-e CC=gcc -e CXX=g++"
 
     - TEST_NAME="Java Lua Perl PHP Python Ruby (automake)"
       BUILD_CMD="../autotools.sh"


[6/8] thrift git commit: THRIFT-2877 Generate hashCode using primitives and static utility methods Client: Java Author: Roshan George

Posted by ns...@apache.org.
THRIFT-2877 Generate hashCode using primitives and static utility methods
Client: Java
Author: Roshan George <ro...@arjie.com>

The TBaseHelper.hashCode methods are the Java 8 implementations of hashCode for
those types.

This closes #448


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/949e242e
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/949e242e
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/949e242e

Branch: refs/heads/master
Commit: 949e242ec8099e616e464ee7dce8d14e516b2519
Parents: 919752c
Author: Roshan George <ro...@arjie.com>
Authored: Fri Apr 17 00:46:02 2015 -0700
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sun Feb 14 22:47:19 2016 +0900

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_java_generator.cc   | 52 ++++++++++++++++----
 lib/java/src/org/apache/thrift/TBaseHelper.java | 10 ++++
 2 files changed, 53 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/949e242e/compiler/cpp/src/generate/t_java_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index 419a461..6a2b888 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -1882,9 +1882,12 @@ void t_java_generator::generate_java_struct_equality(ofstream& out, t_struct* ts
   scope_down(out);
   out << endl;
 
+  const int MUL = 8191; // HashCode multiplier
+  const int B_YES = 131071;
+  const int B_NO = 524287;
   out << indent() << "@Override" << endl << indent() << "public int hashCode() {" << endl;
   indent_up();
-  indent(out) << "List<Object> list = new ArrayList<Object>();" << endl;
+  indent(out) << "int hashCode = 1;" << endl;
 
   for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
     out << endl;
@@ -1894,24 +1897,55 @@ void t_java_generator::generate_java_struct_equality(ofstream& out, t_struct* ts
     bool can_be_null = type_can_be_null(t);
     string name = (*m_iter)->get_name();
 
-    string present = "true";
+    if (is_optional || can_be_null) {
+      indent(out) << "hashCode = hashCode * " << MUL << " + ((" << generate_isset_check(*m_iter)
+                  << ") ? " << B_YES << " : " << B_NO << ");" << endl;
+    }
 
     if (is_optional || can_be_null) {
-      present += " && (" + generate_isset_check(*m_iter) + ")";
+      indent(out) << "if (" + generate_isset_check(*m_iter) + ")" << endl;
+      indent_up();
     }
 
-    indent(out) << "boolean present_" << name << " = " << present << ";" << endl;
-    indent(out) << "list.add(present_" << name << ");" << endl;
-    indent(out) << "if (present_" << name << ")" << endl;
     if (t->is_enum()) {
-      indent(out) << "  list.add(" << name << ".getValue());" << endl;
+      indent(out) << "hashCode = hashCode * " << MUL << " + " << name << ".getValue();" << endl;
+    } else if (t->is_base_type()) {
+      switch(((t_base_type*)t)->get_base()) {
+      case t_base_type::TYPE_STRING:
+        indent(out) << "hashCode = hashCode * " << MUL << " + " << name << ".hashCode();" << endl;
+        break;
+      case t_base_type::TYPE_BOOL:
+        indent(out) << "hashCode = hashCode * " << MUL << " + ((" << name << ") ? "
+                    << B_YES << " : " << B_NO << ");" << endl;
+        break;
+      case t_base_type::TYPE_I8:
+        indent(out) << "hashCode = hashCode * " << MUL << " + (int) (" << name << ");" << endl;
+        break;
+      case t_base_type::TYPE_I16:
+      case t_base_type::TYPE_I32:
+        indent(out) << "hashCode = hashCode * " << MUL << " + " << name << ";" << endl;
+        break;
+      case t_base_type::TYPE_I64:
+      case t_base_type::TYPE_DOUBLE:
+        indent(out) << "hashCode = hashCode * " << MUL << " + org.apache.thrift.TBaseHelper.hashCode(" << name << ");" << endl;
+        break;
+      case t_base_type::TYPE_VOID:
+        throw std::logic_error("compiler error: a struct field cannot be void");
+      default:
+        throw std::logic_error("compiler error: the following base type has no hashcode generator: " +
+               t_base_type::t_base_name(((t_base_type*)t)->get_base()));
+      }
     } else {
-      indent(out) << "  list.add(" << name << ");" << endl;
+      indent(out) << "hashCode = hashCode * " << MUL << " + " << name << ".hashCode();" << endl;
+    }
+
+    if (is_optional || can_be_null) {
+      indent_down();
     }
   }
 
   out << endl;
-  indent(out) << "return list.hashCode();" << endl;
+  indent(out) << "return hashCode;" << endl;
   indent_down();
   indent(out) << "}" << endl << endl;
 }

http://git-wip-us.apache.org/repos/asf/thrift/blob/949e242e/lib/java/src/org/apache/thrift/TBaseHelper.java
----------------------------------------------------------------------
diff --git a/lib/java/src/org/apache/thrift/TBaseHelper.java b/lib/java/src/org/apache/thrift/TBaseHelper.java
index 5517536..559df33 100644
--- a/lib/java/src/org/apache/thrift/TBaseHelper.java
+++ b/lib/java/src/org/apache/thrift/TBaseHelper.java
@@ -324,4 +324,14 @@ public final class TBaseHelper {
     System.arraycopy(orig, 0, copy, 0, orig.length);
     return copy;
   }
+
+  public static int hashCode(long value) {
+    int low = (int) value;
+    int high = (int) (value >>> 32);
+    return high * 127 + low;
+  }
+
+  public static int hashCode(double value) {
+    return hashCode(Double.doubleToRawLongBits(value));
+  }
 }