void runTestAppendEntriesTimeout(CLUSTER cluster) throws Exception { LOG.info("Running testAppendEntriesTimeout"); final TimeDuration oldExpiryTime = RaftServerConfigKeys.RetryCache.expiryTime(getProperties()); RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), TimeDuration.valueOf(20, TimeUnit.SECONDS)); waitForLeader(cluster);
throws IOException, InterruptedException, ExecutionException { LOG.info("Running testAppendEntriesTimeout"); final TimeDuration oldExpiryTime = RaftServerConfigKeys.RetryCache.expiryTime(getProperties()); RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), TimeDuration.valueOf(20, TimeUnit.SECONDS)); final CLUSTER cluster = newCluster(NUM_SERVERS);
public static void testRequestTimeout(boolean async, MiniRaftCluster cluster, Logger LOG) throws Exception { LOG.info("Running testRequestTimeout"); waitForLeader(cluster); long time = System.currentTimeMillis(); try (final RaftClient client = cluster.createClient()) { // Get the next callId to be used by the client long callId = RaftClientTestUtil.getCallId(client); // Create an entry corresponding to the callId and clientId // in each server's retry cache. cluster.getServerAliveStream().forEach( raftServer -> RetryCacheTestUtil.getOrCreateEntry(raftServer.getRetryCache(), client.getId(), callId)); // Client request for the callId now waits // as there is already a cache entry in the server for the request. // Ideally the client request should timeout and the client should retry. // The retry is successful when the retry cache entry for the corresponding callId and clientId expires. if (async) { CompletableFuture<RaftClientReply> replyFuture = client.sendAsync(new SimpleMessage("abc")); replyFuture.get(); } else { client.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. TimeDuration duration = TimeDuration.valueOf(System.currentTimeMillis() - time, TimeUnit.MILLISECONDS); TimeDuration retryCacheExpiryDuration = RaftServerConfigKeys.RetryCache.expiryTime(cluster.getProperties()); Assert.assertTrue(duration.compareTo(retryCacheExpiryDuration) >= 0); } }
public static void testRequestTimeout(boolean async, MiniRaftCluster cluster, Logger LOG) throws Exception { waitForLeader(cluster); long time = System.currentTimeMillis(); try (final RaftClient client = cluster.createClient()) { // Get the next callId to be used by the client long callId = RaftClientTestUtil.getCallId(client); // Create an entry corresponding to the callId and clientId // in each server's retry cache. cluster.getServerAliveStream().forEach( raftServer -> RetryCacheTestUtil.getOrCreateEntry(raftServer.getRetryCache(), client.getId(), callId)); // Client request for the callId now waits // as there is already a cache entry in the server for the request. // Ideally the client request should timeout and the client should retry. // The retry is successful when the retry cache entry for the corresponding callId and clientId expires. if (async) { CompletableFuture<RaftClientReply> replyFuture = client.sendAsync(new SimpleMessage("abc")); replyFuture.get(); } else { client.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. TimeDuration duration = TimeDuration.valueOf(System.currentTimeMillis() - time, TimeUnit.MILLISECONDS); TimeDuration retryCacheExpiryDuration = RaftServerConfigKeys.RetryCache.expiryTime(cluster.getProperties()); Assert.assertTrue(duration.compareTo(retryCacheExpiryDuration) >= 0); } } }
private RetryCache initRetryCache(RaftProperties prop) { final int capacity = RaftServerConfigKeys.RetryCache.capacity(prop); final TimeDuration expireTime = RaftServerConfigKeys.RetryCache.expiryTime(prop); return new RetryCache(capacity, expireTime); }
private RetryCache initRetryCache(RaftProperties prop) { final int capacity = RaftServerConfigKeys.RetryCache.capacity(prop); final TimeDuration expireTime = RaftServerConfigKeys.RetryCache.expiryTime(prop); return new RetryCache(capacity, expireTime); }
@Test public void testRequestTimeout() throws Exception { final TimeDuration oldExpiryTime = RaftServerConfigKeys.RetryCache.expiryTime(getProperties()); RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), TimeDuration.valueOf(5, TimeUnit.SECONDS)); runWithNewCluster(NUM_SERVERS, cluster -> RaftBasicTests.testRequestTimeout(true, cluster, LOG)); //reset for the other tests RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), oldExpiryTime); }
@Test public void testRequestTimeout() throws Exception { final TimeDuration oldExpiryTime = RaftServerConfigKeys.RetryCache.expiryTime(getProperties()); RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), TimeDuration.valueOf(5, TimeUnit.SECONDS)); final CLUSTER cluster = newCluster(NUM_SERVERS); cluster.start(); RaftBasicTests.testRequestTimeout(true, cluster, LOG); cluster.shutdown(); //reset for the other tests RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), oldExpiryTime); }