You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by to...@apache.org on 2010/08/27 08:16:38 UTC

svn commit: r990032 - in /incubator/thrift/trunk/lib/java: build.xml test/org/apache/thrift/async/TestTAsyncClientManager.java test/org/apache/thrift/server/ServerTestBase.java

Author: todd
Date: Fri Aug 27 06:16:37 2010
New Revision: 990032

URL: http://svn.apache.org/viewvc?rev=990032&view=rev
Log:
THRIFT-873. java: Java tests fail due to Too many open files

- Drops TestTAsyncClientManager to use only 200 clients instead of 500
- Changes each unit test to run in its own JVM instead of sharing them.
- Allows the port used for binding the test servers to be configured from the command line

Modified:
    incubator/thrift/trunk/lib/java/build.xml
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/async/TestTAsyncClientManager.java
    incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java

Modified: incubator/thrift/trunk/lib/java/build.xml
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/build.xml?rev=990032&r1=990031&r2=990032&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/build.xml (original)
+++ incubator/thrift/trunk/lib/java/build.xml Fri Aug 27 06:16:37 2010
@@ -179,16 +179,18 @@
   <property name="test.timeout" value="2000000"/>
   <property name="test.src.dir" location="${basedir}/test"/>
   <property name="test.log.dir" value="${build.test}/log"/>
+  <property name="test.port" value="9090" />
 
   <target name="junit-test" description="Run the JUnit test suite" depends="compile-test">
     <mkdir dir="${test.log.dir}"/>
     <junit
       printsummary="yes" showoutput="${test.output}" 
-      haltonfailure="no" fork="yes" forkmode="once" maxmemory="512m"
+      haltonfailure="no" fork="yes" maxmemory="512m"
       errorProperty="tests.failed" failureProperty="tests.failed"
       timeout="${test.timeout}"
     >
       <sysproperty key="build.test" value="${build.test}"/>
+      <sysproperty key="test.port" value="${test.port}" />
       <classpath refid="test.classpath"/>
       <formatter type="${test.junit.output.format}" />
       <batchtest todir="${test.log.dir}" unless="testcase">

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/async/TestTAsyncClientManager.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/async/TestTAsyncClientManager.java?rev=990032&r1=990031&r2=990032&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/async/TestTAsyncClientManager.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/async/TestTAsyncClientManager.java Fri Aug 27 06:16:37 2010
@@ -30,6 +30,7 @@ import org.apache.thrift.protocol.TBinar
 import org.apache.thrift.server.TNonblockingServer;
 import org.apache.thrift.transport.TNonblockingServerSocket;
 import org.apache.thrift.transport.TNonblockingSocket;
+import org.apache.thrift.server.ServerTestBase;
 
 import thrift.test.CompactProtoTestStruct;
 import thrift.test.Srv;
@@ -95,7 +96,7 @@ public class TestTAsyncClientManager ext
     public JankyRunnable(TAsyncClientManager acm, int numCalls) throws Exception {
       this.acm_ = acm;
       this.numCalls_ = numCalls;
-      this.clientSocket_ = new TNonblockingSocket("localhost", 12345);
+      this.clientSocket_ = new TNonblockingSocket(ServerTestBase.HOST, ServerTestBase.PORT);
       this.client_ = new Srv.AsyncClient(new TBinaryProtocol.Factory(), acm_, clientSocket_);
     }
 
@@ -177,7 +178,8 @@ public class TestTAsyncClientManager ext
 
   public void testIt() throws Exception {
     // put up a server
-    final TNonblockingServer s = new TNonblockingServer(new Srv.Processor(new SrvHandler()), new TNonblockingServerSocket(12345));
+    final TNonblockingServer s = new TNonblockingServer(new Srv.Processor(new SrvHandler()),
+      new TNonblockingServerSocket(ServerTestBase.PORT));
     new Thread(new Runnable() {
       @Override
       public void run() {
@@ -190,7 +192,8 @@ public class TestTAsyncClientManager ext
     TAsyncClientManager acm = new TAsyncClientManager();
 
     // connect an async client
-    TNonblockingSocket clientSock = new TNonblockingSocket("localhost", 12345);
+    TNonblockingSocket clientSock = new TNonblockingSocket(
+      ServerTestBase.HOST, ServerTestBase.PORT);
     Srv.AsyncClient client = new Srv.AsyncClient(new TBinaryProtocol.Factory(), acm, clientSock);
 
     final Object o = new Object();
@@ -268,7 +271,7 @@ public class TestTAsyncClientManager ext
     assertTrue(voidAfterOnewayReturned.get());
 
     // make multiple calls with deserialization in the selector thread (repro Eric's issue)
-    int numThreads = 500;
+    int numThreads = 200;
     int numCallsPerThread = 100;
     List<JankyRunnable> runnables = new ArrayList<JankyRunnable>();
     List<Thread> threads = new ArrayList<Thread>();

Modified: incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java?rev=990032&r1=990031&r2=990032&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java (original)
+++ incubator/thrift/trunk/lib/java/test/org/apache/thrift/server/ServerTestBase.java Fri Aug 27 06:16:37 2010
@@ -275,8 +275,9 @@ public abstract class ServerTestBase ext
       new TBinaryProtocol.Factory(),
       new TCompactProtocol.Factory());
 
-  protected static final String HOST = "localhost";
-  protected static final int PORT = 9090;
+  public static final String HOST = "localhost";
+  public static final int PORT = Integer.valueOf(
+    System.getProperty("test.port", "9090"));
   protected static final int SOCKET_TIMEOUT = 1000;
   private static final Xtruct XSTRUCT = new Xtruct("Zero", (byte) 1, -3, -5);
   private static final Xtruct2 XSTRUCT2 = new Xtruct2((byte)1, XSTRUCT, 5);