Skip to content

Commit 371f68c

Browse files
slfan1989szetszwo
authored andcommitted
RATIS-1977. Remove Junit 4 dependencies. (#1269)
1 parent a458272 commit 371f68c

File tree

11 files changed

+103
-152
lines changed

11 files changed

+103
-152
lines changed

pom.xml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@
221221
<testsThreadCount>4</testsThreadCount>
222222

223223
<slf4j.version>2.0.7</slf4j.version>
224-
<junit-bom.version>5.11.2</junit-bom.version>
224+
<junit-bom.version>5.12.2</junit-bom.version>
225+
<mockito.version>4.11.0</mockito.version>
225226
<jacoco.version>0.8.12</jacoco.version>
227+
<jakarta.annotation.version>1.3.5</jakarta.annotation.version>
226228
<flaky-test-groups>flaky | org.apache.ratis.test.tag.FlakyTest</flaky-test-groups>
227229
</properties>
228230

@@ -417,12 +419,6 @@
417419
<scope>test</scope>
418420
<version>${slf4j.version}</version>
419421
</dependency>
420-
421-
<dependency>
422-
<groupId>junit</groupId>
423-
<artifactId>junit</artifactId>
424-
<version>4.13.2</version>
425-
</dependency>
426422
<dependency>
427423
<groupId>org.junit</groupId>
428424
<artifactId>junit-bom</artifactId>
@@ -433,13 +429,12 @@
433429
<dependency>
434430
<groupId>org.mockito</groupId>
435431
<artifactId>mockito-core</artifactId>
436-
<version>4.3.1</version>
432+
<version>${mockito.version}</version>
437433
</dependency>
438434
<dependency>
439-
<groupId>org.apache.tomcat</groupId>
440-
<artifactId>annotations-api</artifactId>
441-
<version>6.0.53</version>
442-
<scope>provided</scope>
435+
<groupId>jakarta.annotation</groupId>
436+
<artifactId>jakarta.annotation-api</artifactId>
437+
<version>${jakarta.annotation.version}</version>
443438
</dependency>
444439
</dependencies>
445440
</dependencyManagement>

ratis-common/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
<artifactId>slf4j-api</artifactId>
3939
</dependency>
4040

41-
<dependency>
42-
<groupId>junit</groupId>
43-
<artifactId>junit</artifactId>
44-
<scope>test</scope>
45-
</dependency>
46-
4741
<dependency>
4842
<groupId>org.junit.jupiter</groupId>
4943
<artifactId>junit-jupiter-api</artifactId>
@@ -54,11 +48,6 @@
5448
<artifactId>junit-jupiter-engine</artifactId>
5549
<scope>test</scope>
5650
</dependency>
57-
<dependency>
58-
<groupId>org.junit.vintage</groupId>
59-
<artifactId>junit-vintage-engine</artifactId>
60-
<scope>test</scope>
61-
</dependency>
6251
<dependency>
6352
<groupId>org.junit.platform</groupId>
6453
<artifactId>junit-platform-launcher</artifactId>

ratis-common/src/test/java/org/apache/ratis/BaseTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import org.apache.ratis.util.StringUtils;
2626
import org.apache.ratis.util.TimeDuration;
2727
import org.apache.ratis.util.function.CheckedRunnable;
28-
import org.junit.After;
29-
import org.junit.Before;
3028
import org.junit.jupiter.api.AfterEach;
3129
import org.junit.jupiter.api.Assertions;
3230
import org.junit.jupiter.api.Assumptions;
@@ -71,8 +69,6 @@ public void setFirstException(Throwable e) {
7169
}
7270
}
7371

74-
// TODO: Junit 4 reference should be removed once all the unit tests are migrated to Junit 5.
75-
7672
private String testCaseName;
7773

7874
@BeforeEach
@@ -84,8 +80,6 @@ public void setup(TestInfo testInfo) {
8480
+ "." + (method == null? null : method.getName());
8581
}
8682

