szetszwo commented on code in PR #1269:
URL: https://github.com/apache/ratis/pull/1269#discussion_r2103679708


##########
ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java:
##########
@@ -479,7 +479,7 @@ static List<RaftPeer> getPeersWithPriority(List<RaftPeer> 
peers, RaftPeer sugges
 
   static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader)
       throws Exception {
-    return changeLeader(cluster, oldLeader, AssumptionViolatedException::new);

Review Comment:
   Let's use 
[Assumptions.abort(..)](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/Assumptions.html#abort(java.lang.String))
 since it is a public API.
   
   ```java
   diff --git a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java 
b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
   index c9db9933b2..d0641e39c4 100644
   --- a/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
   +++ b/ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java
   @@ -44,7 +44,8 @@ import org.apache.ratis.util.JavaUtils;
    import org.apache.ratis.util.Preconditions;
    import org.apache.ratis.util.ProtoUtils;
    import org.apache.ratis.util.TimeDuration;
   -import org.opentest4j.TestAbortedException;
   +import org.apache.ratis.util.function.CheckedConsumer;
   +import org.junit.jupiter.api.Assumptions;
    import org.junit.jupiter.api.Assertions;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
   @@ -479,18 +480,18 @@ public interface RaftTestUtil {
    
      static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId 
oldLeader)
          throws Exception {
   -    return changeLeader(cluster, oldLeader, TestAbortedException::new);
   +    return changeLeader(cluster, oldLeader, Assumptions::abort);
      }
    
   -  static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId 
oldLeader, Function<String, Exception> constructor)
   -      throws Exception {
   +  static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId 
oldLeader,
   +      CheckedConsumer<String, Exception> failToChangeLeaderHandler) throws 
Exception {
        final String name = 
JavaUtils.getCallerStackTraceElement().getMethodName() + "-changeLeader";
        cluster.setBlockRequestsFrom(oldLeader.toString(), true);
        try {
          return JavaUtils.attemptRepeatedly(() -> {
            final RaftPeerId newLeader = waitForLeader(cluster).getId();
            if (newLeader.equals(oldLeader)) {
   -          throw constructor.apply("Failed to change leader: newLeader == 
oldLeader == " + oldLeader);
   +          failToChangeLeaderHandler.accept("Failed to change leader: 
newLeader == oldLeader == " + oldLeader);
            }
            LOG.info("Changed leader from " + oldLeader + " to " + newLeader);
            return newLeader;
   diff --git 
a/ratis-server/src/test/java/org/apache/ratis/server/impl/LeaderElectionTests.java
 
b/ratis-server/src/test/java/org/apache/ratis/server/impl/LeaderElectionTests.java
   index f35626894f..25caa9d06e 100644
   --- 
a/ratis-server/src/test/java/org/apache/ratis/server/impl/LeaderElectionTests.java
   +++ 
b/ratis-server/src/test/java/org/apache/ratis/server/impl/LeaderElectionTests.java
   @@ -184,7 +184,7 @@ public abstract class LeaderElectionTests<CLUSTER 
extends MiniRaftCluster>
      void runTestChangeLeader(MiniRaftCluster cluster) throws Exception {
        RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId();
        for(int i = 0; i < 10; i++) {
   -      leader = RaftTestUtil.changeLeader(cluster, leader, 
IllegalStateException::new);
   +      leader = RaftTestUtil.changeLeader(cluster, leader, Assertions::fail);
        }
      }
    
   ```



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

To unsubscribe, e-mail: [email protected]

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

Reply via email to