add sync function for jdbc server to close and remove sleep fuction in ITs 46/head
authorMyXOF <xuyi556677@163.com>
Wed, 13 Feb 2019 15:57:06 +0000 (23:57 +0800)
committerMyXOF <xuyi556677@163.com>
Wed, 13 Feb 2019 15:57:06 +0000 (23:57 +0800)
12 files changed:
iotdb/src/main/java/org/apache/iotdb/db/service/JDBCService.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBAuthorizationIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBCompleteIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBDaemonIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBEngineTimeGeneratorIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBLargeDataIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBLimitSlimitIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBMetadataFetchIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBSequenceDataQueryIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBSeriesReaderIT.java
iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBTimeZoneIT.java

index edb115e..6570189 100644 (file)
@@ -19,6 +19,7 @@
 package org.apache.iotdb.db.service;
 
 import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.iotdb.db.concurrent.IoTDBThreadPoolFactory;
@@ -50,14 +51,13 @@ public class JDBCService implements JDBCServiceMBean, IService {
       .format("%s:%s=%s", IoTDBConstant.IOTDB_PACKAGE, IoTDBConstant.JMX_TYPE,
           getID().getJmxName());
   private Thread jdbcServiceThread;
-  private boolean isStart;
   private Factory protocolFactory;
   private Processor<TSIService.Iface> processor;
   private TThreadPoolServer.Args poolArgs;
   private TSServiceImpl impl;
+  private CountDownLatch countDownLatch;
 
   private JDBCService() {
-    isStart = false;
   }
 
   public static final JDBCService getInstance() {
@@ -66,7 +66,11 @@ public class JDBCService implements JDBCServiceMBean, IService {
 
   @Override
   public String getJDBCServiceStatus() {
-    return isStart ? STATUS_UP : STATUS_DOWN;
+    if(countDownLatch == null || countDownLatch.getCount() == 0){
+      return STATUS_DOWN;
+    } else{
+      return STATUS_UP;
+    }
   }
 
   @Override
@@ -84,7 +88,6 @@ public class JDBCService implements JDBCServiceMBean, IService {
       LOGGER.error("Failed to start {} because: ", this.getID().getName(), e);
       throw new StartupException(e);
     }
-
   }
 
   @Override
@@ -100,16 +103,17 @@ public class JDBCService implements JDBCServiceMBean, IService {
 
   @Override
   public synchronized void startService() throws StartupException {
-    if (isStart) {
+    if (STATUS_UP.equals(getJDBCServiceStatus())) {
       LOGGER.info("{}: {} has been already running now", IoTDBConstant.GLOBAL_DB_NAME,
           this.getID().getName());
       return;
     }
     LOGGER.info("{}: start {}...", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName());
-
     try {
-      jdbcServiceThread = new JDBCServiceThread();
+      countDownLatch = new CountDownLatch(1);
+      jdbcServiceThread = new JDBCServiceThread(countDownLatch);
       jdbcServiceThread.setName(ThreadName.JDBC_SERVICE.getName());
+      jdbcServiceThread.start();
     } catch (IOException e) {
       String errorMessage = String
           .format("Failed to start %s because of %s", this.getID().getName(),
@@ -117,11 +121,9 @@ public class JDBCService implements JDBCServiceMBean, IService {
       LOGGER.error(errorMessage);
       throw new StartupException(errorMessage);
     }
-    jdbcServiceThread.start();
 
     LOGGER.info("{}: start {} successfully, listening on port {}", IoTDBConstant.GLOBAL_DB_NAME,
         this.getID().getName(), IoTDBDescriptor.getInstance().getConfig().rpcPort);
-    isStart = true;
   }
 
   @Override
@@ -132,7 +134,7 @@ public class JDBCService implements JDBCServiceMBean, IService {
 
   @Override
   public synchronized void stopService() {
-    if (!isStart) {
+    if (STATUS_DOWN.equals(getJDBCServiceStatus())) {
       LOGGER.info("{}: {} isn't running now", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName());
       return;
     }
@@ -140,17 +142,19 @@ public class JDBCService implements JDBCServiceMBean, IService {
     if (jdbcServiceThread != null) {
       ((JDBCServiceThread) jdbcServiceThread).close();
     }
-    LOGGER.info("{}: close {} successfully", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName());
+    try {
+      countDownLatch.await();
+      LOGGER.info("{}: close {} successfully", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName());
+    } catch (InterruptedException e) {
+      LOGGER.error("{}: close {} failed because {}", IoTDBConstant.GLOBAL_DB_NAME, this.getID().getName(), e);
+    }
   }
 
-
-
   private static class JDBCServiceHolder {
 
     private static final JDBCService INSTANCE = new JDBCService();
 
     private JDBCServiceHolder() {
-
     }
   }
 
@@ -158,11 +162,13 @@ public class JDBCService implements JDBCServiceMBean, IService {
 
     private TServerSocket serverTransport;
     private TServer poolServer;
+    private CountDownLatch latch;
 
-    public JDBCServiceThread() throws IOException {
+    public JDBCServiceThread(CountDownLatch latch) throws IOException {
       protocolFactory = new TBinaryProtocol.Factory();
       impl = new TSServiceImpl();
       processor = new TSIService.Processor<>(impl);
+      this.latch = latch;
     }
 
     @Override
@@ -200,7 +206,7 @@ public class JDBCService implements JDBCServiceMBean, IService {
         serverTransport.close();
         serverTransport = null;
       }
-      isStart = false;
+      latch.countDown();
     }
   }
 }
index abf32e9..37d7327 100644 (file)
@@ -62,7 +62,6 @@ public class IoTDBAuthorizationIT {
   @After
   public void tearDown() throws Exception {
     deamon.stop();
-    Thread.sleep(2000);
     EnvironmentUtils.cleanEnv();
   }
 
index cf49ce1..be187c2 100644 (file)
@@ -53,7 +53,6 @@ public class IoTDBCompleteIT {
   @After
   public void tearDown() throws Exception {
     deamon.stop();
-    Thread.sleep(5000);
     EnvironmentUtils.cleanEnv();
   }
 
index ab65f6b..7bc96e4 100644 (file)
@@ -128,8 +128,6 @@ public class IoTDBDaemonIT {
   public static void tearDown() throws Exception {
     connection.close();
     deamon.stop();
-    Thread.sleep(5000);
-
     EnvironmentUtils.cleanEnv();
   }
 
index c7ca523..e7a8200 100644 (file)
@@ -93,8 +93,6 @@ public class IoTDBEngineTimeGeneratorIT {
     connection.close();
 
     daemon.stop();
-    Thread.sleep(5000);
-
     // recovery value
     tsFileConfig.maxNumberOfPointsInPage = maxNumberOfPointsInPage;
     tsFileConfig.pageSizeInByte = pageSizeInByte;
index ffc429a..8b10d0c 100644 (file)
@@ -87,7 +87,6 @@ public class IoTDBLargeDataIT {
     connection.close();\r
 \r
     deamon.stop();\r
-    Thread.sleep(5000);\r
 \r
     // recovery value\r
     tsFileConfig.maxNumberOfPointsInPage = maxNumberOfPointsInPage;\r
index 659cd1e..c9baccb 100644 (file)
@@ -99,7 +99,6 @@ public class IoTDBLimitSlimitIT {
   @AfterClass
   public static void tearDown() throws Exception {
     deamon.stop();
-    Thread.sleep(5000);
     EnvironmentUtils.cleanEnv();
   }
 
index 7b3f7fe..a266258 100644 (file)
@@ -89,7 +89,6 @@ public class IoTDBMetadataFetchIT {
   @After
   public void tearDown() throws Exception {
     deamon.stop();
-    Thread.sleep(5000);
     EnvironmentUtils.cleanEnv();
   }
 
index 018c325..c1ca654 100644 (file)
@@ -87,8 +87,6 @@ public class IoTDBMultiSeriesIT {
     connection.close();\r
 \r
     deamon.stop();\r
-    Thread.sleep(5000);\r
-\r
     // recovery value\r
     tsFileConfig.maxNumberOfPointsInPage = maxNumberOfPointsInPage;\r
     tsFileConfig.pageSizeInByte = pageSizeInByte;\r
index 821e162..4598176 100644 (file)
@@ -93,8 +93,6 @@ public class IoTDBSequenceDataQueryIT {
     connection.close();
 
     daemon.stop();
-    Thread.sleep(5000);
-
     // recovery value
     tsFileConfig.maxNumberOfPointsInPage = maxNumberOfPointsInPage;
     tsFileConfig.pageSizeInByte = pageSizeInByte;
index 86b6812..e3bd59c 100644 (file)
@@ -91,8 +91,6 @@ public class IoTDBSeriesReaderIT {
   public static void tearDown() throws Exception {
     connection.close();
     deamon.stop();
-    Thread.sleep(5000);
-
     // recovery value
     tsFileConfig.maxNumberOfPointsInPage = maxNumberOfPointsInPage;
     tsFileConfig.pageSizeInByte = pageSizeInByte;
index 6e954d0..995dc0f 100644 (file)
@@ -66,7 +66,6 @@ public class IoTDBTimeZoneIT {
   public void tearDown() throws Exception {
     // if (testFlag) {
     deamon.stop();
-    Thread.sleep(5000);
     EnvironmentUtils.cleanEnv();
     // }
   }