This is an automated email from the ASF dual-hosted git repository.

hxd pushed a commit to branch test_travis
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/test_travis by this push:
     new 40d37a2  try to test ports twice
40d37a2 is described below

commit 40d37a29592dbd6c306cb88480e259eba340c01c
Author: xiangdong huang <[email protected]>
AuthorDate: Fri Nov 6 11:01:33 2020 +0800

    try to test ports twice
---
 .../apache/iotdb/db/utils/EnvironmentUtils.java    | 102 +++++++++++++--------
 1 file changed, 63 insertions(+), 39 deletions(-)

diff --git 
a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java 
b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
index 8cbe16f..c381246 100644
--- a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
+++ b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
@@ -24,6 +24,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
+import java.util.stream.IntStream;
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
@@ -88,49 +89,19 @@ public class EnvironmentUtils {
 
     if (examinePorts) {
       // TODO: this is just too slow, especially on Windows, consider a better 
way
-      TTransport transport = new TSocket("127.0.0.1", 6667, 100);
-      if (!transport.isOpen()) {
+      boolean closed = examinePorts();
+      if (!closed) {
+        //sleep 10 seconds
         try {
-          transport.open();
-          logger.error("stop daemon failed. 6667 can be connected now.");
-          transport.close();
-          Assert.fail("stop daemon failed. 6667 can be connected now.");
-        } catch (TTransportException e) {
+          Thread.sleep(10_000);
+        } catch (InterruptedException e) {
+          //do nothing
         }
-      }
-      //try sync service
-      transport = new TSocket("127.0.0.1", 5555, 100);
-      if (!transport.isOpen()) {
-        try {
-          transport.open();
-          logger.error("stop Sync daemon failed. 5555 can be connected now.");
-          transport.close();
-          Assert.fail("stop daemon failed. 6667 can be connected now.");
-        } catch (TTransportException e) {
+
+        if (!examinePorts()) {
+          fail("failed to close some ports");
         }
       }
-      //try jmx connection
-      try {
-        JMXServiceURL url =
-            new 
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:31999/jmxrmi");
-        JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
-        logger.error("stop JMX failed. 31999 can be connected now.");
-        jmxConnector.close();
-        Assert.fail("stop daemon failed. 6667 can be connected now.");
-      } catch (IOException e) {
-        //do nothing
-      }
-      //try MetricService
-      Socket socket = new Socket();
-      try {
-        socket.connect(new InetSocketAddress("127.0.0.1", 8181), 100);
-        logger.error("stop MetricService failed. 8181 can be connected now.");
-        Assert.fail("stop daemon failed. 6667 can be connected now.");
-      } catch (Exception e) {
-        //do nothing
-      } finally {
-        socket.close();
-      }
     }
 
     // clean storage group manager
@@ -167,6 +138,59 @@ public class EnvironmentUtils {
     config.setMemtableSizeThreshold(oldGroupSizeInByte);
   }
 
+
+  private static boolean examinePorts() {
+    TTransport transport = new TSocket("127.0.0.1", 6667, 100);
+    if (!transport.isOpen()) {
+      try {
+        transport.open();
+        logger.error("stop daemon failed. 6667 can be connected now.");
+        transport.close();
+        return false;
+      } catch (TTransportException e) {
+      }
+    }
+    //try sync service
+    transport = new TSocket("127.0.0.1", 5555, 100);
+    if (!transport.isOpen()) {
+      try {
+        transport.open();
+        logger.error("stop Sync daemon failed. 5555 can be connected now.");
+        transport.close();
+        return false;
+      } catch (TTransportException e) {
+      }
+    }
+    //try jmx connection
+    try {
+      JMXServiceURL url =
+          new 
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:31999/jmxrmi");
+      JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
+      logger.error("stop JMX failed. 31999 can be connected now.");
+      jmxConnector.close();
+      return false;
+    } catch (IOException e) {
+      //do nothing
+    }
+    //try MetricService
+    Socket socket = new Socket();
+    try {
+      socket.connect(new InetSocketAddress("127.0.0.1", 8181), 100);
+      logger.error("stop MetricService failed. 8181 can be connected now.");
+      return false;
+    } catch (Exception e) {
+      //do nothing
+    } finally {
+      try {
+        socket.close();
+      } catch (IOException e) {
+        //do nothing
+      }
+    }
+    return true;
+  }
+
+
   public static void cleanAllDir() throws IOException {
     // delete sequential files
     for (String path : directoryManager.getAllSequenceFileFolders()) {

Reply via email to