flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpe...@apache.org
Subject svn commit: r1359374 - in /flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test: agent/TestRpcClient.java agent/TestRpcClientCommunicationFailure.java util/StagedInstall.java
Date Mon, 09 Jul 2012 20:04:06 GMT
Author: mpercy
Date: Mon Jul  9 20:04:05 2012
New Revision: 1359374

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

(Hari Shreedharan via Mike Percy)

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

Modified: flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java
URL: http://svn.apache.org/viewvc/flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java?rev=1359374&r1=1359373&r2=1359374&view=diff
==============================================================================
--- flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java
(original)
+++ flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClient.java
Mon Jul  9 20:04:05 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/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java
URL: http://svn.apache.org/viewvc/flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java?rev=1359374&r1=1359373&r2=1359374&view=diff
==============================================================================
--- flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java
(original)
+++ flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestRpcClientCommunicationFailure.java
Mon Jul  9 20:04:05 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/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
URL: http://svn.apache.org/viewvc/flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java?rev=1359374&r1=1359373&r2=1359374&view=diff
==============================================================================
--- flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
(original)
+++ flume/trunk/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
Mon Jul  9 20:04:05 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) {



Mime
View raw message