IGNITE-22184 Fix race in ItClusterManagerTest#testJoinInvalidTag (#3719)
diff --git a/modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java b/modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java
index 6ffa8a7..75b2171 100644
--- a/modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java
+++ b/modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/ItClusterManagerTest.java
@@ -19,6 +19,7 @@
import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrow;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.will;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
@@ -36,11 +37,10 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+import org.apache.ignite.internal.cluster.management.raft.JoinDeniedException;
import org.apache.ignite.internal.cluster.management.topology.LogicalTopologyImpl;
import org.apache.ignite.internal.cluster.management.topology.api.LogicalNode;
-import org.apache.ignite.internal.lang.IgniteInternalException;
import org.apache.ignite.internal.lang.NodeStoppingException;
import org.apache.ignite.internal.testframework.WorkDirectory;
import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
@@ -308,7 +308,10 @@
// Start a cluster and initialize it
startCluster(2, testInfo);
- String[] cmgNodes = { cluster.get(0).name() };
+ MockNode firstNode = cluster.get(0);
+ MockNode secondNode = cluster.get(1);
+
+ String[] cmgNodes = { firstNode.name() };
initCluster(cmgNodes, cmgNodes);
@@ -316,25 +319,26 @@
stopCluster();
// Remove all persistent state from the first node
- IgniteUtils.deleteIfExists(workDir.resolve("node0"));
+ IgniteUtils.deleteIfExists(firstNode.workDir());
// Start the nodes again
- for (MockNode node : cluster) {
- node.restart();
- }
+ firstNode.restart();
// Initialize the cluster again, but with a different name. It is expected that the second node will try to join the CMG
// and will be rejected.
- cluster.get(0).clusterManager().initCluster(
+ firstNode.clusterManager().initCluster(
Arrays.asList(cmgNodes),
Arrays.asList(cmgNodes),
"cluster2"
);
- assertThrowsWithCause(
- () -> cluster.get(1).clusterManager().joinFuture().get(10, TimeUnit.SECONDS),
- IgniteInternalException.class,
- "Join request denied, reason: Cluster tags do not match"
+ assertThat(firstNode.startFuture(), willCompleteSuccessfully());
+
+ secondNode.restart();
+
+ assertThat(
+ secondNode.startFuture(),
+ willThrow(JoinDeniedException.class, "Join request denied, reason: Cluster tags do not match")
);
}
diff --git a/modules/cluster-management/src/testFixtures/java/org/apache/ignite/internal/cluster/management/MockNode.java b/modules/cluster-management/src/testFixtures/java/org/apache/ignite/internal/cluster/management/MockNode.java
index 300cb12..1789cc9 100644
--- a/modules/cluster-management/src/testFixtures/java/org/apache/ignite/internal/cluster/management/MockNode.java
+++ b/modules/cluster-management/src/testFixtures/java/org/apache/ignite/internal/cluster/management/MockNode.java
@@ -222,6 +222,10 @@
return clusterService;
}
+ public Path workDir() {
+ return workDir;
+ }
+
CompletableFuture<Set<LogicalNode>> logicalTopologyNodes() {
return clusterManager().logicalTopology().thenApply(LogicalTopologySnapshot::nodes);
}