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

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


The following commit(s) were added to refs/heads/master by this push:
     new ffab5bd  [IOTDB-1845] Make the test results in IoTDBTriggerExecutionIT 
& IoTDBContinuousQueryIT deterministic (#4161)
ffab5bd is described below

commit ffab5bd9f100edf0ca314002c24a860b69bd6f81
Author: Steve Yurong Su <[email protected]>
AuthorDate: Thu Oct 14 19:24:21 2021 +0800

    [IOTDB-1845] Make the test results in IoTDBTriggerExecutionIT & 
IoTDBContinuousQueryIT deterministic (#4161)
    
    * Make the test results in IoTDBTriggerExecutionIT deterministic
    
    * Make the test results in IoTDBContinuousQueryIT deterministic
---
 .../db/integration/IoTDBContinuousQueryIT.java     |  8 ++--
 .../db/integration/IoTDBTriggerExecutionIT.java    | 53 ++++++++++++----------
 2 files changed, 33 insertions(+), 28 deletions(-)

diff --git 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBContinuousQueryIT.java
 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBContinuousQueryIT.java
index a0cc4c7..00ead26 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBContinuousQueryIT.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBContinuousQueryIT.java
@@ -317,11 +317,11 @@ public class IoTDBContinuousQueryIT {
     }
 
     final long expectedSize = (duration / everyInterval + 1) * (forInterval / 
groupByInterval);
-    long waitSeconds = 0;
+    long waitMillSeconds = 0;
     List<Pair<Long, String>> result;
     do {
-      Thread.sleep(waitSeconds);
-      waitSeconds += 1000;
+      Thread.sleep(waitMillSeconds);
+      waitMillSeconds += 100;
 
       statement.execute("select temperature_avg from root.ln.wf01");
       result = collectQueryResult();
@@ -332,7 +332,7 @@ public class IoTDBContinuousQueryIT {
       long left = result.get(i).left;
 
       if (i == 0) {
-        assertTrue(Math.abs(creationTime + delay - forInterval - left) <= 100);
+        assertTrue(Math.abs(creationTime + delay - forInterval - left) < 2 * 
forInterval);
       } else {
         long pointNumPerForInterval = forInterval / groupByInterval;
         Assert.assertEquals(
diff --git 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTriggerExecutionIT.java
 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTriggerExecutionIT.java
index dba1a90..d83629c 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTriggerExecutionIT.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTriggerExecutionIT.java
@@ -48,11 +48,11 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-@SuppressWarnings("squid:S2925") // enable to use Thread.sleep(long) without 
warnings
 public class IoTDBTriggerExecutionIT {
 
   private static final Logger LOGGER = 
LoggerFactory.getLogger(IoTDBTriggerExecutionIT.class);
 
+  private volatile long count = 0;
   private volatile Exception exception = null;
 
   private final Thread dataGenerator =
@@ -65,7 +65,6 @@ public class IoTDBTriggerExecutionIT {
                       Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", 
"root");
               Statement statement = connection.createStatement()) {
 
-            long count = 0;
             do {
               ++count;
               statement.execute(
@@ -141,6 +140,13 @@ public class IoTDBTriggerExecutionIT {
     EnvironmentUtils.cleanEnv();
   }
 
+  private void waitCountIncreaseBy(final long increment) throws 
InterruptedException {
+    final long previous = count;
+    while (count - previous < increment) {
+      Thread.sleep(100);
+    }
+  }
+
   @Test
   public void checkFireTimes() throws InterruptedException {
     try (Connection connection =
@@ -167,7 +173,7 @@ public class IoTDBTriggerExecutionIT {
       }
 
       startDataGenerator();
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
       stopDataGenerator();
 
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
@@ -196,7 +202,7 @@ public class IoTDBTriggerExecutionIT {
             DriverManager.getConnection(
                 Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       statement.execute(
           "create trigger trigger-1 before insert on root.vehicle.d1.s1 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
@@ -205,7 +211,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute(
           "create trigger trigger-3 before insert on root.vehicle.d1.s3 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
       // will be meaningless, in which case we ignore the checks
@@ -213,12 +219,11 @@ public class IoTDBTriggerExecutionIT {
         return;
       }
       int[] counters1 = getCounters(3);
-      LOGGER.info(Arrays.toString(counters1));
       for (int i = 0; i < 3; ++i) {
         assertTrue(Counter.BASE < counters1[i]);
       }
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       statement.execute(
           "create trigger trigger-4 after insert on root.vehicle.d1.s4 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
@@ -252,7 +257,7 @@ public class IoTDBTriggerExecutionIT {
             DriverManager.getConnection(
                 Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       statement.execute(
           "create trigger trigger-1 before insert on root.vehicle.d1.s1 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
@@ -261,7 +266,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute(
           "create trigger trigger-3 before insert on root.vehicle.d1.s3 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
       // will be meaningless, in which case we ignore the checks
@@ -274,22 +279,22 @@ public class IoTDBTriggerExecutionIT {
         assertTrue(Counter.BASE < counters1[i]);
       }
 
-      Thread.sleep(100);
+      waitCountIncreaseBy(100);
       statement.execute("drop trigger trigger-1");
       statement.execute("drop trigger trigger-2");
       statement.execute("drop trigger trigger-3");
-      Thread.sleep(100);
+      waitCountIncreaseBy(100);
       statement.execute(
           "create trigger trigger-1 before insert on root.vehicle.d1.s1 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
       statement.execute(
           "create trigger trigger-2 after insert on root.vehicle.d1.s2 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
       statement.execute(
           "create trigger trigger-3 before insert on root.vehicle.d1.s3 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
-      Thread.sleep(100);
+      waitCountIncreaseBy(100);
       statement.execute("drop trigger trigger-1");
       statement.execute("drop trigger trigger-2");
       statement.execute("drop trigger trigger-3");
-      Thread.sleep(100);
+      waitCountIncreaseBy(100);
       statement.execute(
           "create trigger trigger-1 before insert on root.vehicle.d1.s1 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
       statement.execute(
@@ -297,7 +302,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute(
           "create trigger trigger-3 before insert on root.vehicle.d1.s3 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
       // will be meaningless, in which case we ignore the checks
@@ -324,7 +329,7 @@ public class IoTDBTriggerExecutionIT {
             DriverManager.getConnection(
                 Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       statement.execute(
           "create trigger trigger-1 before insert on root.vehicle.d1.s1 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
@@ -339,7 +344,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute(
           "create trigger trigger-6 after insert on root.vehicle.d1.s6 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       statement.execute("stop trigger trigger-1");
       statement.execute("stop trigger trigger-2");
@@ -348,7 +353,7 @@ public class IoTDBTriggerExecutionIT {
       int[] counters1 = getCounters(6);
       LOGGER.info(Arrays.toString(counters1));
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       statement.execute("stop trigger trigger-4");
       statement.execute("stop trigger trigger-5");
@@ -373,7 +378,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute("start trigger trigger-2");
       statement.execute("start trigger trigger-3");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
       // will be meaningless, in which case we ignore the checks
@@ -393,7 +398,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute("start trigger trigger-5");
       statement.execute("start trigger trigger-6");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
       // will be meaningless, in which case we ignore the checks
@@ -413,9 +418,9 @@ public class IoTDBTriggerExecutionIT {
       statement.execute("stop trigger trigger-5");
       statement.execute("stop trigger trigger-6");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
       int[] counters5 = getCounters(6);
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
       int[] counters6 = getCounters(6);
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
       // will be meaningless, in which case we ignore the checks
@@ -448,7 +453,7 @@ public class IoTDBTriggerExecutionIT {
             DriverManager.getConnection(
                 Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
         Statement statement = connection.createStatement()) {
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       statement.execute(
           "create trigger trigger-1 before insert on root.vehicle.d1.s1 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
@@ -463,7 +468,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute(
           "create trigger trigger-6 after insert on root.vehicle.d1.s6 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       // IOTDB-1825: if the background data generator's connection is closed, 
the following checks
       // will be meaningless, in which case we ignore the checks
@@ -553,7 +558,7 @@ public class IoTDBTriggerExecutionIT {
       statement.execute(
           "create trigger trigger-6 after insert on root.vehicle.d1.s6 as 
\"org.apache.iotdb.db.engine.trigger.example.Counter\"");
 
-      Thread.sleep(500);
+      waitCountIncreaseBy(500);
 
       stopDataGenerator();
 

Reply via email to