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

rpuch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new b361c7ef0c IGNITE-23364 Build REST URL without using node metadata in 
tests (#4505)
b361c7ef0c is described below

commit b361c7ef0c832b3beec2fb1031ea276df639e6d7
Author: Roman Puchkovskiy <[email protected]>
AuthorDate: Fri Oct 4 20:02:44 2024 +0400

    IGNITE-23364 Build REST URL without using node metadata in tests (#4505)
---
 .../java/org/apache/ignite/internal/Cluster.java   |  9 ++++++-
 .../disaster/system/ItCmgDisasterRecoveryTest.java | 30 +++++++++------------
 .../system/ItSystemGroupDisasterRecoveryTest.java  | 31 +++++-----------------
 3 files changed, 28 insertions(+), 42 deletions(-)

diff --git 
a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java 
b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
index 6a1ce42678..0b2b5c68ef 100644
--- 
a/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
+++ 
b/modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java
@@ -269,7 +269,7 @@ public class Cluster {
                 BASE_PORT + nodeIndex,
                 seedAddressesString(),
                 BASE_CLIENT_PORT + nodeIndex,
-                BASE_HTTP_PORT + nodeIndex,
+                httpPort(nodeIndex),
                 BASE_HTTPS_PORT + nodeIndex
         );
 
@@ -300,6 +300,13 @@ public class Cluster {
         return testNodeName(testInfo, nodeIndex);
     }
 
+    /**
+     * Returns HTTP port by index.
+     */
+    public int httpPort(int nodeIndex) {
+        return BASE_HTTP_PORT + nodeIndex;
+    }
+
     private static <T> void setListAtIndex(List<T> list, int i, T element) {
         while (list.size() < i) {
             list.add(null);
diff --git 
a/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItCmgDisasterRecoveryTest.java
 
b/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItCmgDisasterRecoveryTest.java
index a96711ce5e..3365bf12e3 100644
--- 
a/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItCmgDisasterRecoveryTest.java
+++ 
b/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItCmgDisasterRecoveryTest.java
@@ -30,7 +30,6 @@ import static org.hamcrest.Matchers.not;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
@@ -41,7 +40,6 @@ import org.apache.ignite.internal.app.IgniteImpl;
 import org.apache.ignite.internal.app.IgniteServerImpl;
 import org.apache.ignite.internal.cluster.management.ClusterState;
 import 
org.apache.ignite.internal.cluster.management.topology.api.LogicalTopologySnapshot;
-import org.apache.ignite.network.NodeMetadata;
 import org.apache.ignite.table.KeyValueView;
 import org.junit.jupiter.api.Test;
 
@@ -61,7 +59,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
 
         assertThatCmgHasNoMajority(igniteImpl1BeforeRestart);
 
-        initiateCmgRepairVia(igniteImpl1BeforeRestart, 1);
+        initiateCmgRepairVia(1, 1);
 
         IgniteImpl restartedIgniteImpl1 = waitTillNodeRestartsInternally(1);
         waitTillCmgHasMajority(restartedIgniteImpl1);
@@ -82,10 +80,8 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
         assertThat(ignite.logicalTopologyService().logicalTopologyOnLeader(), 
willCompleteSuccessfully());
     }
 
-    private void initiateCmgRepairVia(IgniteImpl conductor, int... 
newCmgIndexes) throws InterruptedException {
-        NodeMetadata nodeMetadata = obtainNodeMetadata(conductor);
-
-        recoveryClient.initiateCmgRepair(nodeMetadata.restHost(), 
nodeMetadata.httpPort(), nodeNames(newCmgIndexes));
+    private void initiateCmgRepairVia(int condictorIndex, int... 
newCmgIndexes) throws InterruptedException {
+        recoveryClient.initiateCmgRepair("localhost", 
cluster.httpPort(condictorIndex), nodeNames(newCmgIndexes));
     }
 
     @Test
@@ -101,7 +97,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
 
         assertThatCmgHasNoMajority(igniteImpl2BeforeRestart);
 
-        initiateCmgRepairVia(igniteImpl2BeforeRestart, 2, 3, 4);
+        initiateCmgRepairVia(2, 2, 3, 4);
 
         IgniteImpl restartedIgniteImpl2 = waitTillNodeRestartsInternally(2);
         waitTillCmgHasMajority(restartedIgniteImpl2);
@@ -116,7 +112,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
 
         cluster.stopNode(0);
 
-        initiateCmgRepairVia(igniteImpl(1), 1);
+        initiateCmgRepairVia(1, 1);
 
         // Doing this wait to make sure that blank node will be able to 
connect at least someone. If we don't do this, the new node
         // will still be able to connect, but this will happen on Scalecube's 
initial sync retry, and we don't want to wait for it
@@ -142,7 +138,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
 
         IntStream.of(1, 2).parallel().forEach(this::restartPartially);
 
-        initiateCmgRepairVia(((IgniteServerImpl) 
cluster.server(1)).igniteImpl(), 1);
+        initiateCmgRepairVia(1, 1);
 
         IgniteImpl restartedIgniteImpl1 = waitTillNodeRestartsInternally(1);
         waitTillCmgHasMajority(restartedIgniteImpl1);
@@ -156,7 +152,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
         // This makes the CMG majority go away.
         cluster.stopNode(0);
 
-        initiateCmgRepairVia(igniteImpl(1), 1);
+        initiateCmgRepairVia(1, 1);
 
         IgniteImpl restartedIgniteImpl1 = waitTillNodeRestartsInternally(1);
         waitTillCmgHasMajority(restartedIgniteImpl1);
@@ -194,16 +190,16 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
         IntStream.of(0, 1).parallel().forEach(cluster::stopNode);
 
         // Repair CMG with nodes 2, 3, 4.
-        initiateCmgRepairVia(igniteImpl(2), 2, 3, 4);
+        initiateCmgRepairVia(2, 2, 3, 4);
         IgniteImpl restartedIgniteImpl2 = waitTillNodeRestartsInternally(2);
         waitTillCmgHasMajority(restartedIgniteImpl2);
 
         // Starting the nodes that did not see the repair (in parallel, to 
save time).
-        List<IgniteImpl> partialNodes = IntStream.of(0, 1).parallel()
+        IntStream.of(0, 1).parallel()
                 .mapToObj(index -> ((IgniteServerImpl) 
cluster.startEmbeddedNode(index).server()).igniteImpl())
                 .collect(toList());
 
-        initiateMigrationToNewCluster(partialNodes.get(0), igniteImpl(2));
+        initiateMigrationToNewCluster(0, 2);
 
         waitTillNodeRestartsInternally(0);
         waitTillNodeRestartsInternally(1);
@@ -221,7 +217,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
         breakAndRepairCmgMajorityInTwoNodeCluster();
 
         // Second repair.
-        initiateCmgRepairVia(igniteImpl(1), 1);
+        initiateCmgRepairVia(1, 1);
         IgniteImpl igniteImpl1RestartedSecondTime = 
waitTillNodeRestartsInternally(1);
         waitTillCmgHasMajority(igniteImpl1RestartedSecondTime);
     }
@@ -264,7 +260,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
         cluster.stopNode(0);
 
         // Repair CMG with just node 1.
-        initiateCmgRepairVia(igniteImpl(1), 1);
+        initiateCmgRepairVia(1, 1);
         IgniteImpl restartedIgniteImpl1 = waitTillNodeRestartsInternally(1);
         waitTillCmgHasMajority(restartedIgniteImpl1);
 
@@ -305,7 +301,7 @@ class ItCmgDisasterRecoveryTest extends 
ItSystemGroupDisasterRecoveryTest {
         // Now, dataNodes should have become [1, 2], but as there is no CMG 
leader, no one is able to trigger data nodes update.
 
         // Repair CMG with just node 1.
-        initiateCmgRepairVia(igniteImpl(1), 1);
+        initiateCmgRepairVia(1, 1);
         IgniteImpl restartedIgniteImpl1 = waitTillNodeRestartsInternally(1);
         waitTillCmgHasMajority(restartedIgniteImpl1);
 
diff --git 
a/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItSystemGroupDisasterRecoveryTest.java
 
b/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItSystemGroupDisasterRecoveryTest.java
index 0739d76592..5dfc5097c0 100644
--- 
a/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItSystemGroupDisasterRecoveryTest.java
+++ 
b/modules/system-disaster-recovery/src/integrationTest/java/org/apache/ignite/internal/disaster/system/ItSystemGroupDisasterRecoveryTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.disaster.system;
 
-import static java.util.Objects.requireNonNull;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
 import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
@@ -35,8 +34,6 @@ import 
org.apache.ignite.internal.ClusterPerTestIntegrationTest;
 import org.apache.ignite.internal.app.IgniteImpl;
 import org.apache.ignite.internal.app.IgniteServerImpl;
 import org.apache.ignite.internal.cluster.management.ClusterState;
-import org.apache.ignite.network.ClusterNode;
-import org.apache.ignite.network.NodeMetadata;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -112,33 +109,19 @@ abstract class ItSystemGroupDisasterRecoveryTest extends 
ClusterPerTestIntegrati
 
     final void migrate(int oldClusterNodeIndex, int newClusterNodeIndex) 
throws Exception {
         // Starting the node that did not see the repair.
-        IgniteImpl nodeMissingRepair = ((IgniteServerImpl) 
cluster.startEmbeddedNode(oldClusterNodeIndex).server()).igniteImpl();
+        cluster.startEmbeddedNode(oldClusterNodeIndex);
 
-        initiateMigrationToNewCluster(nodeMissingRepair, 
igniteImpl(newClusterNodeIndex));
+        initiateMigrationToNewCluster(oldClusterNodeIndex, 
newClusterNodeIndex);
 
         waitTillNodeRestartsInternally(oldClusterNodeIndex);
     }
 
-    void initiateMigrationToNewCluster(IgniteImpl nodeMissingRepair, 
IgniteImpl repairedNode) throws Exception {
-        NodeMetadata missingRepairMetadata = 
obtainNodeMetadata(nodeMissingRepair);
-        NodeMetadata repairedMetadata = obtainNodeMetadata(repairedNode);
-
+    void initiateMigrationToNewCluster(int nodeMissingRepairIndex, int 
repairedNodeIndex) throws Exception {
         recoveryClient.initiateMigration(
-                missingRepairMetadata.restHost(),
-                missingRepairMetadata.httpPort(),
-                repairedMetadata.restHost(),
-                repairedMetadata.httpPort()
+                "localhost",
+                cluster.httpPort(nodeMissingRepairIndex),
+                "localhost",
+                cluster.httpPort(repairedNodeIndex)
         );
     }
-
-    static NodeMetadata obtainNodeMetadata(IgniteImpl ignite) throws 
InterruptedException {
-        ClusterNode clusterNode = ignite.node();
-
-        assertTrue(
-                waitForCondition(() -> clusterNode.nodeMetadata() != null, 
SECONDS.toMillis(10)),
-                "Did not see " + ignite.name() + " to get metadata in time"
-        );
-
-        return requireNonNull(clusterNode.nodeMetadata());
-    }
 }

Reply via email to