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

sanpwc 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 56029b95d1 IGNITE-22774 Remove `raftClient` map from `ItTxTestCluster` 
(#4194)
56029b95d1 is described below

commit 56029b95d179c05743a060bd87ab689a2635674b
Author: Mikhail Efremov <[email protected]>
AuthorDate: Mon Aug 12 23:31:39 2024 +0600

    IGNITE-22774 Remove `raftClient` map from `ItTxTestCluster` (#4194)
---
 .../ItTxDistributedTestSingleNodeCollocated.java   | 11 ---
 ...butedTestThreeNodesThreeReplicasCollocated.java |  6 --
 .../apache/ignite/distributed/ItTxTestCluster.java | 79 +++++++---------------
 3 files changed, 24 insertions(+), 72 deletions(-)

diff --git 
a/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestSingleNodeCollocated.java
 
b/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestSingleNodeCollocated.java
index a5bce88e25..8d6b0ac9e2 100644
--- 
a/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestSingleNodeCollocated.java
+++ 
b/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestSingleNodeCollocated.java
@@ -17,8 +17,6 @@
 
 package org.apache.ignite.distributed;
 
-import static org.junit.jupiter.api.Assertions.assertSame;
-
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.TestInfo;
 
@@ -46,15 +44,6 @@ public class ItTxDistributedTestSingleNodeCollocated extends 
ItTxAbstractDistrib
     @Override
     public void before() throws Exception {
         super.before();
-
-        assertSame(
-                
txTestCluster.raftClients.get(ACC_TABLE_NAME).get(0).clusterService(),
-                txTestCluster.getLeader(ACC_TABLE_NAME).service()
-        );
-        assertSame(
-                
txTestCluster.raftClients.get(CUST_TABLE_NAME).get(0).clusterService(),
-                txTestCluster.getLeader(CUST_TABLE_NAME).service()
-        );
     }
 }
 
diff --git 
a/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestThreeNodesThreeReplicasCollocated.java
 
b/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestThreeNodesThreeReplicasCollocated.java
index fba1fc61a0..b9093f55e0 100644
--- 
a/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestThreeNodesThreeReplicasCollocated.java
+++ 
b/modules/table/src/integrationTest/java/org/apache/ignite/distributed/ItTxDistributedTestThreeNodesThreeReplicasCollocated.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.distributed;
 
 import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
-import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.UUID;
@@ -50,11 +49,6 @@ public class 
ItTxDistributedTestThreeNodesThreeReplicasCollocated extends ItTxDi
     @BeforeEach
     @Override public void before() throws Exception {
         super.before();
-
-        assertSame(
-                
txTestCluster.raftClients.get(ACC_TABLE_NAME).get(0).clusterService(),
-                txTestCluster.getLeader(ACC_TABLE_NAME).service()
-        );
     }
 
     @Test
diff --git 
a/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java
 
b/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java
index 761fa5dc91..0c4e6d807e 100644
--- 
a/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java
+++ 
b/modules/table/src/testFixtures/java/org/apache/ignite/distributed/ItTxTestCluster.java
@@ -104,6 +104,7 @@ import 
org.apache.ignite.internal.raft.storage.impl.VolatileLogStorageFactoryCre
 import org.apache.ignite.internal.replicator.Replica;
 import org.apache.ignite.internal.replicator.ReplicaManager;
 import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
 import org.apache.ignite.internal.replicator.TablePartitionId;
 import 
org.apache.ignite.internal.replicator.configuration.ReplicationConfiguration;
 import org.apache.ignite.internal.replicator.listener.ReplicaListener;
@@ -231,8 +232,7 @@ public class ItTxTestCluster {
 
     protected TransactionStateResolver clientTxStateResolver;
 
-    // TODO: should be removed in 
https://issues.apache.org/jira/browse/IGNITE-22774
-    protected Map<String, List<RaftGroupService>> raftClients = new 
HashMap<>();
+    protected Map<String, TableImpl> tables = new HashMap<>();
 
     protected Map<String, TxStateStorage> txStateStorages;
 
@@ -613,6 +613,8 @@ public class ItTxTestCluster {
                 pkCatalogIndexDescriptor.id()
         );
 
+        tables.put(tableName, table);
+
         for (int p = 0; p < assignments.size(); p++) {
             Set<String> partAssignments = assignments.get(p);
 
@@ -718,42 +720,23 @@ public class ItTxTestCluster {
                         schemaManager
                 );
 
-                CompletableFuture<Void> partitionReadyFuture = 
replicaManagers.get(assignment)
-                        .startReplica(
-                                RaftGroupEventsListener.noopLsnr,
-                                partitionListener,
-                                false,
-                                null,
-                                createReplicaListener,
-                                storageIndexTracker,
-                                grpId,
-                                configuration
-                        )
-                        .thenAccept(unused -> { });
+                CompletableFuture<?> partitionReadyFuture = 
replicaManagers.get(assignment).startReplica(
+                        RaftGroupEventsListener.noopLsnr,
+                        partitionListener,
+                        false,
+                        null,
+                        createReplicaListener,
+                        storageIndexTracker,
+                        grpId,
+                        configuration
+                );
 
                 partitionReadyFutures.add(partitionReadyFuture);
             }
-
-            // waiting for started replicas otherwise we would have NPE on 
{@link Replica#replica} call below
-            allOf(partitionReadyFutures.toArray(new 
CompletableFuture[0])).join();
-
-            // TODO: should be removed in 
https://issues.apache.org/jira/browse/IGNITE-22774
-            CompletableFuture<RaftGroupService> txExecutionRaftClient =  
replicaManagers.get(extractConsistentId(cluster.get(0)))
-                        .replica(grpId)
-                        .thenApply(Replica::raftClient)
-                        .thenApply(RaftGroupService::leader)
-                        .thenApply(Peer::consistentId)
-                        .thenApply(replicaManagers::get)
-                        .thenCompose(rm -> rm.replica(grpId))
-                        .thenApply(Replica::raftClient);
-
-            
partitionReadyFutures.add(txExecutionRaftClient.thenAccept(leaderClient -> 
clients.put(grpId.partitionId(), leaderClient)));
         }
 
         allOf(partitionReadyFutures.toArray(new CompletableFuture[0])).join();
 
-        raftClients.computeIfAbsent(tableName, t -> new 
ArrayList<>()).addAll(clients.values());
-
         return table;
     }
 
@@ -846,28 +829,21 @@ public class ItTxTestCluster {
         };
     }
 
