You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by er...@apache.org on 2022/12/28 07:15:24 UTC
[iotdb] 01/01: [IOTDB-5297] Add maxRetryTimes for IoTDBClusterNodeErrorStartUpIT to avoid infinite loop (#8628)
This is an automated email from the ASF dual-hosted git repository.
ericpai pushed a commit to branch bugfix/cp-iotdb-5297
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 1045996c94c61b4fd60f4e5f73f0f1c50212705d
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();
+ }
}