This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.6 by this push:
new 247d9bbf9ec HBASE-29828 Upgrade TestIPC related tests to junit5 (#7626)
247d9bbf9ec is described below
commit 247d9bbf9ec72c379945b0599711e2d95c543ec3
Author: Duo Zhang <[email protected]>
AuthorDate: Sat Jan 17 23:22:05 2026 +0800
HBASE-29828 Upgrade TestIPC related tests to junit5 (#7626)
Signed-off-by: Nick Dimiduk <[email protected]>
(cherry picked from commit 2c8d1c0073078c30efacf1a5542196199557d52c)
---
.../apache/hadoop/hbase/ipc/AbstractTestIPC.java | 156 +++++++++++----------
.../apache/hadoop/hbase/ipc/TestBlockingIPC.java | 29 ++--
.../org/apache/hadoop/hbase/ipc/TestNettyIPC.java | 47 +++----
.../apache/hadoop/hbase/ipc/TestNettyTlsIPC.java | 82 +++++------
4 files changed, 155 insertions(+), 159 deletions(-)
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java
index b18d111c336..658a8a705bc 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/AbstractTestIPC.java
@@ -27,6 +27,7 @@ import static
org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.has
import static org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl.SERVICE;
import static
org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl.newBlockingStub;
import static org.apache.hadoop.hbase.ipc.TestProtobufRpcServiceImpl.newStub;
+import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
@@ -34,14 +35,15 @@ import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -52,7 +54,7 @@ import static
org.mockito.internal.verification.VerificationModeFactory.times;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
-import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
+import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.SpanData;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -82,10 +84,9 @@ import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.util.StringUtils;
import org.hamcrest.Matcher;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runners.Parameterized.Parameter;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -132,13 +133,16 @@ public abstract class AbstractTestIPC {
protected abstract AbstractRpcClient<?> createRpcClientNoCodec(Configuration
conf);
- @Rule
- public OpenTelemetryRule traceRule = OpenTelemetryRule.create();
+ @RegisterExtension
+ private static final OpenTelemetryExtension OTEL_EXT =
OpenTelemetryExtension.create();
- @Parameter(0)
- public Class<? extends RpcServer> rpcServerImpl;
+ private Class<? extends RpcServer> rpcServerImpl;
- @Before
+ protected AbstractTestIPC(Class<? extends RpcServer> rpcServerImpl) {
+ this.rpcServerImpl = rpcServerImpl;
+ }
+
+ @BeforeEach
public void setUpBeforeTest() {
CONF.setClass(RpcServerFactory.CUSTOM_RPC_SERVER_IMPL_CONF_KEY,
rpcServerImpl, RpcServer.class);
}
@@ -146,7 +150,7 @@ public abstract class AbstractTestIPC {
/**
* Ensure we do not HAVE TO HAVE a codec.
*/
- @Test
+ @TestTemplate
public void testNoCodec() throws IOException, ServiceException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -172,7 +176,7 @@ public abstract class AbstractTestIPC {
* unsupported, we'll get an exception out of some time (meantime, have to
trace it manually to
* confirm that compression is happening down in the client and server).
*/
- @Test
+ @TestTemplate
public void testCompressCellBlock() throws IOException, ServiceException {
Configuration clientConf = new Configuration(CONF);
clientConf.set("hbase.client.rpc.compressor",
GzipCodec.class.getCanonicalName());
@@ -208,7 +212,7 @@ public abstract class AbstractTestIPC {
protected abstract AbstractRpcClient<?>
createRpcClientRTEDuringConnectionSetup(Configuration conf) throws
IOException;
- @Test
+ @TestTemplate
public void testRTEDuringConnectionSetup() throws Exception {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -221,7 +225,7 @@ public abstract class AbstractTestIPC {
fail("Expected an exception to have been thrown!");
} catch (Exception e) {
LOG.info("Caught expected exception: " + e.toString());
- assertTrue(e.toString(),
StringUtils.stringifyException(e).contains("Injected fault"));
+ assertTrue(StringUtils.stringifyException(e).contains("Injected fault"),
e.toString());
} finally {
rpcServer.stop();
}
@@ -230,7 +234,7 @@ public abstract class AbstractTestIPC {
/**
* Tests that the rpc scheduler is called when requests arrive.
*/
- @Test
+ @TestTemplate
public void testRpcScheduler() throws IOException, ServiceException,
InterruptedException {
Configuration clientConf = new Configuration(CONF);
RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1));
@@ -254,7 +258,7 @@ public abstract class AbstractTestIPC {
}
/** Tests that the rpc scheduler is called when requests arrive. */
- @Test
+ @TestTemplate
public void testRpcMaxRequestSize() throws IOException, ServiceException {
Configuration clientConf = new Configuration(CONF);
clientConf.setInt(RpcServer.MAX_REQUEST_SIZE, 1000);
@@ -276,8 +280,8 @@ public abstract class AbstractTestIPC {
fail("RPC should have failed because it exceeds max request size");
} catch (ServiceException e) {
LOG.info("Caught expected exception: " + e);
- assertTrue(e.toString(),
- StringUtils.stringifyException(e).contains("RequestTooBigException"));
+
assertTrue(StringUtils.stringifyException(e).contains("RequestTooBigException"),
+ e.toString());
} finally {
rpcServer.stop();
}
@@ -287,7 +291,7 @@ public abstract class AbstractTestIPC {
* Tests that the RpcServer creates & dispatches CallRunner object to
scheduler with non-null
* remoteAddress set to its Call Object
*/
- @Test
+ @TestTemplate
public void testRpcServerForNotNullRemoteAddressInCallObject()
throws IOException, ServiceException {
Configuration clientConf = new Configuration(CONF);
@@ -305,7 +309,7 @@ public abstract class AbstractTestIPC {
}
}
- @Test
+ @TestTemplate
public void testRemoteError() throws IOException, ServiceException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -314,18 +318,18 @@ public abstract class AbstractTestIPC {
try (AbstractRpcClient<?> client = createRpcClient(clientConf)) {
rpcServer.start();
BlockingInterface stub = newBlockingStub(client,
rpcServer.getListenerAddress());
- stub.error(null, EmptyRequestProto.getDefaultInstance());
- } catch (ServiceException e) {
- LOG.info("Caught expected exception: " + e);
- IOException ioe = ProtobufUtil.handleRemoteException(e);
- assertTrue(ioe instanceof DoNotRetryIOException);
- assertTrue(ioe.getMessage().contains("server error!"));
+ ServiceException se = assertThrows(ServiceException.class,
+ () -> stub.error(null, EmptyRequestProto.getDefaultInstance()));
+ LOG.info("Caught expected exception: " + se);
+ IOException ioe = ProtobufUtil.handleRemoteException(se);
+ assertThat(ioe, instanceOf(DoNotRetryIOException.class));
+ assertThat(ioe.getMessage(), containsString("server error!"));
} finally {
rpcServer.stop();
}
}
- @Test
+ @TestTemplate
public void testTimeout() throws IOException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -341,23 +345,25 @@ public abstract class AbstractTestIPC {
pcrc.reset();
pcrc.setCallTimeout(timeout);
long startTime = System.nanoTime();
- try {
- stub.pause(pcrc, PauseRequestProto.newBuilder().setMs(ms).build());
- } catch (ServiceException e) {
- long waitTime = (System.nanoTime() - startTime) / 1000000;
- // expected
- LOG.info("Caught expected exception: " + e);
- IOException ioe = ProtobufUtil.handleRemoteException(e);
- assertTrue(ioe.getCause() instanceof CallTimeoutException);
- // confirm that we got exception before the actual pause.
- assertTrue(waitTime < ms);
- }
+ ServiceException se = assertThrows(ServiceException.class,
+ () -> stub.pause(pcrc,
PauseRequestProto.newBuilder().setMs(ms).build()));
+ long waitTime = (System.nanoTime() - startTime) / 1000000;
+ // expected
+ LOG.info("Caught expected exception: " + se);
+ IOException ioe = ProtobufUtil.handleRemoteException(se);
+ assertThat(ioe.getCause(), instanceOf(CallTimeoutException.class));
+ // confirm that we got exception before the actual pause.
+ assertThat(waitTime, lessThan((long) ms));
}
} finally {
+ // wait until all active calls quit, otherwise it may mess up the
tracing spans
+ await().atMost(Duration.ofSeconds(2))
+ .untilAsserted(() -> assertEquals(0,
rpcServer.getScheduler().getActiveRpcHandlerCount()));
rpcServer.stop();
}
}
+ @SuppressWarnings("deprecation")
private static class FailingSimpleRpcServer extends SimpleRpcServer {
FailingSimpleRpcServer(Server server, String name,
@@ -397,27 +403,25 @@ public abstract class AbstractTestIPC {
}
/** Tests that the connection closing is handled by the client with
outstanding RPC calls */
- @Test
+ @TestTemplate
public void testConnectionCloseWithOutstandingRPCs() throws
InterruptedException, IOException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createTestFailingRpcServer("testRpcServer",
Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(SERVICE,
null)),
new InetSocketAddress("localhost", 0), CONF, new FifoRpcScheduler(CONF,
1));
-
try (AbstractRpcClient<?> client = createRpcClient(clientConf)) {
rpcServer.start();
BlockingInterface stub = newBlockingStub(client,
rpcServer.getListenerAddress());
EchoRequestProto param =
EchoRequestProto.newBuilder().setMessage("hello").build();
- stub.echo(null, param);
- fail("RPC should have failed because connection closed");
- } catch (ServiceException e) {
- LOG.info("Caught expected exception: " + e.toString());
+ ServiceException se = assertThrows(ServiceException.class, () ->
stub.echo(null, param),
+ "RPC should have failed because connection closed");
+ LOG.info("Caught expected exception: " + se);
} finally {
rpcServer.stop();
}
}
- @Test
+ @TestTemplate
public void testAsyncEcho() throws IOException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -448,14 +452,13 @@ public abstract class AbstractTestIPC {
}
}
- @Test
+ @TestTemplate
public void testAsyncRemoteError() throws IOException {
Configuration clientConf = new Configuration(CONF);
- AbstractRpcClient<?> client = createRpcClient(clientConf);
RpcServer rpcServer = createRpcServer("testRpcServer",
Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(SERVICE,
null)),
new InetSocketAddress("localhost", 0), CONF, new FifoRpcScheduler(CONF,
1));
- try {
+ try (AbstractRpcClient<?> client = createRpcClient(clientConf)) {
rpcServer.start();
Interface stub = newStub(client, rpcServer.getListenerAddress());
BlockingRpcCallback<EmptyResponseProto> callback = new
BlockingRpcCallback<>();
@@ -465,15 +468,14 @@ public abstract class AbstractTestIPC {
assertTrue(pcrc.failed());
LOG.info("Caught expected exception: " + pcrc.getFailed());
IOException ioe = ProtobufUtil.handleRemoteException(pcrc.getFailed());
- assertTrue(ioe instanceof DoNotRetryIOException);
- assertTrue(ioe.getMessage().contains("server error!"));
+ assertThat(ioe, instanceOf(DoNotRetryIOException.class));
+ assertThat(ioe.getMessage(), containsString("server error!"));
} finally {
- client.close();
rpcServer.stop();
}
}
- @Test
+ @TestTemplate
public void testAsyncTimeout() throws IOException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -503,19 +505,21 @@ public abstract class AbstractTestIPC {
assertTrue(pcrc.failed());
LOG.info("Caught expected exception: " + pcrc.getFailed());
IOException ioe = ProtobufUtil.handleRemoteException(pcrc.getFailed());
- assertTrue(ioe.getCause() instanceof CallTimeoutException);
+ assertThat(ioe.getCause(), instanceOf(CallTimeoutException.class));
}
// confirm that we got exception before the actual pause.
- assertTrue(waitTime < ms);
+ assertThat(waitTime, lessThan((long) ms));
} finally {
+ // wait until all active calls quit, otherwise it may mess up the
tracing spans
+ await().atMost(Duration.ofSeconds(2))
+ .untilAsserted(() -> assertEquals(0,
rpcServer.getScheduler().getActiveRpcHandlerCount()));
rpcServer.stop();
}
}
private SpanData waitSpan(Matcher<SpanData> matcher) {
- Waiter.waitFor(CONF, 1000,
- new MatcherPredicate<>(() -> traceRule.getSpans(), hasItem(matcher)));
- return traceRule.getSpans().stream().filter(matcher::matches).findFirst()
+ Waiter.waitFor(CONF, 1000, new MatcherPredicate<>(() ->
OTEL_EXT.getSpans(), hasItem(matcher)));
+ return OTEL_EXT.getSpans().stream().filter(matcher::matches).findFirst()
.orElseThrow(AssertionError::new);
}
@@ -555,7 +559,7 @@ public abstract class AbstractTestIPC {
assertEquals(SpanKind.SERVER, data.getKind());
}
- @Test
+ @TestTemplate
public void testTracingSuccessIpc() throws IOException, ServiceException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -576,17 +580,17 @@ public abstract class AbstractTestIPC {
assertThat(pauseServerSpan,
buildIpcServerSpanAttributesMatcher("hbase.test.pb.TestProtobufRpcProto",
"pause"));
assertRemoteSpan();
- assertFalse("no spans provided", traceRule.getSpans().isEmpty());
- assertThat(traceRule.getSpans(),
+ assertFalse(OTEL_EXT.getSpans().isEmpty(), "no spans provided");
+ assertThat(OTEL_EXT.getSpans(),
everyItem(allOf(hasStatusWithCode(StatusCode.OK),
- hasTraceId(traceRule.getSpans().iterator().next().getTraceId()),
+ hasTraceId(OTEL_EXT.getSpans().iterator().next().getTraceId()),
hasDuration(greaterThanOrEqualTo(Duration.ofMillis(100L))))));
} finally {
rpcServer.stop();
}
}
- @Test
+ @TestTemplate
public void testTracingErrorIpc() throws IOException {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
@@ -608,9 +612,9 @@ public abstract class AbstractTestIPC {
assertThat(errorServerSpan,
buildIpcServerSpanAttributesMatcher("hbase.test.pb.TestProtobufRpcProto",
"error"));
assertRemoteSpan();
- assertFalse("no spans provided", traceRule.getSpans().isEmpty());
- assertThat(traceRule.getSpans(),
everyItem(allOf(hasStatusWithCode(StatusCode.ERROR),
- hasTraceId(traceRule.getSpans().iterator().next().getTraceId()))));
+ assertFalse(OTEL_EXT.getSpans().isEmpty(), "no spans provided");
+ assertThat(OTEL_EXT.getSpans(),
everyItem(allOf(hasStatusWithCode(StatusCode.ERROR),
+ hasTraceId(OTEL_EXT.getSpans().iterator().next().getTraceId()))));
} finally {
rpcServer.stop();
}
@@ -624,7 +628,7 @@ public abstract class AbstractTestIPC {
return ProtobufUtil.handleRemoteException(se);
}
- @Test
+ @TestTemplate
public void testBadPreambleHeader() throws Exception {
Configuration clientConf = new Configuration(CONF);
RpcServer rpcServer = createRpcServer("testRpcServer",
Collections.emptyList(),
@@ -643,7 +647,7 @@ public abstract class AbstractTestIPC {
}
Thread.sleep(100);
}
- assertNotNull("Can not get expected BadAuthException", error);
+ assertNotNull(error, "Can not get expected BadAuthException");
assertThat(error.getMessage(), containsString("authName=unknown"));
} finally {
rpcServer.stop();
@@ -654,7 +658,7 @@ public abstract class AbstractTestIPC {
* Testcase for getting connection registry information through connection
preamble header, see
* HBASE-25051 for more details.
*/
- @Test
+ @TestTemplate
public void testGetConnectionRegistry() throws IOException, ServiceException
{
Configuration clientConf = new Configuration(CONF);
String clusterId = "test_cluster_id";
@@ -684,7 +688,7 @@ public abstract class AbstractTestIPC {
* preamble header, i.e, a new client connecting to an old server. We
simulate this by using a
* Server without implementing the ConnectionRegistryEndpoint interface.
*/
- @Test
+ @TestTemplate
public void testGetConnectionRegistryError() throws IOException,
ServiceException {
Configuration clientConf = new Configuration(CONF);
// do not need any services
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestBlockingIPC.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestBlockingIPC.java
index 24177f28c40..ddac8f74b05 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestBlockingIPC.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestBlockingIPC.java
@@ -18,31 +18,26 @@
package org.apache.hadoop.hbase.ipc;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.codec.Codec;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RPCTests;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.params.provider.Arguments;
-@RunWith(Parameterized.class)
-@Category({ RPCTests.class, MediumTests.class })
+@Tag(RPCTests.TAG)
+@Tag(MediumTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: rpcServerImpl={0}")
public class TestBlockingIPC extends AbstractTestIPC {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlockingIPC.class);
+ public TestBlockingIPC(Class<? extends RpcServer> rpcServerImpl) {
+ super(rpcServerImpl);
+ }
- @Parameters(name = "{index}: rpcServerImpl={0}")
- public static List<Object[]> data() {
- return Arrays.asList(new Object[] { SimpleRpcServer.class },
- new Object[] { NettyRpcServer.class });
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of(SimpleRpcServer.class),
Arguments.of(NettyRpcServer.class));
}
@Override
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyIPC.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyIPC.java
index f2366a20fd2..fb415f8d249 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyIPC.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyIPC.java
@@ -20,34 +20,28 @@ package org.apache.hadoop.hbase.ipc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.codec.Codec;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RPCTests;
import org.apache.hadoop.hbase.util.JVM;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameter;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.params.provider.Arguments;
import org.apache.hbase.thirdparty.io.netty.channel.epoll.EpollEventLoopGroup;
import org.apache.hbase.thirdparty.io.netty.channel.epoll.EpollSocketChannel;
import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup;
import
org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioSocketChannel;
-@RunWith(Parameterized.class)
-@Category({ RPCTests.class, MediumTests.class })
+@Tag(RPCTests.TAG)
+@Tag(MediumTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: rpcServerImpl={0},
EventLoop={1}")
public class TestNettyIPC extends AbstractTestIPC {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestNettyIPC.class);
-
private static List<String> getEventLoopTypes() {
List<String> types = new ArrayList<>();
types.add("nio");
@@ -58,24 +52,27 @@ public class TestNettyIPC extends AbstractTestIPC {
return types;
}
- @Parameters(name = "{index}: rpcServerImpl={0}, EventLoop={1}")
- public static List<Object[]> parameters() {
- List<Object[]> params = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (String eventLoopType : getEventLoopTypes()) {
- params.add(new Object[] { SimpleRpcServer.class, eventLoopType });
- params.add(new Object[] { NettyRpcServer.class, eventLoopType });
+ params.add(Arguments.of(SimpleRpcServer.class, eventLoopType));
+ params.add(Arguments.of(NettyRpcServer.class, eventLoopType));
}
- return params;
+ return params.stream();
}
- @Parameter(1)
- public String eventLoopType;
+ private String eventLoopType;
+
+ public TestNettyIPC(Class<? extends RpcServer> rpcServerImpl, String
eventLoopType) {
+ super(rpcServerImpl);
+ this.eventLoopType = eventLoopType;
+ }
private static NioEventLoopGroup NIO;
private static EpollEventLoopGroup EPOLL;
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
NIO = new NioEventLoopGroup();
if (JVM.isLinux() && JVM.isAmd64()) {
@@ -83,7 +80,7 @@ public class TestNettyIPC extends AbstractTestIPC {
}
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
if (NIO != null) {
NIO.shutdownGracefully();
diff --git
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyTlsIPC.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyTlsIPC.java
index fac615456da..04e290e380e 100644
---
a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyTlsIPC.java
+++
b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyTlsIPC.java
@@ -26,10 +26,11 @@ import java.net.InetSocketAddress;
import java.security.Security;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.Server;
import org.apache.hadoop.hbase.codec.Codec;
import org.apache.hadoop.hbase.io.crypto.tls.KeyStoreFileType;
@@ -44,71 +45,70 @@ import org.apache.hadoop.hbase.testclassification.RPCTests;
import org.apache.hadoop.hbase.util.NettyEventLoopGroupConfig;
import org.apache.hadoop.hbase.wal.NettyAsyncFSWALConfigHelper;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-@Category({ RPCTests.class, MediumTests.class })
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.params.provider.Arguments;
+
+@Tag(RPCTests.TAG)
+@Tag(MediumTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: rpcServerImpl={0},
caKeyType={1},"
+ + " certKeyType={2}, keyPassword={3}, acceptPlainText={4},
clientTlsEnabled={5}")
public class TestNettyTlsIPC extends AbstractTestIPC {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestNettyTlsIPC.class);
-
private static final HBaseCommonTestingUtility UTIL = new
HBaseCommonTestingUtility(CONF);
private static X509TestContextProvider PROVIDER;
private static NettyEventLoopGroupConfig EVENT_LOOP_GROUP_CONFIG;
- @Parameterized.Parameter(1)
- public X509KeyType caKeyType;
+ private X509KeyType caKeyType;
+
+ private X509KeyType certKeyType;
- @Parameterized.Parameter(2)
- public X509KeyType certKeyType;
+ private char[] keyPassword;
- @Parameterized.Parameter(3)
- public char[] keyPassword;
+ private boolean acceptPlainText;
- @Parameterized.Parameter(4)
- public boolean acceptPlainText;
+ private boolean clientTlsEnabled;
- @Parameterized.Parameter(5)
- public boolean clientTlsEnabled;
+ public TestNettyTlsIPC(Class<? extends RpcServer> rpcServerImpl, X509KeyType
caKeyType,
+ X509KeyType certKeyType, char[] keyPassword, boolean acceptPlainText,
+ boolean clientTlsEnabled) {
+ super(rpcServerImpl);
+ this.caKeyType = caKeyType;
+ this.certKeyType = certKeyType;
+ this.keyPassword = keyPassword;
+ this.acceptPlainText = acceptPlainText;
+ this.clientTlsEnabled = clientTlsEnabled;
+ }
private X509TestContext x509TestContext;
// only netty rpc server supports TLS, so here we will only test
NettyRpcServer
- @Parameterized.Parameters(
- name = "{index}: rpcServerImpl={0}, caKeyType={1}, certKeyType={2},
keyPassword={3},"
- + " acceptPlainText={4}, clientTlsEnabled={5}")
- public static List<Object[]> data() {
- List<Object[]> params = new ArrayList<>();
+ public static Stream<Arguments> parameters() {
+ List<Arguments> params = new ArrayList<>();
for (X509KeyType caKeyType : X509KeyType.values()) {
for (X509KeyType certKeyType : X509KeyType.values()) {
for (char[] keyPassword : new char[][] { "".toCharArray(),
"pa$$w0rd".toCharArray() }) {
// do not accept plain text
- params.add(new Object[] { NettyRpcServer.class, caKeyType,
certKeyType, keyPassword,
- false, true });
+ params.add(
+ Arguments.of(NettyRpcServer.class, caKeyType, certKeyType,
keyPassword, false, true));
// support plain text and client enables tls
params.add(
- new Object[] { NettyRpcServer.class, caKeyType, certKeyType,
keyPassword, true, true });
+ Arguments.of(NettyRpcServer.class, caKeyType, certKeyType,
keyPassword, true, true));
// support plain text and client disables tls
- params.add(new Object[] { NettyRpcServer.class, caKeyType,
certKeyType, keyPassword, true,
- false });
+ params.add(
+ Arguments.of(NettyRpcServer.class, caKeyType, certKeyType,
keyPassword, true, false));
}
}
}
- return params;
+ return params.stream();
}
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws IOException {
Security.addProvider(new BouncyCastleProvider());
File dir = new
File(UTIL.getDataTestDir(TestNettyTlsIPC.class.getSimpleName()).toString())
@@ -125,14 +125,14 @@ public class TestNettyTlsIPC extends AbstractTestIPC {
EVENT_LOOP_GROUP_CONFIG.clientChannelClass());
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws InterruptedException {
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
EVENT_LOOP_GROUP_CONFIG.group().shutdownGracefully().sync();
UTIL.cleanupTestDir();
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
x509TestContext = PROVIDER.get(caKeyType, certKeyType, keyPassword);
x509TestContext.setConfigurations(KeyStoreFileType.JKS,
KeyStoreFileType.JKS);
@@ -140,7 +140,7 @@ public class TestNettyTlsIPC extends AbstractTestIPC {
CONF.setBoolean(X509Util.HBASE_CLIENT_NETTY_TLS_ENABLED, clientTlsEnabled);
}
- @After
+ @AfterEach
public void tearDown() {
x509TestContext.clearConfigurations();
x509TestContext.getConf().unset(X509Util.TLS_CONFIG_OCSP);