You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flume.apache.org by mp...@apache.org on 2012/07/09 23:00:44 UTC

svn commit: r1359387 - in /flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test: agent/TestRpcClient.java agent/TestRpcClientCommunicationFailure.java util/StagedInstall.java

Author: mpercy
Date: Mon Jul  9 21:00:43 2012
New Revision: 1359387

URL: http://svn.apache.org/viewvc?rev=1359387&view=rev
Log:
FLUME-1297. Tests should wait until socket opens

(Hari Shreedharan via Mike Percy)

Modified:
    flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java
    flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java
    flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java

Modified: flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java
URL: http://svn.apache.org/viewvc/flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java?rev=1359387&r1=1359386&r2=1359387&view=diff
==============================================================================
--- flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java (original)
+++ flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java Mon Jul  9 21:00:43 2012
@@ -44,6 +44,7 @@ public class TestRpcClient {
 
   @Test
   public void testRpcClient() throws Exception {
+    StagedInstall.waitUntilPortOpens("localhost", 12121, 20000);
     RpcClient client = RpcClientFactory.getDefaultInstance("localhost", 12121);
     String[] text = {"foo", "bar", "xyz", "abc"};
     for (String str : text) {

Modified: flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java
URL: http://svn.apache.org/viewvc/flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java?rev=1359387&r1=1359386&r2=1359387&view=diff
==============================================================================
--- flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java (original)
+++ flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java Mon Jul  9 21:00:43 2012
@@ -35,9 +35,10 @@ public class TestRpcClientCommunicationF
    @Test
    public void testFailure() throws Exception {
      try {
+
        StagedInstall.getInstance().startAgent(
          "rpccagent", CONFIG_FILE_PRCCLIENT_TEST);
-
+       StagedInstall.waitUntilPortOpens("localhost", 12121, 20000);
        RpcClient client = RpcClientFactory.getDefaultInstance(
            "localhost", 12121);
        String[] text = {"foo", "bar", "xyz", "abc"};

Modified: flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
URL: http://svn.apache.org/viewvc/flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java?rev=1359387&r1=1359386&r2=1359387&view=diff
==============================================================================
--- flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java (original)
+++ flume/branches/branch-1.2.0/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java Mon Jul  9 21:00:43 2012
@@ -22,8 +22,10 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.Socket;
 import java.util.Map;
 import java.util.Properties;
 import java.util.zip.GZIPInputStream;
@@ -435,6 +437,27 @@ public class StagedInstall {
     return tarballPath;
   }
 
+  public static void waitUntilPortOpens(String host, int port, long timeout)
+      throws IOException, InterruptedException{
+    long startTime = System.currentTimeMillis();
+    Socket socket;
+    boolean connected = false;
+    //See if port has opened for timeout.
+    while(System.currentTimeMillis() - startTime < timeout){
+      try{
+        socket = new Socket(host, port);
+        socket.close();
+        connected = true;
+        break;
+      } catch (IOException e){
+        Thread.sleep(2000);
+      }
+    }
+    if(!connected) {
+      throw new IOException("Port not opened within specified timeout.");
+    }
+  }
+
   private class ProcessShutdownHook extends Thread {
     public void run() {
       synchronized (StagedInstall.this) {