From 5ec6bccff983a994b07107e0f9eb89d16792d7b8 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Fri, 23 May 2025 05:49:20 +0800 Subject: [PATCH 1/6] RATIS-1977. Remove Junit 4 dependencies. --- pom.xml | 12 +++------ ratis-common/pom.xml | 11 -------- .../test/java/org/apache/ratis/BaseTest.java | 6 ----- ratis-docs/src/site/markdown/snapshot.md | 3 ++- ratis-examples/pom.xml | 5 ---- ratis-server/pom.xml | 10 -------- .../apache/ratis/RaftExceptionBaseTest.java | 4 +-- .../java/org/apache/ratis/RaftTestUtil.java | 4 +-- .../impl/StateMachineShutdownTests.java | 25 +++++++++++-------- ratis-test/pom.xml | 10 -------- 10 files changed, 24 insertions(+), 66 deletions(-) diff --git a/pom.xml b/pom.xml index af14e426f2..79f1475e37 100644 --- a/pom.xml +++ b/pom.xml @@ -222,6 +222,8 @@ 2.0.7 5.11.2 + 4.3.1 + 6.0.53 0.8.12 flaky | org.apache.ratis.test.tag.FlakyTest @@ -417,12 +419,6 @@ test ${slf4j.version} - - - junit - junit - 4.13.2 - org.junit junit-bom @@ -433,12 +429,12 @@ org.mockito mockito-core - 4.3.1 + ${mockito.version} org.apache.tomcat annotations-api - 6.0.53 + ${tomcat.version} provided 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..0318ca799c 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; @@ -85,8 +83,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 +95,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(); diff --git a/ratis-docs/src/site/markdown/snapshot.md b/ratis-docs/src/site/markdown/snapshot.md index a9f06511fc..a84b7f7853 100644 --- a/ratis-docs/src/site/markdown/snapshot.md +++ b/ratis-docs/src/site/markdown/snapshot.md @@ -229,7 +229,8 @@ interface FollowerEventApi { * In order to catch up, the {@link StateMachine} has to install the latest snapshot asynchronously. * * @param roleInfoProto information about the current node role and rpc delay information. - * @param firstTermIndexInLog The term-index of the first append entry available in the leader's log. + * @param firstTermIndexInLog The + * term-index of the first append entry available in the leader's log. * @return return the last term-index in the snapshot after the snapshot installation. */ default CompletableFuture notifyInstallSnapshotFromLeader( 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-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..c9db9933b2 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,7 @@ import org.apache.ratis.util.Preconditions; import org.apache.ratis.util.ProtoUtils; import org.apache.ratis.util.TimeDuration; -import org.junit.AssumptionViolatedException; +import org.opentest4j.TestAbortedException; import org.junit.jupiter.api.Assertions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -479,7 +479,7 @@ 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, TestAbortedException::new); } static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader, Function constructor) 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 From c8b6f2c1f81fb36129979f5ba5a5649fd43fa096 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Fri, 23 May 2025 06:07:45 +0800 Subject: [PATCH 2/6] RATIS-1977. Remove Junit 4 dependencies. --- ratis-docs/src/site/markdown/snapshot.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ratis-docs/src/site/markdown/snapshot.md b/ratis-docs/src/site/markdown/snapshot.md index a84b7f7853..a9f06511fc 100644 --- a/ratis-docs/src/site/markdown/snapshot.md +++ b/ratis-docs/src/site/markdown/snapshot.md @@ -229,8 +229,7 @@ interface FollowerEventApi { * In order to catch up, the {@link StateMachine} has to install the latest snapshot asynchronously. * * @param roleInfoProto information about the current node role and rpc delay information. - * @param firstTermIndexInLog The - * term-index of the first append entry available in the leader's log. + * @param firstTermIndexInLog The term-index of the first append entry available in the leader's log. * @return return the last term-index in the snapshot after the snapshot installation. */ default CompletableFuture notifyInstallSnapshotFromLeader( From 77e8c0b960e2fe21e3746ee8216aee93d4714d8e Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Fri, 23 May 2025 10:50:55 +0800 Subject: [PATCH 3/6] RATIS-1977. Improve Code. --- .../src/test/java/org/apache/ratis/RaftTestUtil.java | 11 ++++++----- .../apache/ratis/server/impl/LeaderElectionTests.java | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) 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.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 @@ static List getPeersWithPriority(List peers, RaftPeer sugges 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 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); } } From 8749e5f199802c1976fdd7da33b4f8f9a36616f1 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Fri, 23 May 2025 11:16:34 +0800 Subject: [PATCH 4/6] RATIS-1977. Improve Code. --- pom.xml | 11 ++--------- .../src/test/java/org/apache/ratis/BaseTest.java | 3 --- ratis-proto/pom.xml | 4 ---- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 79f1475e37..63dea3aee1 100644 --- a/pom.xml +++ b/pom.xml @@ -221,9 +221,8 @@ 4 2.0.7 - 5.11.2 - 4.3.1 - 6.0.53 + 5.12.2 + 4.11.0 0.8.12 flaky | org.apache.ratis.test.tag.FlakyTest @@ -431,12 +430,6 @@ mockito-core ${mockito.version} - - org.apache.tomcat - annotations-api - ${tomcat.version} - provided - 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 0318ca799c..a8509c239a 100644 --- a/ratis-common/src/test/java/org/apache/ratis/BaseTest.java +++ b/ratis-common/src/test/java/org/apache/ratis/BaseTest.java @@ -70,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 @@ -127,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-proto/pom.xml b/ratis-proto/pom.xml index e3342f84ba..801633585d 100644 --- a/ratis-proto/pom.xml +++ b/ratis-proto/pom.xml @@ -175,9 +175,5 @@ org.apache.ratis ratis-thirdparty-misc - - org.apache.tomcat - annotations-api - From c00a0aac0eeea0b93495c5d1a37394c18d4e2c5f Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Fri, 23 May 2025 11:28:14 +0800 Subject: [PATCH 5/6] RATIS-1977. Improve Code. --- pom.xml | 6 ++++++ ratis-proto/pom.xml | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 63dea3aee1..3d4de825fe 100644 --- a/pom.xml +++ b/pom.xml @@ -224,6 +224,7 @@ 5.12.2 4.11.0 0.8.12 + 1.3.2 flaky | org.apache.ratis.test.tag.FlakyTest @@ -430,6 +431,11 @@ mockito-core ${mockito.version} + + javax.annotation + javax.annotation-api + ${annotation.version} + diff --git a/ratis-proto/pom.xml b/ratis-proto/pom.xml index 801633585d..8a81026141 100644 --- a/ratis-proto/pom.xml +++ b/ratis-proto/pom.xml @@ -175,5 +175,9 @@ org.apache.ratis ratis-thirdparty-misc + + javax.annotation + javax.annotation-api + From 4801472d52ad655bfe5d519ab99f2cbcb3eb50f2 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Fri, 23 May 2025 13:37:10 +0800 Subject: [PATCH 6/6] RATIS-1977. Use jakarta annotation. --- pom.xml | 8 ++++---- ratis-proto/pom.xml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 3d4de825fe..e79e3ed5ec 100644 --- a/pom.xml +++ b/pom.xml @@ -224,7 +224,7 @@ 5.12.2 4.11.0 0.8.12 - 1.3.2 + 1.3.5 flaky | org.apache.ratis.test.tag.FlakyTest @@ -432,9 +432,9 @@ ${mockito.version} - javax.annotation - javax.annotation-api - ${annotation.version} + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation.version} diff --git a/ratis-proto/pom.xml b/ratis-proto/pom.xml index 8a81026141..c3c11ca439 100644 --- a/ratis-proto/pom.xml +++ b/ratis-proto/pom.xml @@ -176,8 +176,8 @@ ratis-thirdparty-misc - javax.annotation - javax.annotation-api + jakarta.annotation + jakarta.annotation-api