szetszwo commented on a change in pull request #310:
URL: https://github.com/apache/incubator-ratis/pull/310#discussion_r534062126



##########
File path: 
ratis-test/src/test/java/org/apache/ratis/datastream/DataStreamAsyncClusterTests.java
##########
@@ -69,12 +69,29 @@ public void testMultipleStreamsMultipleServers() throws 
Exception {
     RaftServerConfigKeys.Rpc.setTimeoutMax(getProperties(), max);
   }
 
+  @Test
+  public void testSingleStreamMultipleServersStepDownLeader() throws Exception 
{
+    runWithNewCluster(3, this::runTestDataStreamStepDownLeader);
+  }
+
+  void runTestDataStreamStepDownLeader(CLUSTER cluster) throws Exception {
+    runTestDataStream(cluster, true);
+  }
+
   void runTestDataStream(CLUSTER cluster) throws Exception {
+    runTestDataStream(cluster, false);
+  }
+
+  void runTestDataStream(CLUSTER cluster, boolean stepDownLeader) throws 
Exception {
     RaftTestUtil.waitForLeader(cluster);
 
     final List<CompletableFuture<Long>> futures = new ArrayList<>();
-    futures.add(CompletableFuture.supplyAsync(() -> runTestDataStream(cluster, 
5, 10, 1_000_000, 10), executor));
-    futures.add(CompletableFuture.supplyAsync(() -> runTestDataStream(cluster, 
2, 20, 1_000, 10_000), executor));
+    if (stepDownLeader) {
+      futures.add(CompletableFuture.supplyAsync(() -> 
runTestDataStream(cluster, 1, 1, 1_000_000, 10, stepDownLeader), executor));

Review comment:
       We may change leader after the first future has completed.
   ```
   +++ 
b/ratis-test/src/test/java/org/apache/ratis/datastream/DataStreamAsyncClusterTests.java
   @@ -86,17 +86,25 @@ public abstract class 
DataStreamAsyncClusterTests<CLUSTER extends MiniRaftCluste
        RaftTestUtil.waitForLeader(cluster);
    
        final List<CompletableFuture<Long>> futures = new ArrayList<>();
   -    if (stepDownLeader) {
   -      futures.add(CompletableFuture.supplyAsync(() -> 
runTestDataStream(cluster, 1, 1, 1_000_000, 10, stepDownLeader), executor));
   -    } else {
   -      futures.add(CompletableFuture.supplyAsync(() -> 
runTestDataStream(cluster, 5, 10, 1_000_000, 10, stepDownLeader), executor));
   -      futures.add(CompletableFuture.supplyAsync(() -> 
runTestDataStream(cluster, 2, 20, 1_000, 10_000, stepDownLeader), executor));
   -    }
   +    futures.add(CompletableFuture.supplyAsync(() -> 
runTestDataStream(cluster, 5, 10, 1_000_000, 10, false), executor));
   +    futures.add(CompletableFuture.supplyAsync(() -> 
runTestDataStream(cluster, 2, 20, 1_000, 10_000, false), executor));
        final long maxIndex = futures.stream()
            .map(CompletableFuture::join)
            .max(Long::compareTo)
            .orElseThrow(IllegalStateException::new);
    
   +    if (stepDownLeader) {
   +      final RaftPeerId oldLeader = cluster.getLeader().getId();
   +      final CompletableFuture<RaftPeerId> changeLeader = 
futures.get(0).thenApplyAsync(dummy -> {
   +        try {
   +          return RaftTestUtil.changeLeader(cluster, oldLeader);
   +        } catch (Exception e) {
   +          throw new CompletionException("Failed to change leader from " + 
oldLeader, e);
   +        }
   +      });
   +      LOG.info("Changed leader from {} to {}", oldLeader, 
changeLeader.join());
   +    }
   +
   ```
   




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to