You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2020/02/17 15:43:12 UTC

[incubator-iotdb] 02/02: try to connect 6667 to check whether the socket is closed

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

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

commit 70ba6c8de5c8654e57137cb9465d58847d7175f6
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Mon Feb 17 23:41:55 2020 +0800

    try to connect 6667 to check whether the socket is closed
---
 .../apache/iotdb/db/utils/EnvironmentUtils.java    | 27 ++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 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 5c3770b..8c4f931 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
@@ -26,6 +26,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.iotdb.db.auth.AuthException;
 import org.apache.iotdb.db.auth.authorizer.LocalFileAuthorizer;
 import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.conf.adapter.IoTDBConfigDynamicAdapter;
 import org.apache.iotdb.db.conf.directories.DirectoryManager;
@@ -40,6 +41,9 @@ import org.apache.iotdb.db.query.context.QueryContext;
 import org.apache.iotdb.db.query.control.FileReaderManager;
 import org.apache.iotdb.db.query.control.QueryResourceManager;
 import org.apache.iotdb.db.service.IoTDB;
+import org.apache.thrift.transport.TSocket;
+import org.apache.thrift.transport.TTransport;
+import org.apache.thrift.transport.TTransportException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -71,9 +75,15 @@ public class EnvironmentUtils {
       daemon.stop();
       daemon = null;
     }
-
+    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.");
+      } catch (TTransportException e) {
+      }
+    }
     QueryResourceManager.getInstance().endQuery(TEST_QUERY_JOB_ID);
-
     // clear opened file streams
     FileReaderManager.getInstance().closeAndRemoveAllOpenedReaders();
 
@@ -140,6 +150,7 @@ public class EnvironmentUtils {
    * disable memory control</br> this function should be called before all code in the setup
    */
   public static void envSetUp() throws StartupException {
+    System.setProperty(IoTDBConstant.REMOTE_JMX_PORT_NAME, "31999");
     IoTDBDescriptor.getInstance().getConfig().setThriftServerAwaitTimeForStopService(0);
     if (daemon == null) {
       daemon = new IoTDB();
@@ -160,6 +171,18 @@ public class EnvironmentUtils {
     TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID);
   }
 
+  public static void stopDaemon() {
+    if(daemon != null) {
+      daemon.stop();
+    }
+  }
+
+  public static void activeDaemon() {
+    if(daemon != null) {
+      daemon.active();
+    }
+  }
+
   private static void createAllDir() {
     // create sequential files
     for (String path : directoryManager.getAllSequenceFileFolders()) {