From dfc53aa04371fd941538b06cd1c6aa88b12e580e Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 16:45:31 +0800 Subject: [PATCH 1/4] feat: optimize test --- pom.xml | 64 +++++++------------ trpc-core/pom.xml | 25 ++++++++ .../trpc-dependencies-bom/pom.xml | 9 ++- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 2f5abeb62..c7a91c727 100644 --- a/pom.xml +++ b/pom.xml @@ -82,22 +82,26 @@ UTF-8 - false - false - 3.0.0 - 3.5.0 - 3.0.1 - 3.0.1 - 3.1.2 17 17 - 3.7.0 + 17 + + false + false + 3.11.0 + 3.0.0-M9 + 3.0.0-M9 + 3.3.0 + 3.3.0 + 3.5.0 + 3.1.1 + 3.4.1 + 3.1.0 3.1.0 - false - 3.1.2 - 3.0.1 + 0.7.0 3.1.0 + 5.14.2 UTF-8 @@ -124,42 +128,22 @@ org.junit.jupiter junit-jupiter-api - 5.9.3 + ${junit.version} test org.junit.jupiter junit-jupiter-engine - 5.9.3 - test - - - - junit - junit - 4.13.2 + ${junit.version} test - - - - - - - - - - - - - - - - - - - - + + + + + + + org.jacoco org.jacoco.agent diff --git a/trpc-core/pom.xml b/trpc-core/pom.xml index f9c18ce73..9d2eb8999 100644 --- a/trpc-core/pom.xml +++ b/trpc-core/pom.xml @@ -20,6 +20,31 @@ + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.mockito + mockito-core + test + + + org.mockito + mockito-junit-jupiter + test + + + org.mockito + mockito-inline + test + org.assertj assertj-core diff --git a/trpc-dependencies/trpc-dependencies-bom/pom.xml b/trpc-dependencies/trpc-dependencies-bom/pom.xml index 98a5b354e..f902c1824 100644 --- a/trpc-dependencies/trpc-dependencies-bom/pom.xml +++ b/trpc-dependencies/trpc-dependencies-bom/pom.xml @@ -99,7 +99,7 @@ 11.0.25 2.7 2.4.14 - 5.10.0 + 5.14.2 3.28.0-GA 3.1.0 3.0.2 @@ -113,7 +113,7 @@ 3.3.0 1.4.1 3.0.2 - 5.5.0 + 5.21.0 5.2.0 1.4.2 2.2.1 @@ -127,7 +127,6 @@ 1.26.0 3.4.0 1.15.5 - 2.0.9 3.25.5 0.4.1 0.6.13 @@ -792,13 +791,13 @@ org.mockito mockito-core - ${mockito_core.version} + ${mockito-core.version} test org.mockito mockito-junit-jupiter - ${mockito_core.version} + ${mockito-core.version} test From 3fbb6d086b0a50fa58bd5e7c88ccd39a0c8e457f Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 16:49:03 +0800 Subject: [PATCH 2/4] feat: optimize test --- .../cluster/AbstractClusterInvokerTest.java | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java index f4b92fd0a..a5968b371 100644 --- a/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java +++ b/trpc-core/src/test/java/com/tencent/trpc/core/cluster/AbstractClusterInvokerTest.java @@ -22,20 +22,16 @@ import com.tencent.trpc.core.selector.spi.Selector; import com.tencent.trpc.core.worker.WorkerPoolManager; import java.util.concurrent.CompletionException; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(PowerMockRunner.class) -@PrepareForTest(SelectorManager.class) -@PowerMockIgnore({"javax.management.*", "javax.security.*", "javax.ws.*"}) +@ExtendWith(MockitoExtension.class) public class AbstractClusterInvokerTest { private static final String INVALID_SELECTOR = "invalid"; @@ -45,10 +41,7 @@ public class AbstractClusterInvokerTest { @Mock private ExtensionManager mockManager; - /** - * Init defClusterInvoker & mockManager - */ - @Before + @BeforeEach public void setUp() { BackendConfig backendConfig = new BackendConfig(); backendConfig.setServiceInterface(GenericClient.class); @@ -64,23 +57,28 @@ public void setUp() { ConsumerConfig consumerConfig = new ConsumerConfig<>(); consumerConfig.setBackendConfig(backendConfig); consumerConfig.setServiceInterface(GenericClient.class); - // mock SelectorManager and ExtensionManager - MockitoAnnotations.initMocks(this); - PowerMockito.mockStatic(SelectorManager.class); - PowerMockito.when(SelectorManager.getManager()).thenReturn(mockManager); - PowerMockito.when(mockManager.get(INVALID_SELECTOR)).thenReturn(null); - this.defClusterInvoker = new DefClusterInvoker<>(consumerConfig); + + try (MockedStatic mockedStatic = Mockito.mockStatic(SelectorManager.class)) { + mockedStatic.when(SelectorManager::getManager).thenReturn(mockManager); + Mockito.when(mockManager.get(INVALID_SELECTOR)).thenReturn(null); + this.defClusterInvoker = new DefClusterInvoker<>(consumerConfig); + } } @Test public void testInvoke() { - try { - defClusterInvoker.invoke(new DefRequest()).toCompletableFuture().join(); - } catch (CompletionException exception) { - NamingOptions namingOptions = defClusterInvoker.getConfig().getBackendConfig().getNamingOptions(); - String expect = "com.tencent.trpc.core.exception.TRpcException: " - + "the selector name:" + namingOptions.getSelectorId() + " not found selector"; - Assert.assertEquals(expect, exception.getMessage()); + try (MockedStatic mockedStatic = Mockito.mockStatic(SelectorManager.class)) { + mockedStatic.when(SelectorManager::getManager).thenReturn(mockManager); + Mockito.when(mockManager.get(INVALID_SELECTOR)).thenReturn(null); + + try { + defClusterInvoker.invoke(new DefRequest()).toCompletableFuture().join(); + } catch (CompletionException exception) { + NamingOptions namingOptions = defClusterInvoker.getConfig().getBackendConfig().getNamingOptions(); + String expect = "com.tencent.trpc.core.exception.TRpcException: " + + "the selector name:" + namingOptions.getSelectorId() + " not found selector"; + Assertions.assertEquals(expect, exception.getMessage()); + } } } From 4a7f3aca7dda01465449f19707a09d7f7d8963a5 Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 18:04:34 +0800 Subject: [PATCH 3/4] feat: optimize test --- pom.xml | 67 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index c7a91c727..425e2d54b 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,7 @@ 17 false + false false 3.11.0 3.0.0-M9 @@ -99,6 +100,7 @@ 3.1.0 3.1.0 + 0.8.11 0.7.0 3.1.0 5.14.2 @@ -137,17 +139,10 @@ ${junit.version} test - - - - - - - org.jacoco org.jacoco.agent - 0.8.11 + ${jacoco.version} runtime test @@ -183,14 +178,14 @@ --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.io=ALL-UNNAMED ${maven.ignore.testfailure} false - - ${project.build.directory}/coverage.exec - - ../../site/junit + false + 1 + true @@ -256,22 +251,22 @@ org.jacoco jacoco-maven-plugin - 0.8.8 + ${jacoco.version} false + ${project.build.directory}/coverage.exec + true - default-instrument + prepare-agent - instrument - - - - default-restore-instrumented-classes - - restore-instrumented-classes + prepare-agent + + surefireArgLine + ${project.build.directory}/coverage.exec + report @@ -284,6 +279,13 @@ ../../site/${project.artifactId} + + aggregate + verify + + report-aggregate + + @@ -291,6 +293,25 @@ exec-maven-plugin ${exec.maven.version} + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven.failsafe.version} + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + + + + + + integration-test + verify + + + + @@ -311,6 +332,10 @@ org.jacoco jacoco-maven-plugin + + org.apache.maven.plugins + maven-failsafe-plugin + From ef5057d586ff136ca49d84244497f05bfcb51985 Mon Sep 17 00:00:00 2001 From: wardseptember Date: Fri, 16 Jan 2026 18:10:15 +0800 Subject: [PATCH 4/4] feat: optimize trpc-container test --- .../trpc/container/config/YamlUtilsTest.java | 32 +++---- .../system/EnvironmentConfigurationTest.java | 16 ++-- .../config/system/EnvironmentTest.java | 84 ++++++++++++------- .../system/SystemConfigurationTest.java | 9 +- .../DefaultPropertySourceParserTest.java | 15 ++-- .../config/yaml/BackendConfigParserTest.java | 10 +-- .../config/yaml/ClientConfigParserTest.java | 10 +-- .../config/yaml/GlobalConfigParserTest.java | 15 ++-- .../config/yaml/ParseErrorInfoTest.java | 15 ++-- .../yaml/PluginConfigParserHelperTest.java | 46 +++++----- .../config/yaml/PluginConfigParserTest.java | 13 ++- .../config/yaml/ServerConfigParserTest.java | 20 ++--- .../config/yaml/ServiceConfigParserTest.java | 15 ++-- .../yaml/YamlApplicationConfigParserTest.java | 46 +++++----- .../container/ConsumerProxyTest.java | 27 +++--- .../container/DefaultContainerTest.java | 16 ++-- .../src/test/resources/trpc_java.yaml | 4 +- 17 files changed, 205 insertions(+), 188 deletions(-) diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java index 6acd1cb64..bbf699be5 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java @@ -16,10 +16,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -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; /** @@ -31,7 +31,7 @@ public class YamlUtilsTest { private YamlUtils yamlUtils; - @Before + @BeforeEach public void setUp() throws Exception { this.properties = new HashMap<>(); properties.put("string", "string"); @@ -41,7 +41,7 @@ public void setUp() throws Exception { this.yamlUtils = new YamlUtils(""); } - @After + @AfterEach public void tearDown() throws Exception { properties.clear(); } @@ -49,64 +49,64 @@ public void tearDown() throws Exception { @Test public void testGetString() { String string = yamlUtils.getString(properties, "string"); - Assert.assertEquals("string", string); + Assertions.assertEquals("string", string); properties.put("string", null); try { yamlUtils.getString(properties, "string"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetInteger() { int integer = yamlUtils.getInteger(properties, "integer"); - Assert.assertEquals(integer, 10); + Assertions.assertEquals(integer, 10); properties.put("integer", null); try { yamlUtils.getInteger(properties, "integer"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetBoolean() { boolean bool = yamlUtils.getBoolean(properties, "boolean"); - Assert.assertTrue(bool); + Assertions.assertTrue(bool); properties.put("boolean", null); try { yamlUtils.getBoolean(properties, "boolean"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetCollection() { Collection collection = yamlUtils.getCollection(properties, "collection"); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); properties.put("collection", null); try { yamlUtils.getBoolean(properties, "collection"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @Test public void testGetStringList() { List collection = yamlUtils.getStringList(properties, "collection"); - Assert.assertNotNull(collection); + Assertions.assertNotNull(collection); try { yamlUtils.requireMap(Arrays.asList(1, 2), "key"); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java index 6fcd0d5fc..e4d543c24 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java @@ -2,16 +2,16 @@ import com.tencent.trpc.container.config.ApplicationConfigParser; import com.tencent.trpc.core.extension.ExtensionLoader; -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; public class EnvironmentConfigurationTest { private Environment environment; - @Before + @BeforeEach public void init() { System.setProperty("global.namespace", "${env_type_enhancer}"); System.setProperty("server.app", "wechat"); @@ -34,7 +34,7 @@ public void init() { environment = new Environment(parser); } - @After + @AfterEach public void teardown() { System.clearProperty("global.namespace"); System.clearProperty("server.app"); @@ -57,6 +57,6 @@ public void teardown() { @Test public void testGetInternalProperty() { Object internalProperty = environment.getInternalProperty("server.app"); - Assert.assertEquals(internalProperty, "wechat"); + Assertions.assertEquals(internalProperty, "wechat"); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java index 25e91f60e..8c0cae980 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentTest.java @@ -11,19 +11,19 @@ package com.tencent.trpc.container.config.system; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.container.config.ApplicationConfigParser; import com.tencent.trpc.core.common.ConfigManager; import com.tencent.trpc.core.extension.ExtensionLoader; import java.util.Map; import java.util.NoSuchElementException; -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; /** * Environment test class @@ -34,7 +34,7 @@ public class EnvironmentTest { private ConfigManager configManager; private ConfigManager otherConfigManager; - @Before + @BeforeEach public void init() { System.setProperty("global.namespace", "${env_type_enhancer}"); System.setProperty("server.app", "wechat"); @@ -59,7 +59,7 @@ public void init() { otherConfigManager = environment.parse(); } - @After + @AfterEach public void teardown() { System.clearProperty("global.namespace"); System.clearProperty("server.app"); @@ -123,9 +123,11 @@ public void testOverrideConfig() { assertEquals(protocol, configManager.getClientConfig().getProtocol()); } - @Test(expected = IllegalStateException.class) + @Test public void testInteger() { - environment.getInteger("global.namespace", 2); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getInteger("global.namespace", 2); + }); } @Test @@ -133,54 +135,74 @@ public void testBoolean() { environment.getBoolean("global.namespace", true); } - @Test(expected = IllegalStateException.class) + @Test public void testShort() { - environment.getShort("global.namespace", (short) 2); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getShort("global.namespace", (short) 2); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testByte() { - environment.getByte("global.namespace", (byte) 2); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getByte("global.namespace", (byte) 2); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testFloat() { - environment.getFloat("global.namespace", 2f); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getFloat("global.namespace", 2f); + }); } - @Test(expected = IllegalStateException.class) + @Test public void testDouble() { - environment.getDouble("global.namespace", 2d); + Assertions.assertThrows(IllegalStateException.class, () -> { + environment.getDouble("global.namespace", 2d); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testIntNoElement() { - environment.getInt("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getInt("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testBooleanNoElement() { - environment.getBoolean("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getBoolean("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testShortNoElement() { - environment.getShort("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getShort("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testByteNoElement() { - environment.getByte("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getByte("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testFloatNoElement() { - environment.getFloat("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getFloat("global.namespace.not.exist"); + }); } - @Test(expected = NoSuchElementException.class) + @Test public void testDoubleNoElement() { - environment.getDouble("global.namespace.not.exist"); + Assertions.assertThrows(NoSuchElementException.class, () -> { + environment.getDouble("global.namespace.not.exist"); + }); } @Test diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java index 7f216d975..0bfa80171 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java @@ -1,17 +1,16 @@ package com.tencent.trpc.container.config.system; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SystemConfigurationTest { @Test public void testGetInternalProperty() { - System.setProperty("testSysProperty","1"); + System.setProperty("testSysProperty", "1"); SystemConfiguration systemConfiguration = new SystemConfiguration(); Object result = systemConfiguration.getInternalProperty("testSysProperty"); assertEquals("1", result); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java index c03eb914f..3919db6f4 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java @@ -3,18 +3,17 @@ import com.tencent.trpc.container.config.system.Configuration; import com.tencent.trpc.core.utils.YamlParser; import java.util.Map; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; -public class DefaultPropertySourceParserTest extends TestCase { +public class DefaultPropertySourceParserTest { @Test public void testGetFlattableMap() { Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); DefaultPropertySourceParser propertySourceParser = new DefaultPropertySourceParser(); Map flattableMap = propertySourceParser.getFlattableMap(yamlConfigMap); - Assert.assertEquals(147, flattableMap.size()); + Assertions.assertEquals(147, flattableMap.size()); } @Test @@ -22,8 +21,8 @@ public void testParseFlattableMap() { Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); DefaultPropertySourceParser propertySourceParser = new DefaultPropertySourceParser(); Map stringObjectMap = propertySourceParser.parseFlattableMap(yamlConfigMap); - Assert.assertEquals(4, stringObjectMap.size()); + Assertions.assertEquals(4, stringObjectMap.size()); Boolean aBoolean = Configuration.toBooleanObject(true); - Assert.assertTrue(aBoolean); + Assertions.assertTrue(aBoolean); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java index 708675a0e..fbd81e718 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java @@ -13,8 +13,8 @@ import com.tencent.trpc.core.common.config.BackendConfig; import com.tencent.trpc.core.utils.YamlParser; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -27,18 +27,18 @@ public class BackendConfigParserTest { @Test public void testParseConfigMap() { BackendConfigParser backendConfigParser = new BackendConfigParser(); - Assert.assertNotNull(backendConfigParser); + Assertions.assertNotNull(backendConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); List> maps = Arrays.asList(yamlConfigMap); Map stringBackendConfigMap = BackendConfigParser.parseConfigMap(maps); - Assert.assertNotNull(stringBackendConfigMap); + Assertions.assertNotNull(stringBackendConfigMap); } @Test public void testParseConfig() { Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); BackendConfig backendConfig = BackendConfigParser.parseConfig(yamlConfigMap); - Assert.assertNotNull(backendConfig); + Assertions.assertNotNull(backendConfig); } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java index f24338bfa..77bedf1b7 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java @@ -4,8 +4,8 @@ import com.tencent.trpc.core.common.config.ClientConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -14,11 +14,11 @@ public class ClientConfigParserTest { @Test public void testParseClientConfig() { ClientConfigParser clientConfigParser = new ClientConfigParser(); - Assert.assertNotNull(clientConfigParser); + Assertions.assertNotNull(clientConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); ClientConfig clientConfig = ClientConfigParser.parseClientConfig(yamlUtils.getMap(yamlConfigMap, ConfigConstants.CLIENT)); - Assert.assertNotNull(clientConfig.getNamespace()); + Assertions.assertNotNull(clientConfig.getNamespace()); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java index a755fca6e..2b763bad1 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java @@ -4,23 +4,22 @@ import com.tencent.trpc.core.common.config.GlobalConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; import java.util.Map; -public class GlobalConfigParserTest extends TestCase { +public class GlobalConfigParserTest { @Test public void testParseGlobalConfig() { GlobalConfigParser globalConfigParser = new GlobalConfigParser(); - Assert.assertNotNull(globalConfigParser); + Assertions.assertNotNull(globalConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); Map map = yamlUtils.getMap(yamlConfigMap, ConfigConstants.GLOBAL); GlobalConfig globalConfig = GlobalConfigParser.parseGlobalConfig(map); - Assert.assertNotNull(globalConfig.getNamespace()); - Assert.assertNotNull(globalConfig.getEnvName()); + Assertions.assertNotNull(globalConfig.getNamespace()); + Assertions.assertNotNull(globalConfig.getEnvName()); GlobalConfigParser.parseGlobalConfig(null); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java index 5c58a5516..ec1053377 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java @@ -1,22 +1,21 @@ package com.tencent.trpc.container.config.yaml; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; -public class ParseErrorInfoTest extends TestCase { +public class ParseErrorInfoTest { @Test public void testInfo() { ParseErrorInfo parseErrorInfo = new ParseErrorInfo(); - Assert.assertNotNull(parseErrorInfo); + Assertions.assertNotNull(parseErrorInfo); String info = ParseErrorInfo.info("key", "value"); - Assert.assertNotNull(info); + Assertions.assertNotNull(info); } @Test public void testTestInfo() { String info = ParseErrorInfo.info("key", "index", "value"); - Assert.assertNotNull(info); + Assertions.assertNotNull(info); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.java index f63f95b05..cb0d2cc4a 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserHelperTest.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, @@ -20,15 +20,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class PluginConfigParserHelperTest { @Test public void testParseAllPluginConfig() { PluginConfigParserHelper pluginConfigParserHelper = new PluginConfigParserHelper(); - Assert.assertNotNull(pluginConfigParserHelper); + Assertions.assertNotNull(pluginConfigParserHelper); Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); @@ -37,11 +37,11 @@ public void testParseAllPluginConfig() { checkRegistry(plugins.get(Registry.class).get("polaris")); try { Map mockMap = new HashMap(); - mockMap.put("key","v"); + mockMap.put("key", "v"); PluginConfigParserHelper .parseAllPluginConfig(yamlUtils.getMap(mockMap, ConfigConstants.PLUGINS)); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } try { Map mockMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); @@ -50,7 +50,7 @@ public void testParseAllPluginConfig() { PluginConfigParserHelper .parseAllPluginConfig(yamlUtils.getMap(mockMap, ConfigConstants.PLUGINS)); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } @@ -62,34 +62,32 @@ public void testParsePluginConfig() { .getMap(yamlConfigMap, ConfigConstants.PLUGINS) .get("registry"); Map plugins = PluginConfigParserHelper - .parsePluginConfig("plugin(type=registry)",Registry.class,polaris); + .parsePluginConfig("plugin(type=registry)", Registry.class, polaris); checkRegistry(plugins.get("polaris")); try { - Map mockMap = new HashMap(); - mockMap.put("key1","v"); - mockMap.put("key1","v"); + Map mockMap = new HashMap(); + mockMap.put("key1", "v"); + mockMap.put("key1", "v"); PluginConfigParserHelper - .parsePluginConfig("plugin(type=registry)",Registry.class,mockMap); + .parsePluginConfig("plugin(type=registry)", Registry.class, mockMap); } catch (Exception e) { - Assert.assertTrue(e instanceof IllegalArgumentException); + Assertions.assertTrue(e instanceof IllegalArgumentException); } } - - private void checkRegistry(PluginConfig config) { - Assert.assertEquals(config.getName(), "polaris"); - Assert.assertEquals(config.getPluginInterface(), Registry.class); - Assert.assertEquals(config.getPluginClass(), PolarisRegistry.class); - Assert.assertEquals(config.getProperties().get("address_list"), "10.235.25.48:8090"); - Assert.assertEquals(config.getProperties().get("register_self"), false); + Assertions.assertEquals(config.getName(), "polaris"); + Assertions.assertEquals(config.getPluginInterface(), Registry.class); + Assertions.assertEquals(config.getPluginClass(), PolarisRegistry.class); + Assertions.assertEquals(config.getProperties().get("address_list"), "10.235.25.48:8090"); + Assertions.assertEquals(config.getProperties().get("register_self"), false); List> services = (List>) config.getProperties() .get(ConfigConstants.SERVICE); - Assert.assertEquals(services.get(0).get("namespace"), "java-sdk-test-service1"); - Assert.assertEquals(services.get(0).get("token"), "xxxx"); - Assert.assertEquals(services.get(0).get("instance_id"), + Assertions.assertEquals(services.get(0).get("namespace"), "java-sdk-test-service1"); + Assertions.assertEquals(services.get(0).get("token"), "xxxx"); + Assertions.assertEquals(services.get(0).get("instance_id"), "feda4ceffed0b7b08cf5ec665dcd320e50434549"); - Assert.assertEquals(services.get(0).get("name"), "trpc.TestApp.TestServer.Greeter"); + Assertions.assertEquals(services.get(0).get("name"), "trpc.TestApp.TestServer.Greeter"); } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java index 6e85f1fab..7553846fa 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/PluginConfigParserTest.java @@ -4,21 +4,20 @@ import com.tencent.trpc.core.common.config.PluginConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; import java.util.Map; -public class PluginConfigParserTest extends TestCase { +public class PluginConfigParserTest { @Test public void testParsePlugins() { PluginConfigParser pluginConfigParser = new PluginConfigParser(); - Assert.assertNotNull(pluginConfigParser); + Assertions.assertNotNull(pluginConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); Map objectMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); Map, Map> classMapMap = PluginConfigParser.parsePlugins(objectMap); - Assert.assertNotNull(classMapMap.getClass()); + Assertions.assertNotNull(classMapMap.getClass()); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java index 5981abde0..9a394a38e 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServerConfigParserTest.java @@ -11,10 +11,10 @@ package com.tencent.trpc.container.config.yaml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import com.tencent.trpc.container.config.YamlUtils; import com.tencent.trpc.container.container.DefaultServerListener; @@ -24,9 +24,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -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; /** * ServerConfigParser test class @@ -37,7 +37,7 @@ public class ServerConfigParserTest { private List> serverListenerConfig; - @Before + @BeforeEach public void before() { this.yamlUtils = new YamlUtils(""); } @@ -45,14 +45,14 @@ public void before() { @Test public void testParseDefaultStartedListeners() { ServerConfigParser serverConfigParser = new ServerConfigParser(); - Assert.assertNotNull(serverConfigParser); + Assertions.assertNotNull(serverConfigParser); List serverListeners = ServerConfigParser.parseStartedListeners(yamlUtils, serverListenerConfig); assertNotNull(serverListeners); assertEquals(serverListeners.size(), 0); try { ServerConfig serverConfig = ServerConfigParser.parseServerConfig(null, null); - Assert.assertNotNull(serverConfig); + Assertions.assertNotNull(serverConfig); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java index 8b18eeda5..cdb0c3b91 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/ServiceConfigParserTest.java @@ -5,25 +5,24 @@ import com.tencent.trpc.core.common.config.ServiceConfig; import com.tencent.trpc.core.common.config.constant.ConfigConstants; import com.tencent.trpc.core.utils.YamlParser; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; import java.util.Arrays; import java.util.Map; -public class ServiceConfigParserTest extends TestCase { +public class ServiceConfigParserTest { @Test public void testParseServiceMapConfig() { ServiceConfigParser serviceConfigParser = new ServiceConfigParser(); - Assert.assertNotNull(serviceConfigParser); + Assertions.assertNotNull(serviceConfigParser); Map yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); YamlUtils yamlUtils = new YamlUtils("Label[]"); Map objectMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); Map, Map> classMapMap = PluginConfigParser.parsePlugins(objectMap); Map stringServiceConfigMap = ServiceConfigParser.parseServiceMapConfig(Arrays.asList(yamlConfigMap), classMapMap); - Assert.assertEquals(1,stringServiceConfigMap.size()); + Assertions.assertEquals(1, stringServiceConfigMap.size()); } @Test @@ -33,6 +32,6 @@ public void testParseServiceConfig() { Map objectMap = yamlUtils.getMap(yamlConfigMap, ConfigConstants.PLUGINS); Map, Map> classMapMap = PluginConfigParser.parsePlugins(objectMap); ServiceConfig serviceConfig = ServiceConfigParser.parseServiceConfig(yamlConfigMap, classMapMap); - Assert.assertFalse(serviceConfig.isSetDefault()); + Assertions.assertFalse(serviceConfig.isSetDefault()); } -} \ No newline at end of file +} diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java index 8e56a9a0f..440889cfa 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/yaml/YamlApplicationConfigParserTest.java @@ -11,9 +11,9 @@ package com.tencent.trpc.container.config.yaml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.tencent.trpc.core.common.ConfigManager; import com.tencent.trpc.core.common.TRpcSystemProperties; @@ -28,19 +28,19 @@ import com.tencent.trpc.core.utils.YamlParser; import java.util.Map; import org.apache.commons.collections4.MapUtils; -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; public class YamlApplicationConfigParserTest { - @Before + @BeforeEach public void before() { ConfigManager.stopTest(); } - @After + @AfterEach public void after() { ConfigManager.stopTest(); } @@ -276,7 +276,7 @@ public void testParseMap() { ConfigManager.stopTest(); String path = YamlParser.class.getClassLoader().getResource("trpc_java.yaml").getPath(); Map map = new YamlApplicationConfigParser().parseMap(path); - Assert.assertNotEquals(map.size(), 0); + Assertions.assertNotEquals(map.size(), 0); } @Test @@ -284,11 +284,11 @@ public void testParseMap_confPath() { ConfigManager.stopTest(); TRpcSystemProperties.setProperties(TRpcSystemProperties.CONFIG_PATH, ""); Map map1 = new YamlApplicationConfigParser().parseMap(""); - Assert.assertNotNull(map1); + Assertions.assertNotNull(map1); String path = YamlParser.class.getClassLoader().getResource("trpc_java.yaml").getPath(); TRpcSystemProperties.setProperties(TRpcSystemProperties.CONFIG_PATH, path); Map map = new YamlApplicationConfigParser().parseMap(""); - Assert.assertNotEquals(map.size(), 0); + Assertions.assertNotEquals(map.size(), 0); } @Test @@ -300,20 +300,20 @@ public void testParseImpls() { applicationConfig.setDefault(); ProviderConfig providerConfig1 = applicationConfig.getServerConfig().getServiceMap() .get("trpc.TestApp.TestServer.Greeter").getProviderConfigs().get(0); - Assert.assertEquals(providerConfig1.getRequestTimeout(), 2000); - Assert.assertEquals(providerConfig1.getWorkerPool(), "trpc_provider_biz_def"); - Assert.assertEquals(providerConfig1.getFilters().size(), 2); - Assert.assertEquals(providerConfig1.getFilters().get(0), "a"); - Assert.assertEquals(providerConfig1.getFilters().get(1), "b"); - Assert.assertFalse(providerConfig1.getEnableLinkTimeout()); + Assertions.assertEquals(providerConfig1.getRequestTimeout(), 2000); + Assertions.assertEquals(providerConfig1.getWorkerPool(), "trpc_provider_biz_def"); + Assertions.assertEquals(providerConfig1.getFilters().size(), 2); + Assertions.assertEquals(providerConfig1.getFilters().get(0), "a"); + Assertions.assertEquals(providerConfig1.getFilters().get(1), "b"); + Assertions.assertFalse(providerConfig1.getEnableLinkTimeout()); ProviderConfig providerConfig2 = applicationConfig.getServerConfig().getServiceMap() .get("trpc.TestApp.TestServer.Greeter").getProviderConfigs().get(1); - Assert.assertEquals(providerConfig2.getRequestTimeout(), Integer.MAX_VALUE); - Assert.assertEquals(providerConfig2.getWorkerPool(), "trpc_provider_biz_def"); - Assert.assertEquals(providerConfig2.getFilters().size(), 1); - Assert.assertEquals(providerConfig2.getFilters().get(0), "c"); - Assert.assertTrue(providerConfig2.getEnableLinkTimeout()); + Assertions.assertEquals(providerConfig2.getRequestTimeout(), Integer.MAX_VALUE); + Assertions.assertEquals(providerConfig2.getWorkerPool(), "trpc_provider_biz_def"); + Assertions.assertEquals(providerConfig2.getFilters().size(), 1); + Assertions.assertEquals(providerConfig2.getFilters().get(0), "c"); + Assertions.assertTrue(providerConfig2.getEnableLinkTimeout()); } @Test diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java index bb76a4c6e..b87cab833 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/ConsumerProxyTest.java @@ -11,8 +11,9 @@ package com.tencent.trpc.container.container; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Assertions; import com.google.protobuf.ByteString; import com.tencent.trpc.container.demo.HelloRequestProtocol.HelloRequest; import com.tencent.trpc.container.demo.HelloRequestProtocol.HelloResponse; @@ -22,15 +23,15 @@ import com.tencent.trpc.core.exception.TRpcException; import com.tencent.trpc.core.rpc.RpcClientContext; import com.tencent.trpc.core.rpc.TRpcProxy; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ConsumerProxyTest { Container container; - @Before + @BeforeEach public void before() throws Exception { ConfigManager.startTest(); container = new DefaultContainer(); @@ -38,7 +39,7 @@ public void before() throws Exception { container.start(); } - @After + @AfterEach public void after() { if (container != null) { container.stop(); @@ -60,13 +61,15 @@ public void getProxy() { System.out.println("namingOptions:>>>>>>>>>>>>>" + backendConfig.getNamingOptions()); } - @Test(expected = TRpcException.class) + @Test public void notConnect() { - String servcieId = "trpc.TestApp.TestServer.Notconnect"; - com.tencent.trpc.container.demo.GreeterClient service = TRpcProxy.getProxy(servcieId); - service.sayHello(new RpcClientContext(), HelloRequest.newBuilder() - .setMessage(ByteString.copyFrom("abc".getBytes())) - .build()); + Assertions.assertThrows(TRpcException.class, () -> { + String servcieId = "trpc.TestApp.TestServer.Notconnect"; + com.tencent.trpc.container.demo.GreeterClient service = TRpcProxy.getProxy(servcieId); + service.sayHello(new RpcClientContext(), HelloRequest.newBuilder() + .setMessage(ByteString.copyFrom("abc".getBytes())) + .build()); + }); } } diff --git a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.java b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.java index 08c359630..a2af534ef 100644 --- a/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.java +++ b/trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/container/DefaultContainerTest.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, @@ -11,23 +11,23 @@ package com.tencent.trpc.container.container; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.google.protobuf.ByteString; import com.tencent.trpc.container.demo.HelloRequestProtocol; import com.tencent.trpc.core.container.spi.Container; import com.tencent.trpc.core.extension.ExtensionLoader; import com.tencent.trpc.core.rpc.RpcClientContext; import com.tencent.trpc.core.rpc.TRpcProxy; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class DefaultContainerTest { Container container; - @Before + @BeforeEach public void start() { container = ExtensionLoader.getExtensionLoader(Container.class).getExtension("default"); @@ -45,7 +45,7 @@ public void testStart() { assertEquals(sayHello.getMessage().toStringUtf8(), "abc-"); } - @After + @AfterEach public void testStop() throws InterruptedException { Thread.sleep(1000); container.stop(); diff --git a/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml b/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml index fae3432a6..37ae74f4f 100644 --- a/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml +++ b/trpc-container/trpc-container-default/src/test/resources/trpc_java.yaml @@ -20,7 +20,7 @@ server: impls: - com.tencent.trpc.container.demo.GreeterServiceImp ip: 127.0.0.1 - port: 12345 + port: 13345 network: tcp protocol: trpc @@ -29,7 +29,7 @@ client: service: - name: trpc.TestApp.TestServer.Greeter interface: com.tencent.trpc.container.demo.GreeterClient - naming_url: ip://127.0.0.1:12345 + naming_url: ip://127.0.0.1:13345 - name: trpc.TestApp.TestServer.Notconnect interface: com.tencent.trpc.container.demo.GreeterClient naming_url: ip://127.0.0.1:9999