-    /**
-     * Returns a raft manager for a group.
-     * TODO: should be removed in 
https://issues.apache.org/jira/browse/IGNITE-22774
-     *
-     * @param tableName Table name.
-     * @return Raft manager hosting a leader for group.
-     */
-    protected Loza getLeader(String tableName) {
-        var services = raftClients.get(tableName);
-
-        Peer leader = services.get(0).leader();
+    private CompletableFuture<RaftGroupService> 
getRaftClientForGroup(ReplicationGroupId groupId) {
+        int partId = 0;
 
-        assertNotNull(leader);
-
-        return raftServers.get(leader.consistentId());
+        return replicaManagers.get(extractConsistentId(cluster.get(partId)))
+                .replica(groupId)
+                .thenApply(Replica::raftClient);
     }
 
     protected Peer getLeaderId(String tableName) {
-        // TODO: should be rewritten in 
https://issues.apache.org/jira/browse/IGNITE-22774
-        var services = raftClients.get(tableName);
+        int partId = 0;
 
-        return services.get(0).leader();
+        return replicaManagers.get(extractConsistentId(cluster.get(partId)))
+                .replica(new TablePartitionId(tables.get(tableName).tableId(), 
partId))
+                .thenApply(replica -> replica.raftClient().leader())
+                .join();
     }
 
     /**
@@ -939,13 +915,6 @@ public class ItTxTestCluster {
         if (clientTxManager != null) {
             assertThat(clientTxManager.stopAsync(new ComponentContext()), 
willCompleteSuccessfully());
         }
-
-        // TODO: should be removed in 
https://issues.apache.org/jira/browse/IGNITE-22774
-        for (Map.Entry<String, List<RaftGroupService>> e : 
raftClients.entrySet()) {
-            for (RaftGroupService svc : e.getValue()) {
-                svc.shutdown();
-            }
-        }
     }
 
     /**

Reply via email to