You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sh...@apache.org on 2020/05/08 09:05:25 UTC

[incubator-ratis] branch master updated: RATIS-901. Fix Failed UT: WatchRequestTests.testWatchRequestClientTimeout (#83)

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

shashikant pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 8263087  RATIS-901. Fix Failed UT: WatchRequestTests.testWatchRequestClientTimeout (#83)
8263087 is described below

commit 8263087b57518bc29a020b544ab805db90b49c08
Author: runzhiwang <51...@users.noreply.github.com>
AuthorDate: Fri May 8 17:05:17 2020 +0800

    RATIS-901. Fix Failed UT: WatchRequestTests.testWatchRequestClientTimeout (#83)
---
 .../test/java/org/apache/ratis/WatchRequestTests.java  | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java b/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java
index 0f5d902..c9dd63f 100644
--- a/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java
+++ b/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java
@@ -23,11 +23,13 @@ import org.apache.ratis.client.RaftClientConfigKeys;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.proto.RaftProtos.CommitInfoProto;
 import org.apache.ratis.proto.RaftProtos.ReplicationLevel;
+import org.apache.ratis.protocol.AlreadyClosedException;
 import org.apache.ratis.protocol.NotReplicatedException;
 import org.apache.ratis.protocol.RaftClientReply;
 import org.apache.ratis.protocol.RaftRetryFailureException;
 import org.apache.ratis.protocol.TimeoutIOException;
 import org.apache.ratis.retry.RetryPolicies;
+import org.apache.ratis.retry.RetryPolicy;
 import org.apache.ratis.server.RaftServerConfigKeys;
 import org.apache.ratis.server.impl.RaftServerImpl;
 import org.apache.ratis.server.impl.RaftServerTestUtil;
@@ -113,13 +115,11 @@ public abstract class WatchRequestTests<CLUSTER extends MiniRaftCluster>
       }
     }
 
-    CompletableFuture<RaftClientReply> sendWatchRequest(long logIndex)
+    CompletableFuture<RaftClientReply> sendWatchRequest(long logIndex, RetryPolicy policy)
         throws Exception {
 
       try (final RaftClient watchClient =
-          cluster.createClient(RaftTestUtil.waitForLeader(cluster).getId(),
-          RetryPolicies.retryUpToMaximumCountWithFixedSleep(5,
-          TimeDuration.valueOf(5, TimeUnit.SECONDS)))) {
+          cluster.createClient(RaftTestUtil.waitForLeader(cluster).getId(), policy)) {
 
         CompletableFuture<RaftClientReply> reply =
             watchClient.sendAsync(new RaftTestUtil.SimpleMessage("message"));
@@ -446,15 +446,19 @@ public abstract class WatchRequestTests<CLUSTER extends MiniRaftCluster>
     final Logger LOG = p.log;
 
     CompletableFuture<RaftClientReply> watchReply;
-    watchReply = p.sendWatchRequest(1000);
+    // watch 1000 which will never be committed
+    // so client can not receive reply, and connection closed, throw TimeoutException.
+    // We should not retry, because if retry, RaftClientImpl::handleIOException will random select a leader,
+    // then sometimes throw NotLeaderException.
+    watchReply = p.sendWatchRequest(1000, RetryPolicies.noRetry());
 
     try {
       watchReply.get();
       fail("runTestWatchRequestClientTimeout failed");
     } catch (Exception ex) {
       LOG.error("error occurred", ex);
-      Assert.assertEquals(RaftRetryFailureException.class,
-          ex.getCause().getClass());
+      Assert.assertTrue(ex.getCause().getClass() == AlreadyClosedException.class ||
+          ex.getCause().getClass() == RaftRetryFailureException.class);
       if (ex.getCause() != null) {
         if (ex.getCause().getCause() != null) {
           Assert.assertEquals(TimeoutIOException.class,