You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2021/12/10 09:46:08 UTC

[iotdb] 01/01: [IOTDB-2130] IT fails on MQTTSinkTest.onEventUsingMultiSensorsHandler

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

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

commit 06fab120e308aa63848739ab7c9157e45254ed88
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Fri Dec 10 17:45:09 2021 +0800

    [IOTDB-2130] IT fails on MQTTSinkTest.onEventUsingMultiSensorsHandler
---
 .../java/org/apache/iotdb/db/sink/MQTTSinkTest.java    | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/server/src/test/java/org/apache/iotdb/db/sink/MQTTSinkTest.java b/server/src/test/java/org/apache/iotdb/db/sink/MQTTSinkTest.java
index cfcbabd..7ba4f3f 100644
--- a/server/src/test/java/org/apache/iotdb/db/sink/MQTTSinkTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/sink/MQTTSinkTest.java
@@ -43,6 +43,8 @@ import java.sql.Types;
 import java.util.HashMap;
 import java.util.Map;
 
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.awaitility.Awaitility.await;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
@@ -78,8 +80,11 @@ public class MQTTSinkTest {
 
     mqttHandler.close();
 
-    Thread.sleep(1000);
+    await().atMost(1, MINUTES).until(() -> 10000 == checkSingleSensorHandlerResult());
+  }
 
+  private int checkSingleSensorHandlerResult() throws ClassNotFoundException {
+    int count = 0;
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection =
             DriverManager.getConnection(
@@ -97,19 +102,18 @@ public class MQTTSinkTest {
               Types.TIMESTAMP, Types.FLOAT,
             });
 
-        int count = 0;
         while (resultSet.next()) {
           for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
             assertEquals(count, Double.parseDouble(resultSet.getString(i)), 0.0);
           }
           count++;
         }
-        Assert.assertEquals(10000, count);
       }
     } catch (Exception e) {
       e.printStackTrace();
       fail(e.getMessage());
     }
+    return count;
   }
 
   @Test
@@ -141,8 +145,11 @@ public class MQTTSinkTest {
 
     mqttHandler.close();
 
-    Thread.sleep(1000);
+    await().atMost(1, MINUTES).until(() -> 10000 == checkMultiSensorsHandlerResult());
+  }
 
+  private int checkMultiSensorsHandlerResult() throws ClassNotFoundException {
+    int count = 0;
     Class.forName(Config.JDBC_DRIVER_NAME);
     try (Connection connection =
             DriverManager.getConnection(
@@ -167,7 +174,6 @@ public class MQTTSinkTest {
               Types.FLOAT,
             });
 
-        int count = 0;
         while (resultSet.next()) {
           for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
             try {
@@ -178,12 +184,12 @@ public class MQTTSinkTest {
           }
           count++;
         }
-        Assert.assertEquals(10000, count);
       }
     } catch (Exception e) {
       e.printStackTrace();
       fail(e.getMessage());
     }
+    return count;
   }
 
   private void checkHeader(