diff --git a/pom.xml b/pom.xml index 425e2d54b2..c48cabb3ce 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,8 @@ 0.7.0 3.1.0 5.14.2 + 5.21.0 + 5.2.0 UTF-8 @@ -146,6 +148,24 @@ runtime test + + org.mockito + mockito-core + ${mockito-core.version} + test + + + org.mockito + mockito-junit-jupiter + ${mockito-core.version} + test + + + org.mockito + mockito-inline + ${mockito-inline.version} + test + diff --git a/trpc-dependencies/trpc-dependencies-bom/pom.xml b/trpc-dependencies/trpc-dependencies-bom/pom.xml index e839e92219..a3e7e2798a 100644 --- a/trpc-dependencies/trpc-dependencies-bom/pom.xml +++ b/trpc-dependencies/trpc-dependencies-bom/pom.xml @@ -83,9 +83,9 @@ 2.8.9 32.1.3-jre 4.5.14 - 5.4.1 + 5.3.1 4.4.15 - 5.2.1 + 5.2.5 5.8.28 2.15.0-rc2 6.0.0 diff --git a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/ExecutorDispatcherTest.java b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/ExecutorDispatcherTest.java index 2814e45454..fd34bad172 100644 --- a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/ExecutorDispatcherTest.java +++ b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/ExecutorDispatcherTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -17,17 +17,17 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.junit.Test; -import org.powermock.api.mockito.PowerMockito; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; public class ExecutorDispatcherTest { @Test public void test() throws ServletException, IOException { ExecutorDispatcher dispatcher = new ExecutorDispatcher(); - HttpServletRequest req = PowerMockito.mock(HttpServletRequest.class); - PowerMockito.when(req.getLocalPort()).thenReturn(1024); - HttpServletResponse rsp = PowerMockito.mock(HttpServletResponse.class); + HttpServletRequest req = Mockito.mock(HttpServletRequest.class); + Mockito.when(req.getLocalPort()).thenReturn(1024); + HttpServletResponse rsp = Mockito.mock(HttpServletResponse.class); dispatcher.service(req, rsp); org.mockito.Mockito.verify(rsp, times(1)).sendError(404, "HttpExecutor is closed: port is:1024."); diff --git a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2ServerTest.java b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2ServerTest.java index e10d6d906b..cb47a9ae71 100644 --- a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2ServerTest.java +++ b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2ServerTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -14,7 +14,7 @@ import static com.tencent.trpc.transport.http.common.Constants.HTTP2_SCHEME; import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PASS; import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PATH; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.extension.ExtensionLoader; @@ -43,10 +43,10 @@ import org.apache.hc.core5.http2.ssl.ConscryptClientTlsStrategy; import org.apache.hc.core5.ssl.SSLContexts; import org.eclipse.jetty.http.HttpStatus; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class JettyHttp2ServerTest { @@ -56,7 +56,7 @@ public class JettyHttp2ServerTest { private static CloseableHttpAsyncClient httpAsyncClient; - @BeforeClass + @BeforeAll public static void beforeClass() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException { ProtocolConfig protocolConfig = ProtocolConfig.newInstance(); @@ -109,7 +109,7 @@ public static void beforeClass() throws CertificateException, NoSuchAlgorithmExc httpAsyncClient.start(); } - @AfterClass + @AfterAll public static void afterClass() { if (httpServer != null) { httpServer.open(); @@ -146,14 +146,14 @@ public void cancelled() { } }); SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS); - Assert.assertNotEquals(null, simpleHttpResponse); + Assertions.assertNotEquals(null, simpleHttpResponse); logger.error(simpleHttpResponse.getBodyText()); - Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); - Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); + Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); + Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); logger.info("response code is {}", simpleHttpResponse.getCode()); - Assert.assertEquals(200, simpleHttpResponse.getCode()); + Assertions.assertEquals(200, simpleHttpResponse.getCode()); logger.info("http response is: {}", simpleHttpResponse.getBodyText()); - Assert.assertEquals("", simpleHttpResponse.getBodyText()); + Assertions.assertEquals("", simpleHttpResponse.getBodyText()); } @Test @@ -178,14 +178,14 @@ public void cancelled() { } }); SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS); - Assert.assertNotEquals(null, simpleHttpResponse); + Assertions.assertNotEquals(null, simpleHttpResponse); logger.error(simpleHttpResponse.getBodyText()); - Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); - Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); + Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); + Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); logger.info("response code is {}", simpleHttpResponse.getCode()); - Assert.assertEquals(404, simpleHttpResponse.getCode()); + Assertions.assertEquals(404, simpleHttpResponse.getCode()); logger.info("http response is: {}", simpleHttpResponse.getBodyText()); - Assert.assertEquals("", simpleHttpResponse.getBodyText()); + Assertions.assertEquals("", simpleHttpResponse.getBodyText()); } } diff --git a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2cServerTest.java b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2cServerTest.java index 99229f4345..38a8e7a2d9 100644 --- a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2cServerTest.java +++ b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttp2cServerTest.java @@ -12,7 +12,7 @@ package com.tencent.trpc.transport.http; import static com.tencent.trpc.transport.http.common.Constants.HTTP2_SCHEME; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.extension.ExtensionLoader; @@ -34,10 +34,10 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.eclipse.jetty.http.HttpStatus; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class JettyHttp2cServerTest { @@ -49,7 +49,7 @@ public class JettyHttp2cServerTest { private static CloseableHttpClient httpClient; - @BeforeClass + @BeforeAll public static void beforeClass() { ProtocolConfig protocolConfig = ProtocolConfig.newInstance(); protocolConfig.setIp("localhost"); @@ -88,7 +88,7 @@ public static void beforeClass() { httpClient = HttpClients.custom().build(); } - @AfterClass + @AfterAll public static void afterClass() { if (httpServer != null) { httpServer.open(); @@ -125,14 +125,14 @@ public void cancelled() { } }); SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS); - Assert.assertNotEquals(null, simpleHttpResponse); + Assertions.assertNotEquals(null, simpleHttpResponse); logger.error(simpleHttpResponse.getBodyText()); - Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); - Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); + Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); + Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); logger.info("response code is {}", simpleHttpResponse.getCode()); - Assert.assertEquals(200, simpleHttpResponse.getCode()); + Assertions.assertEquals(200, simpleHttpResponse.getCode()); logger.info("http response is: {}", simpleHttpResponse.getBodyText()); - Assert.assertEquals("", simpleHttpResponse.getBodyText()); + Assertions.assertEquals("", simpleHttpResponse.getBodyText()); } @Test @@ -157,14 +157,14 @@ public void cancelled() { } }); SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS); - Assert.assertNotEquals(null, simpleHttpResponse); + Assertions.assertNotEquals(null, simpleHttpResponse); logger.error(simpleHttpResponse.getBodyText()); - Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); - Assert.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); + Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); + Assertions.assertEquals(2, simpleHttpResponse.getVersion().getMajor()); logger.info("response code is {}", simpleHttpResponse.getCode()); - Assert.assertEquals(404, simpleHttpResponse.getCode()); + Assertions.assertEquals(404, simpleHttpResponse.getCode()); logger.info("http response is: {}", simpleHttpResponse.getBodyText()); - Assert.assertEquals("", simpleHttpResponse.getBodyText()); + Assertions.assertEquals("", simpleHttpResponse.getBodyText()); } @Test @@ -175,10 +175,10 @@ public void testNormalRequestWithHttp() throws Exception { int responseCode = httpResponse.getStatusLine().getStatusCode(); logger.info("response code is {}", responseCode); - Assert.assertEquals(responseCode, 200); + Assertions.assertEquals(responseCode, 200); - Assert.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP"); - Assert.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1); + Assertions.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP"); + Assertions.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1); } @@ -190,10 +190,10 @@ public void testNotExistRequestWithHttp1() throws Exception { int responseCode = httpResponse.getStatusLine().getStatusCode(); logger.info("response code is {}", responseCode); - Assert.assertEquals(responseCode, 404); + Assertions.assertEquals(responseCode, 404); - Assert.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP"); - Assert.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1); + Assertions.assertEquals(httpResponse.getProtocolVersion().getProtocol(), "HTTP"); + Assertions.assertEquals(httpResponse.getProtocolVersion().getMajor(), 1); } diff --git a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttpsServerTest.java b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttpsServerTest.java index db7cfe19b7..5e82f1cdb8 100644 --- a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttpsServerTest.java +++ b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyHttpsServerTest.java @@ -1,7 +1,7 @@ /* * Tencent is pleased to support the open source community by making tRPC available. * - * Copyright (C) 2023 THL A29 Limited, a Tencent company. + * Copyright (C) 2023 THL A29 Limited, a Tencent company. * All rights reserved. * * If you have downloaded a copy of the tRPC source code from Tencent, @@ -14,7 +14,7 @@ import static com.tencent.trpc.transport.http.common.Constants.HTTP_SCHEME; import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PASS; import static com.tencent.trpc.transport.http.common.Constants.KEYSTORE_PATH; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.extension.ExtensionLoader; @@ -40,13 +40,15 @@ import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder; import org.apache.hc.core5.concurrent.FutureCallback; import org.apache.hc.core5.http2.HttpVersionPolicy; -import org.apache.hc.core5.http2.ssl.ConscryptClientTlsStrategy; +import org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder; +import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; import org.apache.hc.core5.ssl.SSLContexts; +import org.apache.hc.core5.ssl.TrustStrategy; import org.eclipse.jetty.http.HttpStatus; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class JettyHttpsServerTest { @@ -56,7 +58,7 @@ public class JettyHttpsServerTest { private static CloseableHttpAsyncClient httpAsyncClient; - @BeforeClass + @BeforeAll public static void beforeClass() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException { ProtocolConfig protocolConfig = ProtocolConfig.newInstance(); @@ -97,11 +99,15 @@ public static void beforeClass() throws CertificateException, NoSuchAlgorithmExc String keyStorePath = String.valueOf(path); String keyStorePass = "init234"; final SSLContext sslContext = SSLContexts.custom() - .loadTrustMaterial(new File(keyStorePath), keyStorePass.toCharArray()) + .loadTrustMaterial(new File(keyStorePath), keyStorePass.toCharArray(), + (TrustStrategy) (chain, authType) -> true) .build(); final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder - .create().useSystemProperties() - .setTlsStrategy(new ConscryptClientTlsStrategy(sslContext)) + .create() + .setTlsStrategy(ClientTlsStrategyBuilder.create() + .setSslContext(sslContext) + .setHostnameVerifier(NoopHostnameVerifier.INSTANCE) + .build()) .build(); httpAsyncClient = HttpAsyncClients.custom() .setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1).setConnectionManager(cm) @@ -109,7 +115,7 @@ public static void beforeClass() throws CertificateException, NoSuchAlgorithmExc httpAsyncClient.start(); } - @AfterClass + @AfterAll public static void afterClass() { if (httpServer != null) { httpServer.open(); @@ -146,14 +152,14 @@ public void cancelled() { } }); SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS); - Assert.assertNotEquals(null, simpleHttpResponse); + Assertions.assertNotEquals(null, simpleHttpResponse); logger.error(simpleHttpResponse.getBodyText()); - Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); - Assert.assertEquals(1, simpleHttpResponse.getVersion().getMajor()); + Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); + Assertions.assertEquals(1, simpleHttpResponse.getVersion().getMajor()); logger.info("response code is {}", simpleHttpResponse.getCode()); - Assert.assertEquals(200, simpleHttpResponse.getCode()); + Assertions.assertEquals(200, simpleHttpResponse.getCode()); logger.info("http response is: {}", simpleHttpResponse.getBodyText()); - Assert.assertEquals("", simpleHttpResponse.getBodyText()); + Assertions.assertEquals("", simpleHttpResponse.getBodyText()); } @Test @@ -178,14 +184,14 @@ public void cancelled() { } }); SimpleHttpResponse simpleHttpResponse = httpResponseFuture.get(2000, TimeUnit.MILLISECONDS); - Assert.assertNotEquals(null, simpleHttpResponse); + Assertions.assertNotEquals(null, simpleHttpResponse); logger.error(simpleHttpResponse.getBodyText()); - Assert.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); - Assert.assertEquals(1, simpleHttpResponse.getVersion().getMajor()); + Assertions.assertEquals("HTTP", simpleHttpResponse.getVersion().getProtocol()); + Assertions.assertEquals(1, simpleHttpResponse.getVersion().getMajor()); logger.info("response code is {}", simpleHttpResponse.getCode()); - Assert.assertEquals(404, simpleHttpResponse.getCode()); + Assertions.assertEquals(404, simpleHttpResponse.getCode()); logger.info("http response is: {}", simpleHttpResponse.getBodyText()); - Assert.assertEquals("", simpleHttpResponse.getBodyText()); + Assertions.assertEquals("", simpleHttpResponse.getBodyText()); } } diff --git a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyServerTest.java b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyServerTest.java index 154604656e..3cd1140641 100644 --- a/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyServerTest.java +++ b/trpc-transport/trpc-transport-http/src/test/java/com/tencent/trpc/transport/http/JettyServerTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.transport.http; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.extension.ExtensionLoader; @@ -22,10 +22,10 @@ import java.net.HttpURLConnection; import java.net.URL; import org.eclipse.jetty.http.HttpStatus; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class JettyServerTest { @@ -33,7 +33,7 @@ public class JettyServerTest { private static HttpServer httpServer; - @BeforeClass + @BeforeAll public static void beforeClass() { ProtocolConfig protocolConfig = ProtocolConfig.newInstance(); protocolConfig.setIp("localhost"); @@ -65,7 +65,7 @@ public static void beforeClass() { JettyServerTest.httpServer = httpServer; } - @AfterClass + @AfterAll public static void afterClass() { if (httpServer != null) { httpServer.open(); @@ -90,7 +90,7 @@ public void testNormalRequest() throws Exception { int responseCode = connection.getResponseCode(); logger.info("response code is {}", responseCode); - Assert.assertEquals(responseCode, 200); + Assertions.assertEquals(responseCode, 200); } finally { if (connection != null) { connection.disconnect(); @@ -114,7 +114,7 @@ public void testNotExistRequest() throws Exception { int responseCode = connection.getResponseCode(); logger.info("response code is {}", responseCode); - Assert.assertEquals(responseCode, 404); + Assertions.assertEquals(responseCode, 404); } finally { if (connection != null) { connection.disconnect(); diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/AbstractBatchDecoderTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/AbstractBatchDecoderTest.java index e97c8302d8..169dc60069 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/AbstractBatchDecoderTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/AbstractBatchDecoderTest.java @@ -18,8 +18,8 @@ import io.netty.buffer.EmptyByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.List; @@ -34,7 +34,7 @@ public class AbstractBatchDecoderTest { public void setSingleDecode() { DecoderTest decoderTest = new DecoderTest(); decoderTest.setSingleDecode(true); - Assert.assertTrue(decoderTest.isSingleDecode()); + Assertions.assertTrue(decoderTest.isSingleDecode()); } @Test @@ -70,7 +70,7 @@ public void internalBuffer() { DecoderTest decoderTest = new DecoderTest(); decoderTest.setCumulator(AbstractBatchDecoder.COMPOSITE_CUMULATOR); ByteBuf byteBuf = decoderTest.internalBuffer(); - Assert.assertEquals(Unpooled.EMPTY_BUFFER, byteBuf); + Assertions.assertEquals(Unpooled.EMPTY_BUFFER, byteBuf); } @Test @@ -124,4 +124,4 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) t } } -} \ No newline at end of file +} diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/ChannelBufferTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/ChannelBufferTest.java index 586a4ee9f6..0a2ee0a64e 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/ChannelBufferTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/ChannelBufferTest.java @@ -20,8 +20,8 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class ChannelBufferTest { @@ -38,190 +38,190 @@ public void test() { ChannelBuffer copy = channelBuffer.copy(); copy.capacity(1000); - Assert.assertTrue("capacity = 1000", copy.capacity() == 1000); - Assert.assertTrue(copy.maxCapacity() != 0); - Assert.assertTrue(copy.isDirect()); + Assertions.assertTrue(copy.capacity() == 1000, "capacity = 1000"); + Assertions.assertTrue(copy.maxCapacity() != 0); + Assertions.assertTrue(copy.isDirect()); copy.clear(); copy.writeByte(1); - Assert.assertTrue(copy.isReadable()); + Assertions.assertTrue(copy.isReadable()); copy.readByte(); - Assert.assertTrue(!copy.isReadOnly()); - Assert.assertTrue(copy.asReadOnly().isReadOnly()); + Assertions.assertTrue(!copy.isReadOnly()); + Assertions.assertTrue(copy.asReadOnly().isReadOnly()); copy.clear(); copy.writeCharSequence("abcdefg", Charset.defaultCharset()); - Assert.assertTrue(copy.readerIndex() == 0); - Assert.assertTrue(copy.writerIndex() == "abcdefg".length()); + Assertions.assertTrue(copy.readerIndex() == 0); + Assertions.assertTrue(copy.writerIndex() == "abcdefg".length()); copy.readerIndex(3); copy.writerIndex(3); - Assert.assertTrue(copy.readerIndex() == 3); - Assert.assertTrue(copy.writerIndex() == 3); + Assertions.assertTrue(copy.readerIndex() == 3); + Assertions.assertTrue(copy.writerIndex() == 3); copy.setIndex(4, 4); - Assert.assertTrue(copy.readerIndex() == 4); - Assert.assertTrue(copy.writerIndex() == 4); + Assertions.assertTrue(copy.readerIndex() == 4); + Assertions.assertTrue(copy.writerIndex() == 4); // copy.clear(); copy.writeCharSequence("abcd", Charset.defaultCharset()); - Assert.assertTrue(copy.readableBytes() == 4); - Assert.assertTrue(copy.writableBytes() == copy.capacity() - "abcd".length()); - Assert.assertTrue(copy.maxWritableBytes() == copy.maxCapacity() - "abcd".length()); - Assert.assertTrue(copy.isReadable()); - Assert.assertTrue(!copy.isReadable(5)); - Assert.assertTrue(copy.isReadable(3)); - Assert.assertTrue(copy.isWritable()); - Assert.assertTrue(copy.isWritable(3)); - Assert.assertTrue(!copy.isWritable(Integer.MAX_VALUE)); + Assertions.assertTrue(copy.readableBytes() == 4); + Assertions.assertTrue(copy.writableBytes() == copy.capacity() - "abcd".length()); + Assertions.assertTrue(copy.maxWritableBytes() == copy.maxCapacity() - "abcd".length()); + Assertions.assertTrue(copy.isReadable()); + Assertions.assertTrue(!copy.isReadable(5)); + Assertions.assertTrue(copy.isReadable(3)); + Assertions.assertTrue(copy.isWritable()); + Assertions.assertTrue(copy.isWritable(3)); + Assertions.assertTrue(!copy.isWritable(Integer.MAX_VALUE)); // copy.clear(); copy.writeCharSequence("abcd", Charset.defaultCharset()); copy.markReaderIndex(); copy.readByte(); - Assert.assertTrue(copy.readerIndex() == 1); + Assertions.assertTrue(copy.readerIndex() == 1); copy.resetReaderIndex(); - Assert.assertTrue(copy.readerIndex() == 0); + Assertions.assertTrue(copy.readerIndex() == 0); copy.markWriterIndex(); copy.writeBoolean(false); - Assert.assertTrue(copy.writerIndex() == "abcd".length() + 1); + Assertions.assertTrue(copy.writerIndex() == "abcd".length() + 1); copy.resetWriterIndex(); - Assert.assertTrue(copy.writerIndex() == "abcd".length()); + Assertions.assertTrue(copy.writerIndex() == "abcd".length()); // copy.clear(); copy.writeCharSequence("abcd", Charset.defaultCharset()); copy.readByte(); - Assert.assertTrue(copy.readerIndex() == 1); + Assertions.assertTrue(copy.readerIndex() == 1); copy.discardReadBytes(); - Assert.assertTrue(copy.readerIndex() == 0); + Assertions.assertTrue(copy.readerIndex() == 0); copy.clear(); copy.capacity(10); copy.writeCharSequence("abcd", Charset.defaultCharset()); copy.ensureWritable(10); - Assert.assertTrue(copy.capacity() + "", copy.capacity() > 14); + Assertions.assertTrue(copy.capacity() > 14, copy.capacity() + ""); copy.clear(); copy.writeByte(1); copy.writeBoolean(true); - Assert.assertTrue(copy.getBoolean(1)); - Assert.assertTrue(copy.readBoolean()); + Assertions.assertTrue(copy.getBoolean(1)); + Assertions.assertTrue(copy.readBoolean()); copy.setBoolean(1, false); - Assert.assertTrue(!copy.getBoolean(1)); + Assertions.assertTrue(!copy.getBoolean(1)); copy.clear(); copy.writeByte(1); copy.writeByte(2); - Assert.assertTrue(copy.getByte(1) == 2); - Assert.assertTrue(copy.readByte() == 1); + Assertions.assertTrue(copy.getByte(1) == 2); + Assertions.assertTrue(copy.readByte() == 1); copy.setByte(1, 3); - Assert.assertTrue(copy.getByte(1) == 3); + Assertions.assertTrue(copy.getByte(1) == 3); copy.clear(); copy.writeByte(1); copy.writeByte(254); - Assert.assertTrue(copy.getUnsignedByte(1) == 254); - Assert.assertTrue(copy.readUnsignedByte() == 1); + Assertions.assertTrue(copy.getUnsignedByte(1) == 254); + Assertions.assertTrue(copy.readUnsignedByte() == 1); copy.clear(); copy.writeByte(1); copy.writeShort(11); - Assert.assertTrue(copy.getShort(1) == 11); + Assertions.assertTrue(copy.getShort(1) == 11); copy.readByte(); - Assert.assertTrue(copy.readShort() == 11); + Assertions.assertTrue(copy.readShort() == 11); copy.setShort(0, 22); - Assert.assertTrue(copy.getShort(0) == 22); + Assertions.assertTrue(copy.getShort(0) == 22); copy.clear(); copy.writeShortLE(11); - Assert.assertTrue(copy.getShortLE(0) + "", copy.getShortLE(0) == 11); - Assert.assertTrue(copy.getShort(0) != 11); - Assert.assertTrue(copy.readShortLE() == 11); + Assertions.assertTrue(copy.getShortLE(0) == 11, copy.getShortLE(0) + ""); + Assertions.assertTrue(copy.getShort(0) != 11); + Assertions.assertTrue(copy.readShortLE() == 11); copy.setShortLE(0, 22); - Assert.assertTrue(copy.getShortLE(0) == 22); + Assertions.assertTrue(copy.getShortLE(0) == 22); copy.clear(); copy.writeShort(Short.MAX_VALUE); - Assert.assertTrue(copy.getUnsignedShort(0) == Short.MAX_VALUE); - Assert.assertTrue(copy.readUnsignedShort() == Short.MAX_VALUE); + Assertions.assertTrue(copy.getUnsignedShort(0) == Short.MAX_VALUE); + Assertions.assertTrue(copy.readUnsignedShort() == Short.MAX_VALUE); copy.setShort(0, Short.MAX_VALUE - 1); - Assert.assertTrue(copy.getUnsignedShort(0) == Short.MAX_VALUE - 1); + Assertions.assertTrue(copy.getUnsignedShort(0) == Short.MAX_VALUE - 1); copy.clear(); copy.writeShortLE(Short.MAX_VALUE); - Assert.assertTrue(copy.getUnsignedShortLE(0) == Short.MAX_VALUE); - Assert.assertTrue(copy.readUnsignedShortLE() == Short.MAX_VALUE); + Assertions.assertTrue(copy.getUnsignedShortLE(0) == Short.MAX_VALUE); + Assertions.assertTrue(copy.readUnsignedShortLE() == Short.MAX_VALUE); copy.setShortLE(0, Short.MAX_VALUE - 1); - Assert.assertTrue(copy.getUnsignedShortLE(0) == Short.MAX_VALUE - 1); + Assertions.assertTrue(copy.getUnsignedShortLE(0) == Short.MAX_VALUE - 1); copy.clear(); copy.writeInt(Integer.MAX_VALUE); - Assert.assertTrue(copy.getInt(0) == Integer.MAX_VALUE); - Assert.assertTrue(copy.readInt() == Integer.MAX_VALUE); + Assertions.assertTrue(copy.getInt(0) == Integer.MAX_VALUE); + Assertions.assertTrue(copy.readInt() == Integer.MAX_VALUE); copy.setInt(0, Integer.MAX_VALUE - 1); - Assert.assertTrue(copy.getInt(0) == Integer.MAX_VALUE - 1); + Assertions.assertTrue(copy.getInt(0) == Integer.MAX_VALUE - 1); copy.clear(); copy.writeIntLE(Integer.MAX_VALUE); - Assert.assertTrue(copy.getIntLE(0) == Integer.MAX_VALUE); - Assert.assertTrue(copy.readIntLE() == Integer.MAX_VALUE); + Assertions.assertTrue(copy.getIntLE(0) == Integer.MAX_VALUE); + Assertions.assertTrue(copy.readIntLE() == Integer.MAX_VALUE); copy.setIntLE(0, Integer.MAX_VALUE - 1); - Assert.assertTrue(copy.getIntLE(0) == Integer.MAX_VALUE - 1); + Assertions.assertTrue(copy.getIntLE(0) == Integer.MAX_VALUE - 1); copy.clear(); copy.writeInt(Integer.MAX_VALUE); - Assert.assertTrue(copy.getUnsignedInt(0) == Integer.MAX_VALUE); - Assert.assertTrue(copy.readUnsignedInt() == Integer.MAX_VALUE); + Assertions.assertTrue(copy.getUnsignedInt(0) == Integer.MAX_VALUE); + Assertions.assertTrue(copy.readUnsignedInt() == Integer.MAX_VALUE); copy.clear(); copy.writeIntLE(Integer.MAX_VALUE); - Assert.assertTrue(copy.getUnsignedIntLE(0) == Integer.MAX_VALUE); - Assert.assertTrue(copy.readUnsignedIntLE() == Integer.MAX_VALUE); + Assertions.assertTrue(copy.getUnsignedIntLE(0) == Integer.MAX_VALUE); + Assertions.assertTrue(copy.readUnsignedIntLE() == Integer.MAX_VALUE); copy.setIntLE(0, Integer.MAX_VALUE - 1); - Assert.assertTrue(copy.getUnsignedIntLE(0) == Integer.MAX_VALUE - 1); + Assertions.assertTrue(copy.getUnsignedIntLE(0) == Integer.MAX_VALUE - 1); copy.clear(); copy.writeLong(Long.MAX_VALUE); - Assert.assertTrue(copy.getLong(0) == Long.MAX_VALUE); - Assert.assertTrue(copy.readLong() == Long.MAX_VALUE); + Assertions.assertTrue(copy.getLong(0) == Long.MAX_VALUE); + Assertions.assertTrue(copy.readLong() == Long.MAX_VALUE); copy.setLong(0, Long.MAX_VALUE - 1); - Assert.assertTrue(copy.getLong(0) == Long.MAX_VALUE - 1); + Assertions.assertTrue(copy.getLong(0) == Long.MAX_VALUE - 1); copy.clear(); copy.writeLongLE(Long.MAX_VALUE); - Assert.assertTrue(copy.getLongLE(0) == Long.MAX_VALUE); - Assert.assertTrue(copy.readLongLE() == Long.MAX_VALUE); + Assertions.assertTrue(copy.getLongLE(0) == Long.MAX_VALUE); + Assertions.assertTrue(copy.readLongLE() == Long.MAX_VALUE); copy.setLongLE(0, Long.MAX_VALUE - 1); - Assert.assertTrue(copy.getLongLE(0) == Long.MAX_VALUE - 1); + Assertions.assertTrue(copy.getLongLE(0) == Long.MAX_VALUE - 1); copy.clear(); copy.writeChar('A'); - Assert.assertTrue(copy.getChar(0) == 'A'); - Assert.assertTrue(copy.readChar() == 'A'); + Assertions.assertTrue(copy.getChar(0) == 'A'); + Assertions.assertTrue(copy.readChar() == 'A'); copy.setChar(0, 'B'); - Assert.assertTrue(copy.getChar(0) == 'B'); + Assertions.assertTrue(copy.getChar(0) == 'B'); copy.clear(); copy.writeCharSequence("A", Charset.defaultCharset()); - Assert.assertTrue(copy.getCharSequence(0, 1, Charset.defaultCharset()) + "", - copy.getCharSequence(0, 1, Charset.defaultCharset()).equals("A")); - Assert.assertTrue(copy.readCharSequence(1, Charset.defaultCharset()).equals("A")); + Assertions.assertTrue(copy.getCharSequence(0, 1, Charset.defaultCharset()).equals("A"), + copy.getCharSequence(0, 1, Charset.defaultCharset()) + ""); + Assertions.assertTrue(copy.readCharSequence(1, Charset.defaultCharset()).equals("A")); copy.setCharSequence(0, "B", Charset.defaultCharset()); - Assert.assertTrue(copy.getCharSequence(0, 1, Charset.defaultCharset()).equals("B")); + Assertions.assertTrue(copy.getCharSequence(0, 1, Charset.defaultCharset()).equals("B")); copy.clear(); copy.writeFloat(Float.valueOf("1.0")); - Assert.assertTrue(String.valueOf(copy.getFloat(0)), - String.valueOf(copy.getFloat(0)).equals("1.0")); - Assert.assertTrue(String.valueOf(copy.readFloat()).equals("1.0")); + Assertions.assertTrue(String.valueOf(copy.getFloat(0)).equals("1.0"), + String.valueOf(copy.getFloat(0))); + Assertions.assertTrue(String.valueOf(copy.readFloat()).equals("1.0")); copy.setFloat(0, Float.valueOf("1.0")); - Assert.assertTrue(String.valueOf(copy.getFloat(0)).equals("1.0")); + Assertions.assertTrue(String.valueOf(copy.getFloat(0)).equals("1.0")); copy.clear(); copy.writeDouble(Float.valueOf("1.0")); - Assert.assertTrue(String.valueOf(copy.getDouble(0)), - String.valueOf(copy.getDouble(0)).equals("1.0")); - Assert.assertTrue(String.valueOf(copy.readDouble()).equals("1.0")); + Assertions.assertTrue(String.valueOf(copy.getDouble(0)).equals("1.0"), + String.valueOf(copy.getDouble(0))); + Assertions.assertTrue(String.valueOf(copy.readDouble()).equals("1.0")); copy.setDouble(0, Float.valueOf("1.0")); - Assert.assertTrue(String.valueOf(copy.getDouble(0)).equals("1.0")); + Assertions.assertTrue(String.valueOf(copy.getDouble(0)).equals("1.0")); copy.clear(); copy.capacity(1000); @@ -230,37 +230,37 @@ public void test() { copy.writeByte(1); ChannelBuffer copy3 = copy.copy(); copy.getBytes(0, copy2); - Assert.assertTrue(copy2.readByte() == 1); - Assert.assertTrue(copy3.capacity() == 1); - Assert.assertTrue(copy3.readerIndex() == 0); - Assert.assertTrue(copy3.writerIndex() == 1); - Assert.assertTrue(copy3.getByte(0) == 1); + Assertions.assertTrue(copy2.readByte() == 1); + Assertions.assertTrue(copy3.capacity() == 1); + Assertions.assertTrue(copy3.readerIndex() == 0); + Assertions.assertTrue(copy3.writerIndex() == 1); + Assertions.assertTrue(copy3.getByte(0) == 1); IndexOutOfBoundsException ex = null; try { copy.getBytes(0, copy2, Integer.MAX_VALUE); } catch (IndexOutOfBoundsException e) { ex = e; } - Assert.assertTrue(ex != null); + Assertions.assertTrue(ex != null); copy.clear(); copy.capacity(1000); copy.writeByte(1); byte[] b = new byte[99]; copy.getBytes(0, b); - Assert.assertTrue(b[0] == 1); + Assertions.assertTrue(b[0] == 1); copy.setByte(0, 2); copy.getBytes(0, b, 0, 1); - Assert.assertTrue(b[0] == 2); + Assertions.assertTrue(b[0] == 2); copy.setByte(0, 3); copy.getBytes(0, ByteBuffer.wrap(b)); - Assert.assertTrue(b[0] == 3); + Assertions.assertTrue(b[0] == 3); try { copy.setByte(0, 4); ByteArrayOutputStream out = new ByteArrayOutputStream(); copy.getBytes(0, out, 1); - Assert.assertTrue(out.toByteArray()[0] == 4); + Assertions.assertTrue(out.toByteArray()[0] == 4); } catch (IOException e) { LOGGER.error("error:", e); } @@ -276,19 +276,19 @@ public void test() { } catch (IndexOutOfBoundsException e) { ex = e; } - Assert.assertTrue(ex != null); - Assert.assertTrue(copy2.readerIndex() == 1); - Assert.assertTrue(copy.getByte(0) == 1); + Assertions.assertTrue(ex != null); + Assertions.assertTrue(copy2.readerIndex() == 1); + Assertions.assertTrue(copy.getByte(0) == 1); copy.clear(); b = new byte[]{1}; copy.setBytes(0, b); - Assert.assertTrue(copy.getByte(0) == 1); + Assertions.assertTrue(copy.getByte(0) == 1); copy.clear(); b = new byte[]{1}; copy.setBytes(0, ByteBuffer.wrap(b)); - Assert.assertTrue(copy.getByte(0) == 1); + Assertions.assertTrue(copy.getByte(0) == 1); copy.clear(); b = new byte[]{1}; @@ -297,7 +297,7 @@ public void test() { } catch (IOException e) { LOGGER.error("error:", e); } - Assert.assertTrue(copy.getByte(0) == 1); + Assertions.assertTrue(copy.getByte(0) == 1); copy.clear(); copy.capacity(100); @@ -306,17 +306,17 @@ public void test() { copy.setByte(0, 1); b = new byte[10]; copy.readBytes(b, 0, 1); - Assert.assertTrue(b[0] == 1); + Assertions.assertTrue(b[0] == 1); copy.setByte(0, 2); copy.readerIndex(0); copy.readBytes(ByteBuffer.wrap(b)); - Assert.assertTrue(b[0] + "", b[0] == 2); + Assertions.assertTrue(b[0] == 2, b[0] + ""); copy.setByte(0, 3); copy.readerIndex(0); copy.readBytes(ByteBuffer.wrap(b)); - Assert.assertTrue(b[0] == 3); + Assertions.assertTrue(b[0] == 3); copy.setByte(0, 4); copy.readerIndex(0); @@ -326,13 +326,13 @@ public void test() { } catch (IOException e) { LOGGER.error("error:", e); } - Assert.assertTrue(s.toByteArray()[0] == 4); + Assertions.assertTrue(s.toByteArray()[0] == 4); copy.clear(); copy.capacity(100); copy.writeCharSequence("abcd", Charset.defaultCharset()); copy.skipBytes(1); - Assert.assertTrue(copy.readCharSequence(1, Charset.defaultCharset()).equals("b")); + Assertions.assertTrue(copy.readCharSequence(1, Charset.defaultCharset()).equals("b")); ChannelBuffer copyC1 = channelBuffer.copy(); ChannelBuffer copyC2 = channelBuffer.copy(); @@ -341,22 +341,22 @@ public void test() { copyC2.capacity(1000); copyC2.writeByte(1); copyC2.toString(); - Assert.assertTrue(0 == copyC2.compareTo(copyC1)); + Assertions.assertTrue(0 == copyC2.compareTo(copyC1)); copy.clear(); copy.capacity(100); copy.writeByte(1); b = new byte[]{1}; copy.writeBytes(b, 0, 1); - Assert.assertTrue(copy.readByte() == 1); + Assertions.assertTrue(copy.readByte() == 1); copy.writeBytes(ByteBuffer.wrap(b)); - Assert.assertTrue(copy.readByte() == 1); + Assertions.assertTrue(copy.readByte() == 1); try { copy.writeBytes(new ByteArrayInputStream(b), 1); } catch (IOException e1) { LOGGER.error("error:", e1); } - Assert.assertTrue(copy.readByte() == 1); + Assertions.assertTrue(copy.readByte() == 1); copy.clear(); copy.capacity(100); @@ -364,15 +364,15 @@ public void test() { writeCopy.capacity(100); writeCopy.writeByte(1); copy.writeBytes(writeCopy); - Assert.assertTrue(copy.readerIndex() == 0); - Assert.assertTrue(copy.readableBytes() == 1); - Assert.assertTrue(copy.readByte() == 1); + Assertions.assertTrue(copy.readerIndex() == 0); + Assertions.assertTrue(copy.readableBytes() == 1); + Assertions.assertTrue(copy.readByte() == 1); try { copy.clear(); copy.capacity(100); copy.writeCharSequence("abcd", Charset.defaultCharset()); - Assert.assertTrue(copy.arrayOffset() == 0); + Assertions.assertTrue(copy.arrayOffset() == 0); } catch (Exception e) { LOGGER.error("error:", e); } @@ -383,8 +383,8 @@ public void test() { readCopy.capacity(1); copy.writeByte(1); copy.readBytes(readCopy); - Assert.assertTrue(readCopy.readerIndex() == 0); - Assert.assertTrue(readCopy.readableBytes() == 1); - Assert.assertTrue(readCopy.readByte() == 1); + Assertions.assertTrue(readCopy.readerIndex() == 0); + Assertions.assertTrue(readCopy.readableBytes() == 1); + Assertions.assertTrue(readCopy.readByte() == 1); } } diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelHandlerTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelHandlerTest.java index e9d8b4f41c..2eaa2f00cc 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelHandlerTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelHandlerTest.java @@ -14,8 +14,8 @@ import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.transport.handler.ChannelHandlerAdapter; import io.netty.handler.timeout.IdleStateEvent; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class NettyChannelHandlerTest { @@ -26,27 +26,27 @@ public void test() throws Exception { new NettyClientHandler(new ChannelHandlerAdapter(), new ProtocolConfig(), true) .exceptionCaught(new ChannelHandlerContextTest(channelTest1), new RuntimeException("")); - Assert.assertTrue(channelTest1.getIsClose() != null && channelTest1.isClose); + Assertions.assertTrue(channelTest1.getIsClose() != null && channelTest1.isClose); ChannelTest channelTest2 = new ChannelTest(); channelTest2.setActive(true); new NettyClientHandler(new ChannelHandlerAdapter(), new ProtocolConfig(), true) .userEventTriggered(new ChannelHandlerContextTest(channelTest2), IdleStateEvent.WRITER_IDLE_STATE_EVENT); - Assert.assertTrue(channelTest2.getIsClose() != null && channelTest2.isClose); + Assertions.assertTrue(channelTest2.getIsClose() != null && channelTest2.isClose); ChannelTest channelTest3 = new ChannelTest(); channelTest3.setActive(true); new NettyServerHandler(new ChannelHandlerAdapter(), new ProtocolConfig(), true) .exceptionCaught(new ChannelHandlerContextTest(channelTest3), new RuntimeException("")); - Assert.assertTrue(channelTest3.getIsClose() != null && channelTest3.isClose); + Assertions.assertTrue(channelTest3.getIsClose() != null && channelTest3.isClose); ChannelTest channelTest4 = new ChannelTest(); channelTest4.setActive(true); new NettyServerHandler(new ChannelHandlerAdapter(), new ProtocolConfig(), true) .userEventTriggered(new ChannelHandlerContextTest(channelTest4), IdleStateEvent.WRITER_IDLE_STATE_EVENT); - Assert.assertTrue(channelTest4.getIsClose() != null && channelTest4.isClose); + Assertions.assertTrue(channelTest4.getIsClose() != null && channelTest4.isClose); } } diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelManagerTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelManagerTest.java index 2c2782097e..291424c30d 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelManagerTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelManagerTest.java @@ -11,13 +11,13 @@ package com.tencent.trpc.transport.netty; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class NettyChannelManagerTest { @Test public void test() { - Assert.assertTrue(NettyChannelManager.getOrAddChannel(null, null) == null); + Assertions.assertTrue(NettyChannelManager.getOrAddChannel(null, null) == null); } } diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelTest.java index 3fd1b01820..19a0bf0957 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyChannelTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.transport.netty; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.Lists; import com.tencent.trpc.core.common.config.BaseProtocolConfig; @@ -31,23 +31,21 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicLong; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.api.support.membermodification.MemberModifier; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; +import java.lang.reflect.Field; +import java.lang.reflect.Method; /** * Test the potential leak issue during the conversion process between Netty and CompletableFuture */ -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.management.*") -@PrepareForTest({NettyTcpServerTransport.class}) +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class NettyChannelTest { /** @@ -233,89 +231,76 @@ private void sleep(long m) { @Test public void testNettyTcpServerTransport_multiOccupyPort() { try { - ProtocolConfig config = PowerMockito.mock(ProtocolConfig.class); - PowerMockito.when(config.getBossThreads()).thenReturn(1); - PowerMockito.when(config.getReusePort()).thenReturn(true); + ProtocolConfig config = Mockito.mock(ProtocolConfig.class); + Mockito.when(config.getBossThreads()).thenReturn(1); + Mockito.when(config.getReusePort()).thenReturn(true); - ChannelHandler chan = PowerMockito.mock(ChannelHandler.class); - ServerCodec serverCodec = PowerMockito.mock(ServerCodec.class); + ChannelHandler chan = Mockito.mock(ChannelHandler.class); + ServerCodec serverCodec = Mockito.mock(ServerCodec.class); - InetSocketAddress bindAddress = PowerMockito.mock(InetSocketAddress.class); - PowerMockito.when(bindAddress.getPort()).thenReturn(8080); + InetSocketAddress bindAddress = Mockito.mock(InetSocketAddress.class); + Mockito.when(bindAddress.getPort()).thenReturn(8080); - ServerBootstrap bootstrap = PowerMockito.mock(ServerBootstrap.class); + ServerBootstrap bootstrap = Mockito.mock(ServerBootstrap.class); - ChannelFuture channelFuture = PowerMockito.mock(ChannelFuture.class); + ChannelFuture channelFuture = Mockito.mock(ChannelFuture.class); - PowerMockito.when(channelFuture.isSuccess()).thenReturn(true); + Mockito.when(channelFuture.isSuccess()).thenReturn(true); - PowerMockito.when(bootstrap.bind(Mockito.any(InetSocketAddress.class))).thenReturn(channelFuture); + Mockito.when(bootstrap.bind(Mockito.any(InetSocketAddress.class))).thenReturn(channelFuture); - PowerMockito.when(channelFuture.await()).thenReturn(channelFuture); + Mockito.when(channelFuture.await()).thenReturn(channelFuture); NettyTcpServerTransport nettyTcpServerTransport = new NettyTcpServerTransport(config, chan, serverCodec); - NettyTcpServerTransport mockTcpServerTransport = PowerMockito.spy(nettyTcpServerTransport); + NettyTcpServerTransport mockTcpServerTransport = Mockito.spy(nettyTcpServerTransport); - MemberModifier.field(NettyTcpServerTransport.class, "bindAddress") - .set(mockTcpServerTransport, bindAddress); + setField(mockTcpServerTransport, "bindAddress", bindAddress); + setField(mockTcpServerTransport, "bootstrap", bootstrap); + setField(mockTcpServerTransport, "config", config); + ChannelFuture connect = invokeMethod(mockTcpServerTransport, "multiOccupyPort"); + Assertions.assertNotNull(connect); - MemberModifier.field(NettyTcpServerTransport.class, "bootstrap") - .set(mockTcpServerTransport, bootstrap); + Mockito.when(channelFuture.isSuccess()).thenReturn(false); - MemberModifier.field(NettyTcpServerTransport.class, "config") - .set(mockTcpServerTransport, config); - - PowerMockito.when(mockTcpServerTransport, "canMultiOccupyPort").thenReturn(true); - - ChannelFuture connect = Whitebox.invokeMethod(mockTcpServerTransport, "multiOccupyPort"); - Assert.assertNotNull(connect); - - PowerMockito.when(channelFuture.isSuccess()).thenReturn(false); - - ChannelFuture future = Whitebox.invokeMethod(mockTcpServerTransport, "multiOccupyPort"); - Assert.assertNotNull(future); + ChannelFuture future = invokeMethod(mockTcpServerTransport, "multiOccupyPort"); + Assertions.assertNotNull(future); } catch (Exception e) { e.printStackTrace(); - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } @Test public void testNettyTcpServerTransport_multiOccupyPortFail() { try { - ProtocolConfig config = PowerMockito.mock(ProtocolConfig.class); - PowerMockito.when(config.getBossThreads()).thenReturn(1); - PowerMockito.when(config.getReusePort()).thenReturn(true); - ChannelHandler chan = PowerMockito.mock(ChannelHandler.class); - ServerCodec serverCodec = PowerMockito.mock(ServerCodec.class); - InetSocketAddress bindAddress = PowerMockito.mock(InetSocketAddress.class); - PowerMockito.when(bindAddress.getPort()).thenReturn(8080); - ServerBootstrap bootstrap = PowerMockito.mock(ServerBootstrap.class); + ProtocolConfig config = Mockito.mock(ProtocolConfig.class); + Mockito.when(config.getBossThreads()).thenReturn(1); + Mockito.when(config.getReusePort()).thenReturn(true); + ChannelHandler chan = Mockito.mock(ChannelHandler.class); + ServerCodec serverCodec = Mockito.mock(ServerCodec.class); + InetSocketAddress bindAddress = Mockito.mock(InetSocketAddress.class); + Mockito.when(bindAddress.getPort()).thenReturn(8080); + ServerBootstrap bootstrap = Mockito.mock(ServerBootstrap.class); NettyTcpServerTransport nettyTcpServerTransport = new NettyTcpServerTransport(config, chan, serverCodec); - NettyTcpServerTransport mockTcpServerTransport = PowerMockito.spy(nettyTcpServerTransport); + NettyTcpServerTransport mockTcpServerTransport = Mockito.spy(nettyTcpServerTransport); - MemberModifier.field(NettyTcpServerTransport.class, "bindAddress") - .set(mockTcpServerTransport, bindAddress); - - MemberModifier.field(NettyTcpServerTransport.class, "bootstrap") - .set(mockTcpServerTransport, bootstrap); - - MemberModifier.field(NettyTcpServerTransport.class, "config") - .set(mockTcpServerTransport, config); - ChannelFuture connect = Whitebox.invokeMethod(mockTcpServerTransport, "multiOccupyPort"); - Assert.assertNull(connect); + setField(mockTcpServerTransport, "bindAddress", bindAddress); + setField(mockTcpServerTransport, "bootstrap", bootstrap); + setField(mockTcpServerTransport, "config", config); + ChannelFuture connect = invokeMethod(mockTcpServerTransport, "multiOccupyPort"); + Assertions.assertNull(connect); } catch (Exception e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } @Test public void testTRPCNettyBindException() { TRPCNettyBindException trpcNettyBindException = new TRPCNettyBindException("exception"); - Assert.assertNotNull(trpcNettyBindException); + Assertions.assertNotNull(trpcNettyBindException); BaseProtocolConfig baseProtocolConfig = new BaseProtocolConfig(); baseProtocolConfig.setBossThreads(1); @@ -325,7 +310,7 @@ public void testTRPCNettyBindException() { protocolConfig.setIp("127.0.0.1"); protocolConfig.setIoThreads(2); protocolConfig.setBossThreads(1); - Assert.assertTrue(protocolConfig.getBossThreads() > 0); + Assertions.assertTrue(protocolConfig.getBossThreads() > 0); } @@ -337,7 +322,7 @@ public void testTRPCNettyBindException_fail() { protocolConfig.setIoThreads(1); protocolConfig.setBossThreads(2); } catch (Exception e) { - Assert.assertNotNull(e.getMessage()); + Assertions.assertNotNull(e.getMessage()); } } @@ -348,8 +333,42 @@ public void testTRPCNettyBindException_failCpu() { protocolConfig.setIp("127.0.0.1"); protocolConfig.setBossThreads(999999); } catch (Exception e) { - Assert.assertNotNull(e.getMessage()); + Assertions.assertNotNull(e.getMessage()); + } + } + + private void setField(Object target, String fieldName, Object value) throws Exception { + Class clazz = target.getClass(); + Field field = null; + while (clazz != null && field == null) { + try { + field = clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + clazz = clazz.getSuperclass(); + } + } + if (field == null) { + throw new NoSuchFieldException(fieldName); + } + field.setAccessible(true); + field.set(target, value); + } + + private T invokeMethod(Object target, String methodName) throws Exception { + Class clazz = target.getClass(); + Method method = null; + while (clazz != null && method == null) { + try { + method = clazz.getDeclaredMethod(methodName); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } + if (method == null) { + throw new NoSuchMethodException(methodName); } + method.setAccessible(true); + return (T) method.invoke(target); } } diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyCodecAdapterTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyCodecAdapterTest.java index 17e0d7bd0b..21deb55fa4 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyCodecAdapterTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyCodecAdapterTest.java @@ -1,5 +1,9 @@ package com.tencent.trpc.transport.netty; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; + import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.exception.ErrorCode; import com.tencent.trpc.core.exception.TRpcException; @@ -10,16 +14,10 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.DecoderException; -import org.junit.Assert; -import org.junit.Test; - +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; - - public class NettyCodecAdapterTest { @Test @@ -28,7 +26,6 @@ public void testTcpDecodeIllegalPacket1() { doThrow(TRpcException.newFrameException(ErrorCode.TRPC_CLIENT_DECODE_ERR, "the request protocol is not trpc")) .when(codec).decode(any(), any()); - ProtocolConfig protocolConfig = new ProtocolConfig(); // set batchDecoder true protocolConfig.setBatchDecoder(true); @@ -43,12 +40,12 @@ public void testTcpDecodeIllegalPacket1() { // write illegal packet EmbeddedChannel tmpEmbeddedChannel = embeddedChannel; - DecoderException decoderException = Assert.assertThrows(DecoderException.class, () -> { + DecoderException decoderException = Assertions.assertThrows(DecoderException.class, () -> { tmpEmbeddedChannel.writeInbound(byteBuf); }); - Assert.assertTrue(decoderException.getCause() instanceof TransportException); - Assert.assertEquals(byteBuf.refCnt(), 0); + Assertions.assertTrue(decoderException.getCause() instanceof TransportException); + Assertions.assertEquals(byteBuf.refCnt(), 0); } @Test @@ -57,7 +54,6 @@ public void testTcpDecodeIllegalPacket2() { doThrow(TRpcException.newFrameException(ErrorCode.TRPC_CLIENT_DECODE_ERR, "the request protocol is not trpc")) .when(codec).decode(any(), any()); - ProtocolConfig protocolConfig = new ProtocolConfig(); // set batchDecoder false protocolConfig.setBatchDecoder(false); @@ -72,11 +68,11 @@ public void testTcpDecodeIllegalPacket2() { // write illegal packet EmbeddedChannel tmpEmbeddedChannel = embeddedChannel; - DecoderException decoderException = Assert.assertThrows(DecoderException.class, () -> { + DecoderException decoderException = Assertions.assertThrows(DecoderException.class, () -> { tmpEmbeddedChannel.writeInbound(byteBuf); }); - Assert.assertTrue(decoderException.getCause() instanceof TransportException); - Assert.assertEquals(byteBuf.refCnt(), 0); + Assertions.assertTrue(decoderException.getCause() instanceof TransportException); + Assertions.assertEquals(byteBuf.refCnt(), 0); } } diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyFutureUtilsTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyFutureUtilsTest.java index 0f37948a36..9166493918 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyFutureUtilsTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyFutureUtilsTest.java @@ -11,8 +11,8 @@ package com.tencent.trpc.transport.netty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.utils.FutureUtils; @@ -22,9 +22,9 @@ import io.netty.util.concurrent.GenericFutureListener; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentMap; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class NettyFutureUtilsTest { @@ -33,7 +33,7 @@ private static void checkChannelInManager(TestChannel channel) { assertTrue(((NettyChannel) (channelmap.values().toArray()[0])).getIoChannel() == channel); } - @Before + @BeforeEach public void before() { NettyChannelManager.getChannelMap().clear(); } @@ -53,7 +53,7 @@ public void futureisSuccessTest() { ProtocolConfig config = new ProtocolConfig(); NettyFutureUtils.adaptConnectingFuture(future, newFuture, config); checkChannelInManager(channel); - Assert.assertTrue(((NettyChannel) newFuture.join()).getIoChannel() == channel); + Assertions.assertTrue(((NettyChannel) newFuture.join()).getIoChannel() == channel); } /** diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyHandlerTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyHandlerTest.java index cad94b5768..787831ca92 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyHandlerTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyHandlerTest.java @@ -15,7 +15,7 @@ import com.tencent.trpc.core.logger.Logger; import com.tencent.trpc.core.logger.LoggerFactory; import com.tencent.trpc.core.transport.handler.ChannelHandlerAdapter; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class NettyHandlerTest { diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyProtoTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyProtoTest.java index 51c2d6d534..1f015cbd3d 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyProtoTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyProtoTest.java @@ -23,9 +23,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test Netty Protocol @@ -35,7 +35,7 @@ public class NettyProtoTest extends AbstractNettyTest { public static final String MESSAGE = "hello"; private static final Logger LOGGER = LoggerFactory.getLogger(NettyProtoTest.class); - @Before + @BeforeEach public void before() { } @@ -99,8 +99,8 @@ public void received(com.tencent.trpc.core.transport.Channel channel, } catch (InterruptedException e) { LOGGER.error("error:", e); } - Assert.assertEquals(serverReceive.get(), MESSAGE); - Assert.assertEquals(clientReceive.get(), MESSAGE); + Assertions.assertEquals(serverReceive.get(), MESSAGE); + Assertions.assertEquals(clientReceive.get(), MESSAGE); try { server.toString(); server.getChannels(); @@ -168,8 +168,8 @@ public void received(com.tencent.trpc.core.transport.Channel channel, } catch (InterruptedException e) { LOGGER.error("error:", e); } - Assert.assertEquals(serverReceive.get(), MESSAGE); - Assert.assertEquals(clientReceive.get(), MESSAGE); + Assertions.assertEquals(serverReceive.get(), MESSAGE); + Assertions.assertEquals(clientReceive.get(), MESSAGE); try { server.toString(); server.getChannels(); diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyTest.java index f8c1885437..7207b11d41 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/NettyTest.java @@ -11,7 +11,7 @@ package com.tencent.trpc.transport.netty; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.tencent.trpc.core.common.config.ProtocolConfig; import com.tencent.trpc.core.rpc.AbstractRequest; @@ -24,10 +24,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test Netty Transport @@ -38,12 +38,12 @@ public class NettyTest extends AbstractNettyTest { ServerTransport server; ClientTransport client; - @Before + @BeforeEach public void before() { } - @After + @AfterEach public void after() { if (server != null) { server.close(); @@ -153,8 +153,8 @@ public void received(com.tencent.trpc.core.transport.Channel channel, } catch (InterruptedException e) { e.printStackTrace(); } - Assert.assertEquals(serverReceive.get(), MESSAGE); - Assert.assertEquals(clientReceive.get(), MESSAGE); + Assertions.assertEquals(serverReceive.get(), MESSAGE); + Assertions.assertEquals(clientReceive.get(), MESSAGE); try { server.toString(); server.getChannels(); diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamCodecTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamCodecTest.java index ded6fb91be..1eaa6dd31d 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamCodecTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamCodecTest.java @@ -15,8 +15,8 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class StreamCodecTest { @@ -36,11 +36,11 @@ public void testCodec() throws Exception { ByteBuf buffer = Unpooled.buffer(0); frameDecoderHandler.decode(null, buffer, out); - Assert.assertEquals(0, out.size()); + Assertions.assertEquals(0, out.size()); buffer.writeByte(1); frameDecoderHandler.decode(null, buffer, out); - Assert.assertEquals(1, out.size()); + Assertions.assertEquals(1, out.size()); } } diff --git a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamNettyTest.java b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamNettyTest.java index 61bfdcdbf7..24c607e332 100644 --- a/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamNettyTest.java +++ b/trpc-transport/trpc-transport-netty/src/test/java/com/tencent/trpc/transport/netty/stream/StreamNettyTest.java @@ -18,8 +18,8 @@ import com.tencent.trpc.core.stream.transport.ServerTransport; import com.tencent.trpc.core.utils.NetUtils; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; public class StreamNettyTest { @@ -35,30 +35,30 @@ public void testTransport() { NettyServerTransportFactory serverTransportFactory = new NettyServerTransportFactory(); ServerTransport serverTransport = serverTransportFactory.create(protoConfig, () -> in -> in); - Assert.assertNotNull(serverTransport); + Assertions.assertNotNull(serverTransport); Mono serverMono = serverTransport.start(conn -> { connected.incrementAndGet(); return Mono.empty(); }); - Assert.assertNotNull(serverMono); + Assertions.assertNotNull(serverMono); Closeable[] server = new Closeable[1]; serverMono.log().doOnSuccess(svr -> server[0] = svr).block(); - Assert.assertNotNull(server[0]); + Assertions.assertNotNull(server[0]); NettyClientTransportFactory clientTransportFactory = new NettyClientTransportFactory(); ClientTransport clientTransport = clientTransportFactory.create(protoConfig, () -> in -> in); - Assert.assertNotNull(clientTransport); + Assertions.assertNotNull(clientTransport); final RpcConnection[] conn = new RpcConnection[1]; Mono connMono = clientTransport.connect(); - Assert.assertNotNull(connMono); + Assertions.assertNotNull(connMono); connMono.doOnSuccess(c -> conn[0] = c).block(); - Assert.assertNotNull(conn[0]); + Assertions.assertNotNull(conn[0]); conn[0].dispose(); - Assert.assertTrue(conn[0].isDisposed()); + Assertions.assertTrue(conn[0].isDisposed()); server[0].dispose(); }