Skip to content

Commit 23d1367

Browse files
authored
Pipe IT: Stabilize tree model leader stop test (#17825)
1 parent 44cb7c2 commit 23d1367

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/pipe/it/autocreate/IoTDBPipeClusterIT.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
3838
import org.apache.iotdb.it.framework.IoTDBTestRunner;
3939
import org.apache.iotdb.itbase.category.MultiClusterIT2AutoCreateSchema;
40+
import org.apache.iotdb.itbase.env.BaseEnv;
4041
import org.apache.iotdb.rpc.TSStatusCode;
4142

4243
import org.apache.thrift.TException;
@@ -315,6 +316,8 @@ public void testPipeAfterDataRegionLeaderStop() throws Exception {
315316

316317
TestUtils.executeNonQueries(
317318
senderEnv, Arrays.asList("insert into root.db.d1(time,s1) values (1,1)", "flush"), null);
319+
flushTreeDataRegionReplicasAfterReplicationComplete(
320+
senderEnv, Collections.singletonList("root.db"));
318321

319322
final int leaderIndex = restartTreeDataRegionLeader(client, "root.db");
320323
if (leaderIndex == -1) { // ensure the leader is stopped
@@ -333,7 +336,10 @@ public void testPipeAfterDataRegionLeaderStop() throws Exception {
333336
"select count(*) from root.db.d1",
334337
"count(root.db.d1.s1),",
335338
Collections.singleton("2,"));
336-
waitForTreeDataRegionReplicationComplete(Collections.singletonList("root.db"));
339+
flushTreeDataRegionReplicasAfterReplicationComplete(
340+
senderEnv, Collections.singletonList("root.db"));
341+
flushTreeDataRegionReplicasAfterReplicationComplete(
342+
receiverEnv, Collections.singletonList("root.db"));
337343
}
338344

339345
try {
@@ -427,14 +433,22 @@ private int restartTreeDataRegionLeader(
427433
return -1;
428434
}
429435

430-
private void waitForTreeDataRegionReplicationComplete(final List<String> databases) {
436+
private void flushTreeDataRegionReplicasAfterReplicationComplete(
437+
final BaseEnv env, final List<String> databases) {
438+
waitForTreeDataRegionReplicationComplete(env, databases);
439+
TestUtils.executeNonQueryWithRetry(env, "flush");
440+
waitForTreeDataRegionReplicationComplete(env, databases);
441+
}
442+
443+
private void waitForTreeDataRegionReplicationComplete(
444+
final BaseEnv env, final List<String> databases) {
431445
await()
432446
.pollInterval(500, TimeUnit.MILLISECONDS)
433447
.atMost(2, TimeUnit.MINUTES)
434448
.untilAsserted(
435449
() -> {
436450
try (final SyncConfigNodeIServiceClient client =
437-
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
451+
(SyncConfigNodeIServiceClient) env.getLeaderConfigNodeConnection()) {
438452
final List<TRegionInfo> leaderRegionInfoList =
439453
showTreeDataRegionLeaders(databases, client);
440454
Assert.assertFalse(
@@ -443,14 +457,14 @@ private void waitForTreeDataRegionReplicationComplete(final List<String> databas
443457

444458
for (final TRegionInfo regionInfo : leaderRegionInfoList) {
445459
final DataNodeWrapper leaderNode =
446-
findDataNodeWrapperByPort(regionInfo.getClientRpcPort());
460+
findDataNodeWrapperByPort(env, regionInfo.getClientRpcPort());
447461
final String metricsUrl =
448462
"http://"
449463
+ leaderNode.getIp()
450464
+ ":"
451465
+ leaderNode.getMetricPort()
452466
+ "/metrics";
453-
final String metricsContent = senderEnv.getUrlContent(metricsUrl, null);
467+
final String metricsContent = env.getUrlContent(metricsUrl, null);
454468
Assert.assertNotNull(
455469
"Failed to fetch metrics from leader DataNode at " + metricsUrl,
456470
metricsContent);
@@ -478,8 +492,8 @@ private List<TRegionInfo> showTreeDataRegionLeaders(
478492
return result;
479493
}
480494

481-
private DataNodeWrapper findDataNodeWrapperByPort(final int port) {
482-
for (final DataNodeWrapper dataNodeWrapper : senderEnv.getDataNodeWrapperList()) {
495+
private DataNodeWrapper findDataNodeWrapperByPort(final BaseEnv env, final int port) {
496+
for (final DataNodeWrapper dataNodeWrapper : env.getDataNodeWrapperList()) {
483497
if (dataNodeWrapper.getPort() == port) {
484498
return dataNodeWrapper;
485499
}

0 commit comments

Comments
 (0)