You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ca...@apache.org on 2022/12/28 07:08:53 UTC

[iotdb] branch master updated: [IOTDB-5297] Add maxRetryTimes for IoTDBClusterNodeErrorStartUpIT to avoid infinite loop (#8628)

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

caogaofei 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 db38945c16 [IOTDB-5297] Add maxRetryTimes for IoTDBClusterNodeErrorStartUpIT to avoid infinite loop (#8628)
db38945c16 is described below

commit db38945c1691476cf87e0ff8f515536939e8b6c3
Author: BaiJian <er...@hotmail.com>
AuthorDate: Wed Dec 28 15:08:47 2022 +0800

    [IOTDB-5297] Add maxRetryTimes for IoTDBClusterNodeErrorStartUpIT to avoid infinite loop (#8628)
---
 .../it/cluster/IoTDBClusterNodeErrorStartUpIT.java | 48 ++++++++++++++++++++--
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java b/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java
index 65b8bedad1..b1ccbd6a32 100644
--- a/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/confignode/it/cluster/IoTDBClusterNodeErrorStartUpIT.java
@@ -50,6 +50,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
@@ -60,16 +62,20 @@ import java.util.concurrent.atomic.AtomicInteger;
 @Category({ClusterIT.class})
 public class IoTDBClusterNodeErrorStartUpIT {
 
+  private static final Logger logger =
+      LoggerFactory.getLogger(IoTDBClusterNodeErrorStartUpIT.class);
   private static final BaseConfig CONF = ConfigFactory.getConfig();
 
   private static final int testConfigNodeNum = 3;
   private static final int testDataNodeNum = 1;
+  private static final int testNodeNum = testConfigNodeNum + testDataNodeNum;
 
   protected static String originalConfigNodeConsensusProtocolClass;
   private static final String testConsensusProtocolClass = ConsensusFactory.RATIS_CONSENSUS;
 
   private static final String TEST_CLUSTER_NAME = "defaultCluster";
   private static final String ERROR_CLUSTER_NAME = "errorCluster";
+  private static final int maxRetryTimes = 60;
 
   @Before
   public void setUp() throws Exception {
@@ -240,7 +246,8 @@ public class IoTDBClusterNodeErrorStartUpIT {
       // Shutdown and check
       EnvFactory.getEnv().shutdownConfigNode(1);
       EnvFactory.getEnv().shutdownDataNode(0);
-      while (true) {
+      int retryTimes;
+      for (retryTimes = 0; retryTimes < maxRetryTimes; retryTimes++) {
         AtomicInteger unknownCnt = new AtomicInteger(0);
         showClusterResp = client.showCluster();
         showClusterResp
@@ -252,11 +259,16 @@ public class IoTDBClusterNodeErrorStartUpIT {
                   }
                 });
 
-        if (unknownCnt.get() == 2) {
+        if (unknownCnt.get() == testNodeNum - 2) {
           break;
         }
         TimeUnit.SECONDS.sleep(1);
       }
+      logger.info(showClusterStatus(showClusterResp));
+      if (retryTimes >= maxRetryTimes) {
+        Assert.fail(
+            "The running nodes are still insufficient after retrying " + maxRetryTimes + " times");
+      }
 
       /* Restart and updatePeer */
       // TODO: @Itami-sho, enable this test and delete it
@@ -286,7 +298,7 @@ public class IoTDBClusterNodeErrorStartUpIT {
       // Restart and check
       EnvFactory.getEnv().startConfigNode(1);
       EnvFactory.getEnv().startDataNode(0);
-      while (true) {
+      for (retryTimes = 0; retryTimes < maxRetryTimes; retryTimes++) {
         AtomicInteger runningCnt = new AtomicInteger(0);
         showClusterResp = client.showCluster();
         showClusterResp
@@ -298,11 +310,39 @@ public class IoTDBClusterNodeErrorStartUpIT {
                   }
                 });
 
-        if (runningCnt.get() == 3) {
+        if (runningCnt.get() == testNodeNum) {
           break;
         }
         TimeUnit.SECONDS.sleep(1);
       }
+      logger.info(showClusterStatus(showClusterResp));
+      if (retryTimes >= maxRetryTimes) {
+        Assert.fail(
+            "The running nodes are still insufficient after retrying " + maxRetryTimes + " times");
+      }
     }
   }
+
+  private String showClusterStatus(TShowClusterResp showClusterResp) {
+    StringBuilder sb = new StringBuilder();
+    showClusterResp
+        .getConfigNodeList()
+        .forEach(
+            d ->
+                sb.append("ConfigNode")
+                    .append(d.getInternalEndPoint().getPort())
+                    .append(": ")
+                    .append(showClusterResp.getNodeStatus().get(d.getConfigNodeId()))
+                    .append("\n"));
+    showClusterResp
+        .getDataNodeList()
+        .forEach(
+            d ->
+                sb.append("DataNode")
+                    .append(d.getClientRpcEndPoint().getPort())
+                    .append(": ")
+                    .append(showClusterResp.getNodeStatus().get(d.getDataNodeId()))
+                    .append("\n"));
+    return sb.toString();
+  }
 }