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

sk0x50 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 79edfa4  IGNITE-15019 Fixed flaky testFollowerStartStopFollowing test. 
Fixes #215
79edfa4 is described below

commit 79edfa4b56c788e6161a2a0ee35109d8ac1a71b2
Author: Mirza Aliev <alievmi...@gmail.com>
AuthorDate: Fri Jul 16 15:08:10 2021 +0300

    IGNITE-15019 Fixed flaky testFollowerStartStopFollowing test. Fixes #215
    
    Signed-off-by: Slava Koptilin <slava.kopti...@gmail.com>
---
 .../apache/ignite/raft/jraft/core/ITNodeTest.java  | 20 +++++++-----
 .../internal/raft/server/impl/JRaftServerImpl.java |  2 +-
 .../apache/ignite/raft/jraft/RaftGroupService.java | 37 ----------------------
 .../apache/ignite/raft/jraft/core/TestCluster.java |  2 ++
 .../ignite/raft/jraft/rpc/TestIgniteRpcServer.java | 17 ++++++++++
 5 files changed, 32 insertions(+), 46 deletions(-)

diff --git 
a/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
 
b/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
index 268c07a..dc5a525 100644
--- 
a/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
+++ 
b/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
@@ -2665,7 +2665,8 @@ public class ITNodeTest {
         List<Node> firstFollowers = cluster.getFollowers();
         assertEquals(4, firstFollowers.size());
         for (Node node : firstFollowers) {
-            assertTrue(waitForCondition(() -> ((MockStateMachine) 
node.getOptions().getFsm()).getOnStartFollowingTimes() == 1, 5_000));
+            assertTrue(
+                waitForCondition(() -> ((MockStateMachine) 
node.getOptions().getFsm()).getOnStartFollowingTimes() == 1, 5_000));
             assertEquals(0, ((MockStateMachine) 
node.getOptions().getFsm()).getOnStopFollowingTimes());
         }
 
@@ -2681,7 +2682,8 @@ public class ITNodeTest {
         List<Node> secondFollowers = cluster.getFollowers();
         assertEquals(3, secondFollowers.size());
         for (Node node : secondFollowers) {
-            assertEquals(2, ((MockStateMachine) 
node.getOptions().getFsm()).getOnStartFollowingTimes());
+            assertTrue(
+                waitForCondition(() -> ((MockStateMachine) 
node.getOptions().getFsm()).getOnStartFollowingTimes() == 2, 5_000));
             assertEquals(1, ((MockStateMachine) 
node.getOptions().getFsm()).getOnStopFollowingTimes());
         }
 
@@ -2697,15 +2699,17 @@ public class ITNodeTest {
         List<Node> thirdFollowers = cluster.getFollowers();
         assertEquals(3, thirdFollowers.size());
         for (int i = 0; i < 3; i++) {
-            if 
(thirdFollowers.get(i).getNodeId().getPeerId().equals(secondLeader.getNodeId().getPeerId()))
 {
-                assertEquals(2,
-                    ((MockStateMachine) 
thirdFollowers.get(i).getOptions().getFsm()).getOnStartFollowingTimes());
+            Node follower = thirdFollowers.get(i);
+            if 
(follower.getNodeId().getPeerId().equals(secondLeader.getNodeId().getPeerId())) 
{
+                assertTrue(
+                    waitForCondition(() -> ((MockStateMachine) 
follower.getOptions().getFsm()).getOnStartFollowingTimes() == 2, 5_000));
                 assertEquals(1,
-                    ((MockStateMachine) 
thirdFollowers.get(i).getOptions().getFsm()).getOnStopFollowingTimes());
+                    ((MockStateMachine) 
follower.getOptions().getFsm()).getOnStopFollowingTimes());
                 continue;
             }
-            assertEquals(3, ((MockStateMachine) 
thirdFollowers.get(i).getOptions().getFsm()).getOnStartFollowingTimes());
-            assertEquals(2, ((MockStateMachine) 
thirdFollowers.get(i).getOptions().getFsm()).getOnStopFollowingTimes());
+
+            assertTrue(waitForCondition(() -> ((MockStateMachine) 
follower.getOptions().getFsm()).getOnStartFollowingTimes() == 3, 5_000));
+            assertEquals(2, ((MockStateMachine) 
follower.getOptions().getFsm()).getOnStopFollowingTimes());
         }
 
         cluster.ensureSame();
diff --git 
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JRaftServerImpl.java
 
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JRaftServerImpl.java
index 8b77e79..042f727 100644
--- 
a/modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JRaftServerImpl.java
+++ 
b/modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JRaftServerImpl.java
@@ -170,7 +170,7 @@ public class JRaftServerImpl implements RaftServer {
 
         var peerId = new PeerId(addr.host(), addr.port(), 0, 
ElectionPriority.DISABLED);
 
-        var server = new RaftGroupService(groupId, peerId, nodeOptions, 
rpcServer, nodeManager, true);
+        var server = new RaftGroupService(groupId, peerId, nodeOptions, 
rpcServer, nodeManager);
 
         server.start();
 
diff --git 
a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/RaftGroupService.java 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/RaftGroupService.java
index e3c06de..e538035 100644
--- 
a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/RaftGroupService.java
+++ 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/RaftGroupService.java
@@ -52,11 +52,6 @@ public class RaftGroupService {
     private RpcServer rpcServer;
 
     /**
-     * If we want to share the rpcServer instance, then we can't stop it when 
shutdown.
-     */
-    private final boolean sharedRpcServer;
-
-    /**
      * The raft group id
      */
     private String groupId;
@@ -80,26 +75,12 @@ public class RaftGroupService {
      */
     public RaftGroupService(final String groupId, final PeerId serverId, final 
NodeOptions nodeOptions,
         final RpcServer rpcServer, final NodeManager nodeManager) {
-        this(groupId, serverId, nodeOptions, rpcServer, nodeManager, false);
-    }
-
-    /**
-     * @param groupId Group Id.
-     * @param serverId Server id.
-     * @param nodeOptions Node options.
-     * @param rpcServer RPC server.
-     * @param nodeManager Node manager.
-     * @param sharedRpcServer {@code True} if a shared server.
-     */
-    public RaftGroupService(final String groupId, final PeerId serverId, final 
NodeOptions nodeOptions,
-        final RpcServer rpcServer, final NodeManager nodeManager, final 
boolean sharedRpcServer) {
         super();
         this.groupId = groupId;
         this.serverId = serverId;
         this.nodeOptions = nodeOptions;
         this.rpcServer = rpcServer;
         this.nodeManager = nodeManager;
-        this.sharedRpcServer = sharedRpcServer;
     }
 
     public synchronized Node getRaftNode() {
@@ -123,14 +104,6 @@ public class RaftGroupService {
 
         assert this.nodeOptions.getRpcClient() != null;
 
-        // Should start RPC server before node initialization to avoid race.
-        if (!sharedRpcServer) {
-            this.rpcServer.init(null);
-        }
-        else {
-            LOG.info("RPC server is shared by RaftGroupService.");
-        }
-
         this.node = new NodeImpl(groupId, serverId);
 
         if (!this.node.init(this.nodeOptions)) {
@@ -155,16 +128,6 @@ public class RaftGroupService {
 
     public synchronized void shutdown() {
         // TODO asch remove handlers before shutting down raft node 
https://issues.apache.org/jira/browse/IGNITE-14519
-        if (this.rpcServer != null && !this.sharedRpcServer) {
-            try {
-                this.rpcServer.shutdown();
-            }
-            catch (Exception e) {
-                LOG.error("Failed to shutdown the server", e);
-            }
-            this.rpcServer = null;
-        }
-
         if (!this.started) {
             return;
         }
diff --git 
a/modules/raft/src/test/java/org/apache/ignite/raft/jraft/core/TestCluster.java 
b/modules/raft/src/test/java/org/apache/ignite/raft/jraft/core/TestCluster.java
index fe2954c..90d25c0 100644
--- 
a/modules/raft/src/test/java/org/apache/ignite/raft/jraft/core/TestCluster.java
+++ 
b/modules/raft/src/test/java/org/apache/ignite/raft/jraft/core/TestCluster.java
@@ -236,6 +236,8 @@ public class TestCluster {
                 @Override public synchronized void shutdown() {
                     super.shutdown();
 
+                    rpcServer.shutdown();
+
                     clusterService.shutdown();
                 }
             };
diff --git 
a/modules/raft/src/test/java/org/apache/ignite/raft/jraft/rpc/TestIgniteRpcServer.java
 
b/modules/raft/src/test/java/org/apache/ignite/raft/jraft/rpc/TestIgniteRpcServer.java
index 406df62..4e9c117 100644
--- 
a/modules/raft/src/test/java/org/apache/ignite/raft/jraft/rpc/TestIgniteRpcServer.java
+++ 
b/modules/raft/src/test/java/org/apache/ignite/raft/jraft/rpc/TestIgniteRpcServer.java
@@ -30,6 +30,8 @@ import org.apache.ignite.raft.jraft.rpc.impl.IgniteRpcServer;
  * RPC server configured for integration tests.
  */
 public class TestIgniteRpcServer extends IgniteRpcServer {
+    private final NodeOptions nodeOptions;
+
     /**
      * @param clusterService Cluster service.
      * @param servers Server list.
@@ -48,5 +50,20 @@ public class TestIgniteRpcServer extends IgniteRpcServer {
             new RaftClientMessagesFactory(),
             JRaftUtils.createRequestExecutor(nodeOptions)
         );
+
+        this.nodeOptions = nodeOptions;
+    }
+
+    @Override public void shutdown() {
+        super.shutdown();
+
+        if (this.nodeOptions.getClientExecutor() != null)
+            this.nodeOptions.getClientExecutor().shutdown();
+
+        if (this.nodeOptions.getStripedExecutor() != null)
+            this.nodeOptions.getStripedExecutor().shutdownGracefully();
+
+        if (this.nodeOptions.getCommonExecutor() != null)
+            this.nodeOptions.getCommonExecutor().shutdown();
     }
 }

Reply via email to