87-
// @Before annotation is retained to support junit 4 tests.
88-
@Before
8983
@BeforeEach
9084
public void checkAssumptions() {
9185
final Throwable first = firstException.get();
@@ -95,8 +89,6 @@ public void checkAssumptions() {
9589
Assumptions.assumeTrue(exited == null, () -> "Already exited with " + exited);
9690
}
9791

98-
// @After annotation is retained to support junit 4 tests.
99-
@After
10092
@AfterEach
10193
public void assertNoFailures() {
10294
final Throwable e = firstException.get();
@@ -129,7 +121,6 @@ public File getClassTestDir() {
129121
}
130122

131123
public File getTestDir() {
132-
// This will work for both junit 4 and 5.
133124
return new File(getClassTestDir(), testCaseName);
134125
}
135126

ratis-examples/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@
117117
<scope>runtime</scope>
118118
</dependency>
119119

120-
<dependency>
121-
<groupId>junit</groupId>
122-
<artifactId>junit</artifactId>
123-
<scope>test</scope>
124-
</dependency>
125120
<dependency>
126121
<groupId>org.junit.jupiter</groupId>
127122
<artifactId>junit-jupiter-engine</artifactId>

ratis-proto/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@
176176
<artifactId>ratis-thirdparty-misc</artifactId>
177177
</dependency>
178178
<dependency>
179-
<groupId>org.apache.tomcat</groupId>
180-
<artifactId>annotations-api</artifactId>
179+
<groupId>jakarta.annotation</groupId>
180+
<artifactId>jakarta.annotation-api</artifactId>
181181
</dependency>
182182
</dependencies>
183183
</project>

ratis-server/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@
6565
<artifactId>slf4j-api</artifactId>
6666
</dependency>
6767

68-
<dependency>
69-
<groupId>junit</groupId>
70-
<artifactId>junit</artifactId>
71-
<scope>test</scope>
72-
</dependency>
7368
<dependency>
7469
<groupId>org.junit.jupiter</groupId>
7570
<artifactId>junit-jupiter-api</artifactId>
@@ -80,11 +75,6 @@
8075
<artifactId>junit-jupiter-engine</artifactId>
8176
<scope>test</scope>
8277
</dependency>
83-
<dependency>
84-
<groupId>org.junit.vintage</groupId>
85-
<artifactId>junit-vintage-engine</artifactId>
86-
<scope>test</scope>
87-
</dependency>
8878
<dependency>
8979
<groupId>org.junit.platform</groupId>
9080
<artifactId>junit-platform-launcher</artifactId>

ratis-server/src/test/java/org/apache/ratis/RaftExceptionBaseTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.apache.ratis.util.Slf4jUtils;
3535
import org.apache.ratis.util.SizeInBytes;
3636
import org.junit.jupiter.api.Assertions;
37-
import org.junit.Assume;
37+
import org.junit.jupiter.api.Assumptions;
3838
import org.junit.jupiter.api.Test;
3939
import org.slf4j.event.Level;
4040

@@ -84,7 +84,7 @@ RaftClientReply assertNotLeaderException(RaftPeerId expectedSuggestedLeader,
8484
final SimpleMessage message = new SimpleMessage(messageId);
8585
final RaftClientReply reply = rpc.sendRequest(cluster.newRaftClientRequest(ClientId.randomId(), server, message));
8686
Assertions.assertNotNull(reply);
87-
Assume.assumeFalse(reply.isSuccess());
87+
Assumptions.assumeFalse(reply.isSuccess());
8888
final NotLeaderException nle = reply.getNotLeaderException();
8989
Objects.requireNonNull(nle);
9090
Assertions.assertEquals(expectedSuggestedLeader, nle.getSuggestedLeader().getId());

ratis-server/src/test/java/org/apache/ratis/RaftTestUtil.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
import org.apache.ratis.util.Preconditions;
4444
import org.apache.ratis.util.ProtoUtils;
4545
import org.apache.ratis.util.TimeDuration;
46-
import org.junit.AssumptionViolatedException;
46+
import org.apache.ratis.util.function.CheckedConsumer;
47+
import org.junit.jupiter.api.Assumptions;
4748
import org.junit.jupiter.api.Assertions;
4849
import org.slf4j.Logger;
4950
import org.slf4j.LoggerFactory;
@@ -475,18 +476,18 @@ static List<RaftPeer> getPeersWithPriority(List<RaftPeer> peers, RaftPeer sugges
475476

476477
static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader)
477478
throws Exception {
478-
return changeLeader(cluster, oldLeader, AssumptionViolatedException::new);
479+
return changeLeader(cluster, oldLeader, Assumptions::abort);
479480
}
480481

481-
static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader, Function<String, Exception> constructor)
482-
throws Exception {
482+
static RaftPeerId changeLeader(MiniRaftCluster cluster, RaftPeerId oldLeader,
483+
CheckedConsumer<String, Exception> failToChangeLeaderHandler) throws Exception {
483484
final String name = JavaUtils.getCallerStackTraceElement().getMethodName() + "-changeLeader";
484485
cluster.setBlockRequestsFrom(oldLeader.toString(), true);
485486
try {
486487
return JavaUtils.attemptRepeatedly(() -> {
487488
final RaftPeerId newLeader = waitForLeader(cluster).getId();
488489
if (newLeader.equals(oldLeader)) {
489-
throw constructor.apply("Failed to change leader: newLeader == oldLeader == " + oldLeader);
490+
failToChangeLeaderHandler.accept("Failed to change leader: newLeader == oldLeader == " + oldLeader);
490491
}
491492
LOG.info("Changed leader from " + oldLeader + " to " + newLeader);
492493
return newLeader;

0 commit comments

Comments
 (0)