amaliujia commented on code in PR #1695:
URL: https://github.com/apache/ratis/pull/1695#discussion_r4601562247


##########
ratis-server/src/test/java/org/apache/ratis/server/impl/LeaderElectionTests.java:
##########
@@ -281,6 +291,102 @@ public void testTransferLeader() throws Exception {
     }
   }
 
+  @Test
+  public void testRetryCacheCompletesAfterLeaderTransfer() throws Exception {

Review Comment:
   I tried to read this test and failed to understand what does it do :)  For a 
simple fix, this test seems to be too long.
   
   So I asked AI and AI gives a short version of test:
   
   In `RetryCacheTestUtil.java`, we can add
   ```Java
   
     public static RetryCache.Entry createFailedEntry(RaftServer.Division 
server, ClientId clientId, long callId) {
       final RetryCacheImpl.CacheEntry entry = ((RetryCacheImpl) 
server.getRetryCache())
           .getOrCreateEntry(ClientInvocationId.valueOf(clientId, callId));
       entry.failWithException(new IllegalStateException("Injected failure"));
       return entry;
     }
   ```
   
   In `RetryCacheTests.java`, we can have
   ```Java
     @Test
     public void testApplyCompletesReplacementOfFailedEntry() throws Exception {
       runWithNewCluster(NUM_SERVERS, 
this::runTestApplyCompletesReplacementOfFailedEntry);
     }
   
     void runTestApplyCompletesReplacementOfFailedEntry(CLUSTER cluster) throws 
Exception {
       final RaftPeerId leaderId = RaftTestUtil.waitForLeader(cluster).getId();
       final RaftServer.Division follower = cluster.getFollowers().get(0);
   
       try (final RaftClient client = cluster.createClient(leaderId)) {
         final long callId = 999;
         final RetryCache.Entry failed = 
RetryCacheTestUtil.createFailedEntry(follower, client.getId(), callId);
   
         final RaftClientRequest r = 
cluster.newRaftClientRequest(client.getId(), leaderId,
             callId, new SimpleMessage("message"));
         assertReply(client.getClientRpc().sendRequest(r), client, callId);
   
         JavaUtils.attempt(() -> {
           final RetryCache.Entry entry = RetryCacheTestUtil.get(follower, 
client.getId(), callId);
           Assertions.assertNotSame(failed, entry);
           final RaftClientReply reply = entry.getReplyFuture().getNow(null);
           Assertions.assertNotNull(reply, "The replacement entry is not 
completed");
           Assertions.assertTrue(reply.isSuccess(), reply::toString);
         }, 50, TimeDuration.valueOf(100, TimeUnit.MILLISECONDS), "wait for the 
follower to apply", LOG);
       }
     }
   ```



##########
ratis-server/src/test/java/org/apache/ratis/server/impl/LeaderElectionTests.java:
##########
@@ -281,6 +291,102 @@ public void testTransferLeader() throws Exception {
     }
   }
 
+  @Test
+  public void testRetryCacheCompletesAfterLeaderTransfer() throws Exception {
+    try (final MiniRaftCluster cluster = newCluster(3)) {
+      cluster.start();
+      waitForLeader(cluster);
+      // Give peer connections time to recover from connection failures during 
startup.
+      TimeDuration.valueOf(3, TimeUnit.SECONDS).sleep();

Review Comment:
   Do we really need for this 3 second wait? What kind of connection failures 
it could happen during/after leader election?



-- 
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