Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dfc53aa
feat: optimize test
wardseptember Jan 16, 2026
3fbb6d0
feat: optimize test
wardseptember Jan 16, 2026
4a7f3ac
feat: optimize test
wardseptember Jan 16, 2026
ef5057d
feat: optimize trpc-container test
wardseptember Jan 16, 2026
c8f927e
Merge remote-tracking branch 'upstream/JDK17/Springboot3' into feat/o…
wardseptember Jan 19, 2026
8e6543c
feat: optimize trpc-core test
wardseptember Jan 19, 2026
146b627
feat: optimize trpc-core test
wardseptember Jan 19, 2026
cb67b58
feat: optimize trpc-core test
wardseptember Jan 20, 2026
0025a5b
feat: optimize ci and codecov
wardseptember Jan 20, 2026
135f762
feat: optimize trpc-transport test
wardseptember Jan 21, 2026
0ba0f08
Merge remote-tracking branch 'upstream/JDK17/Springboot3' into feat/o…
wardseptember Jan 27, 2026
67f3903
Merge remote-tracking branch 'upstream/JDK17/Springboot3' into feat/o…
wardseptember Feb 2, 2026
c989fc4
feat: optimize trpc-proto test
wardseptember Feb 2, 2026
7eb4de5
Merge remote-tracking branch 'upstream/JDK17/Springboot3' into feat/o…
wardseptember Feb 2, 2026
b0e9a55
feat: optimize trpc-spring-support test
wardseptember Feb 4, 2026
9a12cce
feat: optimize trpc-spring-support test
wardseptember Feb 4, 2026
d571975
feat: optimize trpc-spring-support test
wardseptember Feb 4, 2026
eaed7c3
Merge remote-tracking branch 'refs/remotes/upstream/JDK17/Springboot3…
wardseptember Feb 4, 2026
fccff83
feat: optimize trpc-spring-cloud-gateway test
wardseptember Feb 4, 2026
0a8c9e8
Merge remote-tracking branch 'upstream/JDK17/Springboot3' into feat/o…
wardseptember Feb 4, 2026
07af162
Merge remote-tracking branch 'upstream/JDK17/Springboot3' into feat/o…
wardseptember Feb 6, 2026
60fdccc
feat: optimize trpc-spring-boot-starter test
wardseptember Feb 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: optimize trpc-core test
  • Loading branch information
wardseptember committed Jan 19, 2026
commit 8e6543c744700407e8e07c40ba7fb1da9b7497ee
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,11 +11,11 @@

package com.tencent.trpc.core.common.config;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
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.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
Expand All @@ -34,29 +34,25 @@
import com.tencent.trpc.core.worker.support.thread.ThreadWorkerPool;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
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;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ExtensionLoader.class, RpcServerManager.class, FilterManager.class})
@PowerMockIgnore({"javax.management.*"})
import org.mockito.MockedStatic;

