diff --git a/pom.xml b/pom.xml
index af14e426f2..e79e3ed5ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -221,8 +221,10 @@
4
2.0.7
- 5.11.2
+ 5.12.2
+ 4.11.0
0.8.12
+ 1.3.5
flaky | org.apache.ratis.test.tag.FlakyTest
@@ -417,12 +419,6 @@
test
${slf4j.version}
-
-
- junit
- junit
- 4.13.2
-
org.junit
junit-bom
@@ -433,13 +429,12 @@
org.mockito
mockito-core
- 4.3.1
+ ${mockito.version}
- org.apache.tomcat
- annotations-api
- 6.0.53
- provided
+ jakarta.annotation
+ jakarta.annotation-api
+ ${jakarta.annotation.version}
diff --git a/ratis-common/pom.xml b/ratis-common/pom.xml
index b5676f2c9c..9257acbfc5 100644
--- a/ratis-common/pom.xml
+++ b/ratis-common/pom.xml
@@ -38,12 +38,6 @@
slf4j-api
-
- junit
- junit
- test
-
-
org.junit.jupiter
junit-jupiter-api
@@ -54,11 +48,6 @@
junit-jupiter-engine
test
-
- org.junit.vintage
- junit-vintage-engine
- test
-
org.junit.platform
junit-platform-launcher
diff --git a/ratis-common/src/test/java/org/apache/ratis/BaseTest.java b/ratis-common/src/test/java/org/apache/ratis/BaseTest.java
index 2c9f87c0aa..a8509c239a 100644
--- a/ratis-common/src/test/java/org/apache/ratis/BaseTest.java
+++ b/ratis-common/src/test/java/org/apache/ratis/BaseTest.java
@@ -26,8 +26,6 @@
import org.apache.ratis.util.StringUtils;
import org.apache.ratis.util.TimeDuration;
import org.apache.ratis.util.function.CheckedRunnable;
-import org.junit.After;
-import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
@@ -72,8 +70,6 @@ public void setFirstException(Throwable e) {
}
}
- // TODO: Junit 4 reference should be removed once all the unit tests are migrated to Junit 5.
-
private String testCaseName;
@BeforeEach
@@ -85,8 +81,6 @@ public void setup(TestInfo testInfo) {
+ "." + (method == null? null : method.getName());
}
- // @Before annotation is retained to support junit 4 tests.
- @Before
@BeforeEach
public void checkAssumptions() {
final int leaks = ReferenceCountedLeakDetector.getLeakDetector().getLeakCount();
@@ -99,8 +93,6 @@ public void checkAssumptions() {
Assumptions.assumeTrue(exited == null, () -> "Already exited with " + exited);
}
- // @After annotation is retained to support junit 4 tests.
- @After
@AfterEach
public void assertNoFailures() {
final Throwable e = firstException.get();
@@ -133,7 +125,6 @@ public File getClassTestDir() {
}
public File getTestDir() {
- // This will work for both junit 4 and 5.
return new File(getClassTestDir(), testCaseName);
}
diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml
index ce594d332a..6258d3c1c0 100644
--- a/ratis-examples/pom.xml
+++ b/ratis-examples/pom.xml
@@ -117,11 +117,6 @@
runtime
-
- junit
- junit
- test
-
org.junit.jupiter
junit-jupiter-engine
diff --git a/ratis-proto/pom.xml b/ratis-proto/pom.xml
index e3342f84ba..c3c11ca439 100644
--- a/ratis-proto/pom.xml
+++ b/ratis-proto/pom.xml
@@ -176,8 +176,8 @@
ratis-thirdparty-misc
- org.apache.tomcat
- annotations-api
+ jakarta.annotation
+ jakarta.annotation-api
diff --git a/ratis-server/pom.xml b/ratis-server/pom.xml
index 8ce84148df..dc02403d97 100644
--- a/ratis-server/pom.xml
+++ b/ratis-server/pom.xml
@@ -65,11 +65,6 @@
slf4j-api
-
- junit
- junit
- test
-
org.junit.jupiter
junit-jupiter-api
@@ -80,11 +75,6 @@
junit-jupiter-engine
test
-
- org.junit.vintage
- junit-vintage-engine
- test
-
org.junit.platform
junit-platform-launcher
diff --git a/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java b/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java
index 5a9963e609..9110d2f978 100644
--- a/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java
+++ b/ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java
@@ -34,7 +34,7 @@
import org.apache.ratis.util.Slf4jUtils;
import org.apache.ratis.util.SizeInBytes;
import org.junit.jupiter.api.Assertions;
-import org.junit.Assume;
+import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.slf4j.event.Level;
@@ -84,7 +84,7 @@ RaftClientReply assertNotLeaderException(RaftPeerId expectedSuggestedLeader,
final SimpleMessage message = new SimpleMessage(messageId);
final RaftClientReply reply = rpc.sendRequest(cluster.newRaftClientRequest(ClientId.randomId(), server, message));
Assertions.assertNotNull(reply);
- Assume.assumeFalse(reply.isSuccess());
+ Assumptions.assumeFalse(reply.isSuccess());
final NotLeaderException nle = reply.getNotLeaderException();
Objects.requireNonNull(nle);
Assertions.assertEquals(expectedSuggestedLeader, nle.getSuggestedLeader().getId());
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 bd8634a59b..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.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 getPeersWithPriority(List peers, RaftPeer sugges
static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader)
throws Exception {
- return changeLeader(cluster, oldLeader, AssumptionViolatedException::new);
+ return changeLeader(cluster, oldLeader, Assumptions::abort);
}
- static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader, Function constructor)
- throws Exception {
+ static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader,
+ CheckedConsumer 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 void testChangeLeader() throws Exception {
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);
}
}
diff --git a/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java b/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java
index 23578f01a1..51918ff658 100644
--- a/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java
+++ b/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java
@@ -28,7 +28,10 @@
import org.apache.ratis.statemachine.impl.SimpleStateMachine4Testing;
import org.apache.ratis.statemachine.StateMachine;
import org.apache.ratis.statemachine.TransactionContext;
-import org.junit.*;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.slf4j.Logger;
@@ -121,12 +124,12 @@ public void unblockAllTxns() {
}
}
- @Before
+ @BeforeEach
public void setup() {
mocked = Mockito.mockStatic(CompletableFuture.class, Mockito.CALLS_REAL_METHODS);
}
- @After
+ @AfterEach
public void tearDownClass() {
if (mocked != null) {
mocked.close();
@@ -162,10 +165,10 @@ public void testStateMachineShutdownWaitsForApplyTxn() throws Exception {
RaftClientReply watchReply = client.io().watch(
logIndex, RaftProtos.ReplicationLevel.ALL_COMMITTED);
watchReply.getCommitInfos().forEach(
- val -> Assert.assertTrue(val.getCommitIndex() >= logIndex));
+ val -> Assertions.assertTrue(val.getCommitIndex() >= logIndex));
final RaftServer.Division secondFollower = cluster.getFollowers().get(1);
// Second follower is blocked in apply transaction
- Assert.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < logIndex);
+ Assertions.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < logIndex);
// Now shutdown the follower in a separate thread
final Thread t = new Thread(secondFollower::close);
@@ -176,24 +179,24 @@ public void testStateMachineShutdownWaitsForApplyTxn() throws Exception {
// Now unblock the second follower
long minIndex = ((StateMachineWithConditionalWait) secondFollower.getStateMachine()).blockTxns.stream()
.min(Comparator.naturalOrder()).get();
- Assert.assertEquals(2, StateMachineWithConditionalWait.numTxns.values().stream()
+ Assertions.assertEquals(2, StateMachineWithConditionalWait.numTxns.values().stream()
.filter(val -> val.get() == 3).count());
// The second follower should still be blocked in apply transaction
- Assert.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < minIndex);
+ Assertions.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < minIndex);
for (long index : ((StateMachineWithConditionalWait) secondFollower.getStateMachine()).blockTxns) {
if (minIndex != index) {
((StateMachineWithConditionalWait) secondFollower.getStateMachine()).unBlockApplyTxn(index);
}
}
- Assert.assertEquals(2, StateMachineWithConditionalWait.numTxns.values().stream()
+ Assertions.assertEquals(2, StateMachineWithConditionalWait.numTxns.values().stream()
.filter(val -> val.get() == 3).count());
- Assert.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < minIndex);
+ Assertions.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < minIndex);
((StateMachineWithConditionalWait) secondFollower.getStateMachine()).unBlockApplyTxn(minIndex);
// Now wait for the thread
t.join(5000);
- Assert.assertEquals(logIndex, secondFollower.getInfo().getLastAppliedIndex());
- Assert.assertEquals(3, StateMachineWithConditionalWait.numTxns.values().stream()
+ Assertions.assertEquals(logIndex, secondFollower.getInfo().getLastAppliedIndex());
+ Assertions.assertEquals(3, StateMachineWithConditionalWait.numTxns.values().stream()
.filter(val -> val.get() == 3).count());
cluster.shutdown();
diff --git a/ratis-test/pom.xml b/ratis-test/pom.xml
index a07e38fa76..784efdbd6e 100644
--- a/ratis-test/pom.xml
+++ b/ratis-test/pom.xml
@@ -131,11 +131,6 @@
test
-
- junit
- junit
- test
-
org.junit.jupiter
junit-jupiter-engine
@@ -151,11 +146,6 @@
junit-jupiter-params
test
-
- org.junit.vintage
- junit-vintage-engine
- test
-
org.junit.platform
junit-platform-launcher