This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 05db67929 RATIS-1980. Intermittent failure in
TestRetryCacheWithGrpc#testInvalidateRepliedCalls (#995)
05db67929 is described below
commit 05db67929a5b06ce964eda6627d44cd153cc2bce
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Sun Dec 17 17:47:13 2023 +0100
RATIS-1980. Intermittent failure in
TestRetryCacheWithGrpc#testInvalidateRepliedCalls (#995)
---
.../apache/ratis/grpc/TestRetryCacheWithGrpc.java | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java
b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java
index 8a1878cd8..a39a4d1ef 100644
--- a/ratis-test/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java
+++ b/ratis-test/src/test/java/org/apache/ratis/grpc/TestRetryCacheWithGrpc.java
@@ -34,7 +34,9 @@ import org.apache.ratis.server.RaftServerConfigKeys;
import org.apache.ratis.server.impl.RetryCacheTestUtil;
import org.apache.ratis.statemachine.impl.SimpleStateMachine4Testing;
import org.apache.ratis.statemachine.StateMachine;
+import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.Slf4jUtils;
+import org.apache.ratis.util.TimeDuration;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.event.Level;
@@ -45,6 +47,8 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
public class TestRetryCacheWithGrpc
extends RetryCacheTests<MiniRaftClusterWithGrpc>
@@ -80,12 +84,18 @@ public class TestRetryCacheWithGrpc
return new SimpleMessage("m" + count.incrementAndGet());
}
- void assertRetryCacheEntry(RaftClient client, long callId, boolean exist) {
- final RetryCache.Entry e = RetryCacheTestUtil.get(leader,
client.getId(), callId);
- if (exist) {
- Assert.assertNotNull(e);
+ void assertRetryCacheEntry(RaftClient client, long callId, boolean exist)
throws InterruptedException {
+ assertRetryCacheEntry(client, callId, exist, false);
+ }
+
+ void assertRetryCacheEntry(RaftClient client, long callId, boolean exist,
boolean eventually) throws InterruptedException {
+ Supplier<RetryCache.Entry> lookup = () -> RetryCacheTestUtil.get(leader,
client.getId(), callId);
+ Consumer<RetryCache.Entry> assertion = exist ? Assert::assertNotNull :
Assert::assertNull;
+ if (eventually) {
+ JavaUtils.attempt(() -> assertion.accept(lookup.get()), 100,
TimeDuration.ONE_MILLISECOND,
+ "retry cache entry", null);
} else {
- Assert.assertNull(e);
+ assertion.accept(lookup.get());
}
}
@@ -129,7 +139,7 @@ public class TestRetryCacheWithGrpc
asyncCalls.add(sendAsync(client));
}
// async call will invalidate blocking calls even if applyTransaction
is blocked.
- assertRetryCacheEntry(client, lastBlockingCallId, false);
+ assertRetryCacheEntry(client, lastBlockingCallId, false, true);
ONE_SECOND.sleep();
// No calls can be completed.