@ExtendWith(MockitoExtension.class)
public class ProviderConfigTest {

@Before
@BeforeEach
public void before() {
ConfigManager.stopTest();
ConfigManager.startTest();
}

@After
@AfterEach
public void after() {
ConfigManager.stopTest();
}
Expand All @@ -82,19 +78,19 @@ public void testInitServiceInterfaceConfig() {

@Test
public void testInit() {
PowerMockito.mockStatic(ExtensionLoader.class);
PowerMockito.mockStatic(RpcServerManager.class);
ExtensionLoader mock = PowerMockito.mock(ExtensionLoader.class);
PowerMockito.when(ExtensionLoader.getExtensionLoader(Filter.class)).thenReturn(mock);
PowerMockito.when(mock.hasExtension(Mockito.anyString())).thenReturn(true);
PowerMockito.when(ExtensionLoader.getPluginConfigMap()).then(v -> v.callRealMethod());
Mockito.mockStatic(ExtensionLoader.class);
Mockito.mockStatic(RpcServerManager.class);
ExtensionLoader mock = Mockito.mock(ExtensionLoader.class);
Mockito.when(ExtensionLoader.getExtensionLoader(Filter.class)).thenReturn(mock);
Mockito.when(mock.hasExtension(Mockito.anyString())).thenReturn(true);
Mockito.when(ExtensionLoader.getPluginConfigMap()).then(v -> v.callRealMethod());
ThreadWorkerPool threadWorkerPool = new ThreadWorkerPool();
threadWorkerPool.setPluginConfig(WorkerPoolManager.DEF_CONSUMER_WORKER_POOL_CONFIG);
threadWorkerPool.init();
PowerMockito.when(ExtensionLoader.getExtensionLoader(WorkerPool.class)).thenReturn(mock);
PowerMockito.when(mock.getExtension(Mockito.anyString())).thenReturn(threadWorkerPool);
Filter mockFilter = PowerMockito.mock(Filter.class);
PowerMockito.when(mock.getExtension(Mockito.eq("filterId"))).thenReturn(mockFilter);
Mockito.when(ExtensionLoader.getExtensionLoader(WorkerPool.class)).thenReturn(mock);
Mockito.when(mock.getExtension(Mockito.anyString())).thenReturn(threadWorkerPool);
Filter mockFilter = Mockito.mock(Filter.class);
Mockito.when(mock.getExtension(Mockito.eq("filterId"))).thenReturn(mockFilter);
ExtensionLoader.getExtensionLoader(Filter.class);
ServiceConfig serviceConfig = new ServiceConfig();
serviceConfig.setName("protoid");
Expand All @@ -111,21 +107,21 @@ public void testInit() {
configMap.put("registyId", new PluginConfig("registyId", MockRegistry.class, extMap));
ConfigManager.getInstance().getPluginConfigMap().put(Registry.class, configMap);
config.init();
RpcServer rpcServerMock = PowerMockito.mock(RpcServer.class);
PowerMockito.when(RpcServerManager.getOrCreateRpcServer(Mockito.argThat(new IsValid())))
RpcServer rpcServerMock = Mockito.mock(RpcServer.class);
Mockito.when(RpcServerManager.getOrCreateRpcServer(Mockito.argThat(new IsValid())))
.thenReturn(rpcServerMock);
PowerMockito.when(rpcServerMock.getProtocolConfig()).thenReturn(new ProtocolConfig());
Mockito.when(rpcServerMock.getProtocolConfig()).thenReturn(new ProtocolConfig());
serviceConfig.export();
Mockito.verify(rpcServerMock, Mockito.times(1)).export(Mockito.any(ProviderInvoker.class));
Mockito.verify(rpcServerMock, Mockito.times(1)).open();
assertTrue(serviceConfig.isExported());
serviceConfig.unExport();
assertFalse(serviceConfig.isExported());
ExtensionLoader mockRegistryLoader = PowerMockito.mock(ExtensionLoader.class);
PowerMockito.when(ExtensionLoader.getExtensionLoader(Registry.class))
ExtensionLoader mockRegistryLoader = Mockito.mock(ExtensionLoader.class);
Mockito.when(ExtensionLoader.getExtensionLoader(Registry.class))
.thenReturn(mockRegistryLoader);
Registry registry = PowerMockito.mock(Registry.class);
PowerMockito.when(mockRegistryLoader.getExtension("registyId")).thenReturn(registry);
Registry registry = Mockito.mock(Registry.class);
Mockito.when(mockRegistryLoader.getExtension("registyId")).thenReturn(registry);
}

@Test
Expand Down Expand Up @@ -226,12 +222,16 @@ public static class TRpcServiceInstance implements TRpcServiceInterface {

}

private class IsValid extends ArgumentMatcher<ProtocolConfig> {
private class IsValid implements ArgumentMatcher<ProtocolConfig> {

@Override
public boolean matches(ProtocolConfig protocolConfig) {
return protocolConfig.getIp().contentEquals("127.0.0.1");
}

@Override
public boolean matches(Object o) {
ProtocolConfig ox = (ProtocolConfig) o;
return ox.getIp().contentEquals("127.0.0.1");
public Class<?> type() {
return ProtocolConfig.class;
}
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -24,8 +24,8 @@
import java.util.List;
import java.util.Map;
import org.assertj.core.util.Strings;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class JsonUtilsTest {

Expand All @@ -37,75 +37,77 @@ public class JsonUtilsTest {
@Test
public void testCopy() {
ObjectMapper objectMapper = JsonUtils.copy();
Assert.assertNotNull(objectMapper);
Assertions.assertNotNull(objectMapper);
}

@Test(expected = TRpcException.class)
@Test
public void testFromInputStream() {
JsonUtils.fromInputStream(new InputStream() {
@Override
public int read() throws IOException {
return 0;
}
}, Object.class);
Assertions.assertThrows(TRpcException.class, () -> {
JsonUtils.fromInputStream(new InputStream() {
@Override
public int read() throws IOException {
return 0;
}
}, Object.class);
});
}

@Test
public void testFromJson() {
TestObj obj = JsonUtils.fromJson(JSON, TestObj.class);
Assert.assertEquals(obj.getTest(), 123);
Assertions.assertEquals(obj.getTest(), 123);
TestObj objRef = JsonUtils.fromJson(JSON, new TypeReference<TestObj>() {
});
Assert.assertEquals(objRef.getTest(), 123);
Assertions.assertEquals(objRef.getTest(), 123);
List<TestObj> testObjs = JsonUtils.fromJson(JSON_LIST, JsonUtils.copy().getTypeFactory()
.constructCollectionType(Collection.class, TestObj.class));
Assert.assertEquals(testObjs.get(0).getTest(), 123);
Assertions.assertEquals(testObjs.get(0).getTest(), 123);
try {
JsonUtils.fromJson(ERROR_JSON, TestObj.class);
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
try {
JsonUtils.fromJson(ERROR_JSON, JsonUtils.copy().getTypeFactory().constructCollectionType(
Collection.class, TestObj.class));
Collection.class, TestObj.class));
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
try {
JsonUtils.fromJson(ERROR_JSON, new TypeReference<TestObj>() {
});
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
}

@Test
public void testFromBytes() {
TestObj obj = JsonUtils.fromBytes(JSON.getBytes(Charsets.UTF_8), TestObj.class);
Assert.assertEquals(obj.getTest(), 123);
Assertions.assertEquals(obj.getTest(), 123);
TestObj objRef = JsonUtils.fromBytes(JSON.getBytes(Charsets.UTF_8), new TypeReference<TestObj>() {
});
Assert.assertEquals(objRef.getTest(), 123);
Assertions.assertEquals(objRef.getTest(), 123);
objRef = JsonUtils.fromBytes(JSON, new TypeReference<TestObj>() {
});
Assert.assertEquals(objRef.getTest(), 123);
Assertions.assertEquals(objRef.getTest(), 123);

try {
JsonUtils.fromBytes(ERROR_JSON.getBytes(Charsets.UTF_8), TestObj.class);
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
try {
JsonUtils.fromBytes(ERROR_JSON.getBytes(Charsets.UTF_8), new TypeReference<TestObj>() {
});
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
try {
JsonUtils.fromBytes(ERROR_JSON, new TypeReference<TestObj>() {
});
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
}

Expand All @@ -114,15 +116,15 @@ public void testToJson() {
TestObj obj = new TestObj();
obj.setTest(123);
String json = JsonUtils.toJson(obj);
Assert.assertEquals(json, JSON);
Assertions.assertEquals(json, JSON);
TestObj1 obj1 = new TestObj1();
obj1.setTest(123);
try {
JsonUtils.toJson(obj1);
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
Assert.assertFalse(Strings.isNullOrEmpty(
Assertions.assertFalse(Strings.isNullOrEmpty(
JsonUtils.toJson(ProtoJsonConverter.messageToMap(HelloRequest.getDefaultInstance()))));
}

Expand All @@ -131,25 +133,25 @@ public void testToJsonWithDefaultValue() {
TestObj obj = new TestObj();
obj.setTest(123);
String json = JsonUtils.toJson(obj, "aaa");
Assert.assertEquals(json, JSON);
Assertions.assertEquals(json, JSON);
TestObj1 obj1 = new TestObj1();
obj1.setTest(123);
String aaa = JsonUtils.toJson(obj1, "aaa");
Assert.assertEquals(EMPTY_JSON, aaa);
Assertions.assertEquals(EMPTY_JSON, aaa);
}

@Test
public void testToBytes() {
TestObj obj = new TestObj();
obj.setTest(123);
byte[] bytes = JsonUtils.toBytes(obj);
Assert.assertEquals(new String(bytes), JSON);
Assertions.assertEquals(new String(bytes), JSON);
TestObj1 obj1 = new TestObj1();
obj1.setTest(123);
try {
JsonUtils.toBytes(obj1);
} catch (TRpcException e) {
Assert.assertEquals(e.getCode(), 2001);
Assertions.assertEquals(e.getCode(), 2001);
}
}

Expand All @@ -160,10 +162,10 @@ public void testGeneric() {
testObj.setTest(11);
obj.setData(testObj);
String json = JsonUtils.toJson(obj);
Assert.assertEquals(json, "{\"data\":{\"test\":11}}");
Assertions.assertEquals(json, "{\"data\":{\"test\":11}}");
TestObj2<TestObj> obj2 = JsonUtils.fromJson(json, new TypeReference<TestObj2<TestObj>>() {
});
Assert.assertEquals(obj2.getData().getTest(), 11);
Assertions.assertEquals(obj2.getData().getTest(), 11);
}


Expand All @@ -174,14 +176,14 @@ public void testConvertValue() {
mapValue.put("unknown", 111);
mapValue.put("12", 12);
TestConfigObject testConfigObject = JsonUtils.convertValue(mapValue, TestConfigObject.class);
Assert.assertEquals("123", testConfigObject.getData());
Assertions.assertEquals("123", testConfigObject.getData());
try {
JsonUtils.convertValue(mapValue, Discovery.class);
} catch (Exception e) {
Assert.assertNotNull(e);
Assertions.assertNotNull(e);
return;
}
Assert.fail();
Assertions.fail();
}


Expand Down