From 3ef590f0ef9d755e40ba1eb26cb09baea7ef725d Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Sun, 26 Jul 2026 14:27:34 -0700 Subject: [PATCH] RATIS-2624. Update thirdparty to use junit 5. --- test/pom.xml | 26 ++++++++++++++++--- .../thirdparty/demo/grpc/GrpcSslTest.java | 13 ++++------ .../ratis/thirdparty/demo/grpc/GrpcTest.java | 14 +++++----- .../thirdparty/demo/netty/NettySslTest.java | 7 ++--- .../thirdparty/demo/proto/ProtoUtilTest.java | 12 ++++----- test/src/test/resources/log4j.properties | 6 ++--- 6 files changed, 44 insertions(+), 34 deletions(-) diff --git a/test/pom.xml b/test/pom.xml index 8e1b828..6aa8abe 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -29,21 +29,39 @@ 0.6.1 - 4.13.2 + 5.14.4 2.0.18 + + + + org.junit + junit-bom + ${junit-bom.version} + pom + import + + + + org.apache.ratis ratis-thirdparty-misc + + + org.junit.jupiter + junit-jupiter-engine + test + - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter-api test + org.slf4j slf4j-api diff --git a/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcSslTest.java b/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcSslTest.java index 1888219..0ffa816 100644 --- a/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcSslTest.java +++ b/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcSslTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,20 +20,17 @@ import org.apache.ratis.thirdparty.demo.common.SslClientConfig; import org.apache.ratis.thirdparty.demo.common.SslServerConfig; import org.apache.ratis.thirdparty.demo.common.TestUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.io.IOException; -import java.net.URL; -import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class GrpcSslTest { private final static Logger LOG = LoggerFactory.getLogger(GrpcSslTest.class); - @Test public void testSslClientServer() throws InterruptedException, IOException { final int port = TestUtils.randomPort(); @@ -55,7 +52,7 @@ public void testSslClientServer() throws InterruptedException, IOException { String user = "testuser"; String response = client.greet(user); LOG.info("Greet result: {}", response); - Assert.assertEquals("Hello " + user, response); + assertEquals("Hello " + user, response); } finally { client.shutdown(); } diff --git a/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcTest.java b/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcTest.java index 1aabd00..9b77119 100644 --- a/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcTest.java +++ b/test/src/test/java/org/apache/ratis/thirdparty/demo/grpc/GrpcTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,22 +18,20 @@ package org.apache.ratis.thirdparty.demo.grpc; import org.apache.ratis.thirdparty.demo.common.TestUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Unit test for demo gRPC client/server with ratis thirdparty. */ -@RunWith(JUnit4.class) public class GrpcTest { - private final static Logger LOG = LoggerFactory.getLogger(GrpcTest.class); + @Test public void testClientServer() throws IOException, InterruptedException { final int port = TestUtils.randomPort(); @@ -46,7 +44,7 @@ public void testClientServer() throws IOException, InterruptedException { String user = "testuser"; String response = client.greet(user); LOG.info("Greet result: {}", response); - Assert.assertEquals("Hello " + user, response); + assertEquals("Hello " + user, response); } finally { client.shutdown(); } diff --git a/test/src/test/java/org/apache/ratis/thirdparty/demo/netty/NettySslTest.java b/test/src/test/java/org/apache/ratis/thirdparty/demo/netty/NettySslTest.java index 3459b81..f1deda8 100644 --- a/test/src/test/java/org/apache/ratis/thirdparty/demo/netty/NettySslTest.java +++ b/test/src/test/java/org/apache/ratis/thirdparty/demo/netty/NettySslTest.java @@ -22,8 +22,7 @@ import org.apache.ratis.thirdparty.demo.common.TestUtils; import org.apache.ratis.thirdparty.io.netty.buffer.ByteBuf; import org.apache.ratis.thirdparty.io.netty.handler.ssl.SslContext; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,6 +31,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Unit test for demo netty client/server with ratis thirdparty. */ @@ -70,7 +71,7 @@ static void testNetty(int port, SslServerConfig serverSslConf, SslClientConfig c final CompletableFuture future = replyFutures.get(i); final String reply = future.get(3, TimeUnit.SECONDS); LOG.info(reply); - Assert.assertEquals(NettyServer.toReply(words[i]), reply); + assertEquals(NettyServer.toReply(words[i]), reply); } } } diff --git a/test/src/test/java/org/apache/ratis/thirdparty/demo/proto/ProtoUtilTest.java b/test/src/test/java/org/apache/ratis/thirdparty/demo/proto/ProtoUtilTest.java index 0f8b4b0..caa4b79 100644 --- a/test/src/test/java/org/apache/ratis/thirdparty/demo/proto/ProtoUtilTest.java +++ b/test/src/test/java/org/apache/ratis/thirdparty/demo/proto/ProtoUtilTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,15 +18,13 @@ package org.apache.ratis.thirdparty.demo.proto; import org.apache.ratis.thirdparty.com.google.protobuf.util.JsonFormat; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Unit test for ensure that protobuf-java-util is properly shaded as ratis thirdparty. */ -@RunWith(JUnit4.class) public class ProtoUtilTest { @Test @@ -36,7 +34,7 @@ public void testJsonFormatPrinter() throws Exception { final String expected = "{\n" + " \"name\": \"ratis\"\n" + "}"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); } } diff --git a/test/src/test/resources/log4j.properties b/test/src/test/resources/log4j.properties index 3bf1619..7b26ce9 100644 --- a/test/src/test/resources/log4j.properties +++ b/test/src/test/resources/log4j.properties @@ -9,7 +9,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# log4j configuration used during build and unit tests + +# log4j configuration used in unit tests log4j.rootLogger=INFO,stdout log4j.threshold=ALL @@ -18,6 +19,3 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c{2} (%F:%M(%L)) - %m%n log4j.logger.org.apache.hadoop.util.NativeCodeLoader=ERROR - -# for debugging low level Ozone operations, uncomment this line -# log4j.logger.org.apache.hadoop.ozone=DEBUG