Brokenice0415 commented on code in PR #943:
URL: https://github.com/apache/ratis/pull/943#discussion_r1367321136


##########
ratis-examples/src/test/java/org/apache/ratis/examples/TestMembership.java:
##########
@@ -66,6 +67,70 @@ public static void after() {
     executorService.shutdown();
   }
 
+  @Test
+  public void testShutdown() throws Exception {
+    RaftConfiguration.LatchMap.put(APPLY_OLD_NEW_CONF, new CountDownLatch(0));
+    RaftConfiguration.LatchMap.put(SHUTDOWN_NEW_PEER, new CountDownLatch(0));
+
+    RaftServer[] servers = new RaftServer[5];
+    RaftPeer[] peers = new RaftPeer[] {
+        RaftPeer.newBuilder()
+            .setId("node-0")
+            .setAddress(LOCAL_ADDR + ":21011")
+            .setPriority(0)
+            .build(),
+        RaftPeer.newBuilder()
+            .setId("node-1")
+            .setAddress(LOCAL_ADDR + ":21012")
+            .setPriority(0)
+            .build(),
+        RaftPeer.newBuilder()
+            .setId("node-2")
+            .setAddress(LOCAL_ADDR + ":21013")
+            .setPriority(0)
+            .build(),
+        RaftPeer.newBuilder()
+            .setId("node-3")
+            .setAddress(LOCAL_ADDR + ":21014")
+            .setPriority(0)
+            .build(),
+        RaftPeer.newBuilder()
+            .setId("node-4")
+            .setAddress(LOCAL_ADDR + ":21015")
+            .setPriority(0)
+            .build()
+    };
+
+    // 1. Start raft servers.
+    // Servers {node-0, node-1} form the initial raft cluster.
+    // Then node-2 is added.
+    servers[0] = startServer(RaftGroup.valueOf(GROUP_ID, peers[0], peers[1]), 
peers[0], RaftStorage.StartupOption.FORMAT);
+    servers[1] = startServer(RaftGroup.valueOf(GROUP_ID, peers[0], peers[1]), 
peers[1], RaftStorage.StartupOption.FORMAT);
+    servers[2] = startServer(RaftGroup.valueOf(GROUP_ID), peers[2], 
RaftStorage.StartupOption.FORMAT);
+    while (findLeader(servers) == -1) {
+      // Wait for leader.
+    }
+
+    // 2. Add 1 conf log entry and 10 normal log entries.
+    RaftClient client = createClient(peers[0], peers[1], peers[2]);
+    // Add a conf log entry. Then 
RaftServerImpl#getRaftConf().getLogEntryIndex() will be greater than 0.
+    // This is a condition in RaftServerImpl#shouldSendShutdown().
+    assertTrue(client.admin().setConfiguration(Arrays.copyOfRange(peers, 0, 
3)).isSuccess());
+    // Commit raft log, otherwise the conf log will be the latest log.
+    // This is a condition in RaftServerImpl#shouldSendShutdown().
+    for (int i = 0; i < 10; i++) {
+      client.io().send(Message.valueOf("abc"));
+    }
+
+    // 3. Start {node-3} with {C_old, peer}.
+    servers[3] = startServer(RaftGroup.valueOf(GROUP_ID, peers[0], peers[1], 
peers[2], peers[3]), peers[3], RaftStorage.StartupOption.FORMAT, false);

Review Comment:
   `client.admin().setConfiguration(Arrays.copyOfRange(peers, 0, 4))` is needed 
if making peer 3 in real C_new.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to