-
Notifications
You must be signed in to change notification settings - Fork 440
RATIS-1977. Remove Junit 4 dependencies. #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5ec6bcc
c8b6f2c
77e8c0b
8749e5f
c00a0aa
4801472
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,8 @@ | |
| import org.apache.ratis.util.Preconditions; | ||
| import org.apache.ratis.util.ProtoUtils; | ||
| import org.apache.ratis.util.TimeDuration; | ||
| import org.junit.AssumptionViolatedException; | ||
| 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 @@ static List<RaftPeer> getPeersWithPriority(List<RaftPeer> peers, RaftPeer sugges | |
|
|
||
| static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader) | ||
| throws Exception { | ||
| return changeLeader(cluster, oldLeader, AssumptionViolatedException::new); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part needs some clarification: we've replaced
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use Assumptions.abort(..) since it is a public API. 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);
}
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @szetszwo Thanks for the review! I’ve made the updates as suggested. |
||
| 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also remove the other two junit 4 comments:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing out these issues! I have made the changes as suggested.