use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class RaftBasicTests method testRequestTimeout.
public static void testRequestTimeout(boolean async, MiniRaftCluster cluster, Logger LOG) throws Exception {
waitForLeader(cluster);
final Timestamp startTime = Timestamp.currentTime();
try (final RaftClient client = cluster.createClient()) {
// Get the next callId to be used by the client
final ClientInvocationId invocationId = RaftClientTestUtil.getClientInvocationId(client);
// Create an entry corresponding to the callId and clientId
// in each server's retry cache.
cluster.getServerAliveStream().forEach(raftServer -> RetryCacheTestUtil.getOrCreateEntry(raftServer, invocationId));
// The retry is successful when the retry cache entry for the corresponding callId and clientId expires.
if (async) {
CompletableFuture<RaftClientReply> replyFuture = client.async().send(new SimpleMessage("abc"));
replyFuture.get();
} else {
client.io().send(new SimpleMessage("abc"));
}
// Eventually the request would be accepted by the server
// when the retry cache entry is invalidated.
// The duration for which the client waits should be more than the retryCacheExpiryDuration.
final TimeDuration duration = startTime.elapsedTime();
TimeDuration retryCacheExpiryDuration = RaftServerConfigKeys.RetryCache.expiryTime(cluster.getProperties());
Assert.assertTrue(duration.compareTo(retryCacheExpiryDuration) >= 0);
}
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class TestRatisServerMetricsBase method runTestClientFailedRequest.
void runTestClientFailedRequest(CLUSTER cluster) throws InterruptedException, IOException, ExecutionException {
final RaftServer.Division leaderImpl = RaftTestUtil.waitForLeader(cluster);
ClientId clientId = ClientId.randomId();
// StaleRead with Long.MAX_VALUE minIndex will fail.
RaftClientRequest r = RaftClientRequest.newBuilder().setClientId(clientId).setLeaderId(leaderImpl.getId()).setGroupId(cluster.getGroupId()).setCallId(0).setMessage(Message.EMPTY).setType(RaftClientRequest.staleReadRequestType(Long.MAX_VALUE)).build();
final CompletableFuture<RaftClientReply> f = leaderImpl.getRaftServer().submitClientRequestAsync(r);
Assert.assertTrue(!f.get().isSuccess());
assertEquals(1L, ((RaftServerMetricsImpl) leaderImpl.getRaftServerMetrics()).getCounter(RATIS_SERVER_FAILED_CLIENT_STALE_READ_COUNT).getCount());
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class WatchRequestTests method checkAll.
static void checkAll(List<CompletableFuture<WatchReplies>> watches, Logger LOG) throws Exception {
for (int i = 0; i < watches.size(); i++) {
final WatchReplies watchReplies = watches.get(i).get(GET_TIMEOUT_SECOND, TimeUnit.SECONDS);
final long logIndex = watchReplies.logIndex;
LOG.info("checkAll {}: logIndex={}", i, logIndex);
final RaftClientReply watchAllReply = watchReplies.getAll();
Assert.assertTrue(watchAllReply.isSuccess());
final RaftClientReply watchAllCommittedReply = watchReplies.getAllCommitted();
Assert.assertTrue(watchAllCommittedReply.isSuccess());
{
// check commit infos
final Collection<CommitInfoProto> commitInfos = watchAllCommittedReply.getCommitInfos();
final String message = "logIndex=" + logIndex + ", " + ProtoUtils.toString(commitInfos);
Assert.assertEquals(NUM_SERVERS, commitInfos.size());
commitInfos.forEach(info -> Assert.assertTrue(message, logIndex <= info.getCommitIndex()));
}
}
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class WatchRequestTests method runTestWatchRequestClientTimeout.
static void runTestWatchRequestClientTimeout(TestParameters p) throws Exception {
final Logger LOG = p.log;
CompletableFuture<RaftClientReply> watchReply;
// 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.assertTrue(ex.getCause().getClass() == AlreadyClosedException.class || ex.getCause().getClass() == RaftRetryFailureException.class);
if (ex.getCause() != null) {
if (ex.getCause().getCause() != null) {
Assert.assertEquals(TimeoutIOException.class, ex.getCause().getCause().getClass());
}
}
}
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class WatchRequestTests method checkTimeout.
static void checkTimeout(List<CompletableFuture<RaftClientReply>> replies, List<CompletableFuture<WatchReplies>> watches, Logger LOG) throws Exception {
for (int i = 0; i < replies.size(); i++) {
final RaftClientReply reply = replies.get(i).get(GET_TIMEOUT_SECOND, TimeUnit.SECONDS);
LOG.info("checkTimeout {}: receive {}", i, reply);
final long logIndex = reply.getLogIndex();
Assert.assertTrue(reply.isSuccess());
final WatchReplies watchReplies = watches.get(i).get(GET_TIMEOUT_SECOND, TimeUnit.SECONDS);
Assert.assertEquals(logIndex, watchReplies.logIndex);
assertNotReplicatedException(logIndex, ReplicationLevel.ALL, watchReplies::getAll);
assertNotReplicatedException(logIndex, ReplicationLevel.ALL_COMMITTED, watchReplies::getAllCommitted);
}
}
Aggregations