This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new c56ce422d RATIS-1977. Remove Junit 4 dependencies. (#1269)
c56ce422d is described below

commit c56ce422d736104d216b539bafdd091cbdd8eb25
Author: slfan1989 <[email protected]>
AuthorDate: Fri May 23 16:03:05 2025 +0800

    RATIS-1977. Remove Junit 4 dependencies. (#1269)
---
 pom.xml                                            | 19 ++++++----------
 ratis-common/pom.xml                               | 11 ----------
 .../src/test/java/org/apache/ratis/BaseTest.java   |  9 --------
 ratis-examples/pom.xml                             |  5 -----
 ratis-proto/pom.xml                                |  4 ++--
 ratis-server/pom.xml                               | 10 ---------
 .../org/apache/ratis/RaftExceptionBaseTest.java    |  4 ++--
 .../test/java/org/apache/ratis/RaftTestUtil.java   | 11 +++++-----
 .../ratis/server/impl/LeaderElectionTests.java     |  2 +-
 .../server/impl/StateMachineShutdownTests.java     | 25 ++++++++++++----------
 ratis-test/pom.xml                                 | 10 ---------
 11 files changed, 32 insertions(+), 78 deletions(-)

diff --git a/pom.xml b/pom.xml
index af14e426f..e79e3ed5e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -221,8 +221,10 @@
     <testsThreadCount>4</testsThreadCount>
 
     <slf4j.version>2.0.7</slf4j.version>
-    <junit-bom.version>5.11.2</junit-bom.version>
+    <junit-bom.version>5.12.2</junit-bom.version>
+    <mockito.version>4.11.0</mockito.version>
     <jacoco.version>0.8.12</jacoco.version>
+    <jakarta.annotation.version>1.3.5</jakarta.annotation.version>
     <flaky-test-groups>flaky | 
org.apache.ratis.test.tag.FlakyTest</flaky-test-groups>
   </properties>
 
@@ -417,12 +419,6 @@
         <scope>test</scope>
         <version>${slf4j.version}</version>
       </dependency>
-
-      <dependency>
-        <groupId>junit</groupId>
-        <artifactId>junit</artifactId>
-        <version>4.13.2</version>
-      </dependency>
       <dependency>
         <groupId>org.junit</groupId>
         <artifactId>junit-bom</artifactId>
@@ -433,13 +429,12 @@
       <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-core</artifactId>
-        <version>4.3.1</version>
+        <version>${mockito.version}</version>
       </dependency>
       <dependency>
-        <groupId>org.apache.tomcat</groupId>
-        <artifactId>annotations-api</artifactId>
-        <version>6.0.53</version>
-        <scope>provided</scope>
+        <groupId>jakarta.annotation</groupId>
+        <artifactId>jakarta.annotation-api</artifactId>
+        <version>${jakarta.annotation.version}</version>
       </dependency>
     </dependencies>
   </dependencyManagement>
diff --git a/ratis-common/pom.xml b/ratis-common/pom.xml
index b5676f2c9..9257acbfc 100644
--- a/ratis-common/pom.xml
+++ b/ratis-common/pom.xml
@@ -38,12 +38,6 @@
       <artifactId>slf4j-api</artifactId>
     </dependency>
 
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-api</artifactId>
@@ -54,11 +48,6 @@
       <artifactId>junit-jupiter-engine</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.junit.platform</groupId>
       <artifactId>junit-platform-launcher</artifactId>
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 2c9f87c0a..a8509c239 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.Slf4jUtils;
 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 abstract class BaseTest {
     }
   }
 
-  // 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 abstract class BaseTest {
         + "." + (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 abstract class BaseTest {
     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 abstract class BaseTest {
   }
 
   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 ce594d332..6258d3c1c 100644
--- a/ratis-examples/pom.xml
+++ b/ratis-examples/pom.xml
@@ -117,11 +117,6 @@
       <scope>runtime</scope>
     </dependency>
 
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
diff --git a/ratis-proto/pom.xml b/ratis-proto/pom.xml
index e3342f84b..c3c11ca43 100644
--- a/ratis-proto/pom.xml
+++ b/ratis-proto/pom.xml
@@ -176,8 +176,8 @@
       <artifactId>ratis-thirdparty-misc</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.tomcat</groupId>
-      <artifactId>annotations-api</artifactId>
+      <groupId>jakarta.annotation</groupId>
+      <artifactId>jakarta.annotation-api</artifactId>
     </dependency>
   </dependencies>
 </project>
diff --git a/ratis-server/pom.xml b/ratis-server/pom.xml
index 8ce84148d..dc02403d9 100644
--- a/ratis-server/pom.xml
+++ b/ratis-server/pom.xml
@@ -65,11 +65,6 @@
       <artifactId>slf4j-api</artifactId>
     </dependency>
 
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-api</artifactId>
@@ -80,11 +75,6 @@
       <artifactId>junit-jupiter-engine</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.junit.platform</groupId>
       <artifactId>junit-platform-launcher</artifactId>
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 5a9963e60..9110d2f97 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.JavaUtils;
 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 @@ public abstract class RaftExceptionBaseTest<CLUSTER extends 
MiniRaftCluster>
     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 bd8634a59..d0641e39c 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.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 @@ public interface RaftTestUtil {
 
   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<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 f35626894..25caa9d06 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);
     }
   }
 
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 23578f01a..51918ff65 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.server.RaftServer;
 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 abstract class StateMachineShutdownTests<CLUSTER 
extends MiniRaftCluster>
     }
   }
 
-  @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 abstract class StateMachineShutdownTests<CLUSTER 
extends MiniRaftCluster>
       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 abstract class StateMachineShutdownTests<CLUSTER 
extends MiniRaftCluster>
       // 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 a07e38fa7..784efdbd6 100644
--- a/ratis-test/pom.xml
+++ b/ratis-test/pom.xml
@@ -131,11 +131,6 @@
       <scope>test</scope>
     </dependency>
 
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
@@ -151,11 +146,6 @@
       <artifactId>junit-jupiter-params</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.junit.platform</groupId>
       <artifactId>junit-platform-launcher</artifactId>

Reply via email to