Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void checkClientConfig(ConfigManager applicationConfig) {
assertEquals(backendConfig.getNamespace(), "dev2");
assertEquals(backendConfig.getGroup(), "g1");
assertEquals(backendConfig.getVersion(), "v1");
assertEquals(backendConfig.getCallee(), "127.0.0.1:12345");
assertEquals(backendConfig.getCallee(), "trpc.TestApp.TestServer.GreeterCallee");
assertEquals(backendConfig.getFilters().get(0), "filter");
assertEquals(backendConfig.getRequestTimeout(), 2000);
assertEquals(backendConfig.getProtocol(), "trpc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ protected void initWorkerPool() {
protected void setCalleeInfo() {
String serviceNaming = getNamingOptions().getServiceNaming();
// callee is set to serviceNaming, setting is not supported
callee = serviceNaming;
if (StringUtils.isEmpty(callee)) {
callee = serviceNaming;
}

// in the TRPC scenario, serviceId is in the format trpc.calleeapp.calleeserver.calleeservice
if (StringUtils.isNotBlank(callee) && callee.startsWith(Constants.STANDARD_NAMING_PRE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void testConfig() {
config.setNamingUrl("a://b");
config.setTarget("a://b");
config.setRequestTimeout(10);
config.setBackupRequestTimeMs(100);
config.setProtocol("trpc");
config.setSerialization("pb");
config.setCompressor("gzip");
Expand Down Expand Up @@ -129,6 +130,7 @@ public void testConfig() {
assertEquals(70, config.getConnsPerAddr());
assertEquals(80, config.getConnTimeout());
assertEquals(10, config.getRequestTimeout());
assertEquals(100, config.getBackupRequestTimeMs());
assertEquals(true, config.isIoThreadGroupShare());
assertEquals(1000, config.getIoThreads());
assertEquals("/trpc", config.getBasePath());
Expand All @@ -149,27 +151,41 @@ public void testConfig() {
}

@Test
public void testSetCallee() {
ExtensionLoader
.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
public void testNoSetCallee() {
ExtensionLoader.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
BackendConfig config = new BackendConfig();
config.setName("trpc.calleeapp.calleeserver.calleeservice.calleemethod");
config.setNamingUrl("ip://127.0.0.1:8888");
config.setExtMap(ImmutableMap.of("attalog", (Object) "attalog"));
config.setFilters(Lists.newArrayList("attalog"));
config.setGroup("group");
config.setCallee("trpc.app.server.service");
config.init();
assertEquals(config.getCalleeApp(), "");
assertEquals(config.getCalleeServer(), "");
assertEquals(config.getCalleeService(), "");
assertEquals("127.0.0.1:8888", config.getCallee());
}

@Test
public void testSetCallee() {
ExtensionLoader.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
BackendConfig config = new BackendConfig();
config.setName("trpc.calleeapp.calleeserver.calleeservice.calleemethod");
config.setNamingUrl("ip://127.0.0.1:8888");
config.setExtMap(ImmutableMap.of("attalog", (Object) "attalog"));
config.setFilters(Lists.newArrayList("attalog"));
config.setGroup("group");
config.setCallee("trpc.app.server.service");
config.init();
assertEquals(config.getCalleeApp(), "app");
assertEquals(config.getCalleeServer(), "server");
assertEquals(config.getCalleeService(), "service");
assertEquals("trpc.app.server.service", config.getCallee());
}

@Test
public void testNameSpace() {
ExtensionLoader
.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
ExtensionLoader.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
BackendConfig config = new BackendConfig();
config.setName("trpc.calleeapp.calleeserver.calleeservice.calleemethod");
config.setNamingUrl("ip://127.0.0.1:8888");
Expand All @@ -183,16 +199,15 @@ public void testNameSpace() {
config.init();
config.toString();
assertEquals(0, config.getNamingMap().size());
assertEquals(config.getCalleeApp(), "");
assertEquals(config.getCalleeServer(), "");
assertEquals(config.getCalleeService(), "");
assertEquals(config.getCalleeApp(), "app");
assertEquals(config.getCalleeServer(), "server");
assertEquals(config.getCalleeService(), "service");
assertEquals(config.getNamingOptions().getExtMap().get("namespace"), "abc");
}

@Test
public void testIp() {
ExtensionLoader
.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
ExtensionLoader.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
ExtensionLoader.registerPlugin(ThreadWorkerPool.newThreadWorkerPoolConfig("thread", 10, Boolean.FALSE));
BackendConfig config = new BackendConfig();
config.setNamingUrl("ip://127.0.0.1:8888");
Expand Down Expand Up @@ -237,10 +252,8 @@ public void testIp() {

@Test
public void test() {
ExtensionLoader
.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
ExtensionLoader.registerPlugin(ThreadWorkerPool.newThreadWorkerPoolConfig("thread", 10,
10, Boolean.FALSE));
ExtensionLoader.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
ExtensionLoader.registerPlugin(ThreadWorkerPool.newThreadWorkerPoolConfig("thread", 10, Boolean.FALSE));
BackendConfig config = new BackendConfig();
config.setCallee("trpc.calleeapp.calleeserver.calleeservice.calleemethod");
config.setNamingUrl("ip://127.0.0.1:8888");
Expand Down Expand Up @@ -273,9 +286,9 @@ public void test() {
assertEquals(config.getServiceInterface(), GenericClient.class);
assertEquals(config.getRequestTimeout(), 1234);
assertEquals(config.getVersion(), "v888");
assertEquals(config.getCalleeApp(), "");
assertEquals(config.getCalleeServer(), "");
assertEquals(config.getCalleeService(), "");
assertEquals(config.getCalleeApp(), "calleeapp");
assertEquals(config.getCalleeServer(), "calleeserver");
assertEquals(config.getCalleeService(), "calleeservice");
ServiceId serviceId = config.toNamingServiceId();
assertEquals(serviceId.getGroup(), "group");
assertEquals(serviceId.getServiceName(), "127.0.0.1:8888");
Expand All @@ -294,8 +307,7 @@ public void testGetProxy() {
config.setServiceInterface(GenericClient.class);
config.setName("client");
config.setNamingUrl("ip://127.0.0.1:12345");
ConfigManager.getInstance().getClientConfig().getBackendConfigMap()
.put("client", config);
ConfigManager.getInstance().getClientConfig().getBackendConfigMap().put("client", config);
ConsumerConfig<GenericClient> consumerConfig = new ConsumerConfig<>();
consumerConfig.setBackendConfig(config);
consumerConfig.setServiceInterface(GenericClient.class);
Expand All @@ -317,8 +329,7 @@ public void testGetProxy() {

@Test
public void testNotDefault() {
ExtensionLoader
.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
ExtensionLoader.registerPlugin(new PluginConfig("attalog", Filter.class, RemoteLoggerTest.class));
ExtensionLoader.registerPlugin(ThreadWorkerPool.newThreadWorkerPoolConfig("thread", 10, Boolean.FALSE));
BackendConfig config = new BackendConfig();
config.setName("trpc.calleeapp.calleeserver.calleeservice.calleemethod");
Expand Down Expand Up @@ -351,6 +362,54 @@ public void testNotDefault() {
}
}

@Test
public void testSetDestinationSet() {
BackendConfig config = new BackendConfig();
config.setNamingUrl("polaris://127.0.0.1:8888");
config.setDestinationSet("testSet");
Object metaData = config.getNamingMap().get(Constants.METADATA);
assertNotNull(metaData);
assertTrue(metaData instanceof Map);
assertEquals("testSet", ((Map<?, ?>) metaData).get(Constants.POLARIS_PLUGIN_SET_NAME_KEY));
}

@Test
public void testNewConsumerConfig() {
BackendConfig config = new BackendConfig();
ConsumerConfig<GenericClient> consumerConfig = config.newConsumerConfig(GenericClient.class);
assertNotNull(consumerConfig);
assertEquals(GenericClient.class, consumerConfig.getServiceInterface());
}

@Test
public void testOverrideConfigDefault() {
BackendConfig config = new BackendConfig();
ClientConfig clientConfig = new ClientConfig();
clientConfig.setRequestTimeout(5000);
config.overrideConfigDefault(clientConfig);
assertEquals(5000, config.getRequestTimeout());
}

@Test
public void testMergeConfig() {
BackendConfig config = new BackendConfig();
ClientConfig clientConfig = new ClientConfig();
clientConfig.setFilters(Lists.newArrayList("testFilter"));
config.mergeConfig(clientConfig);
assertEquals(1, config.getFilters().size());
assertEquals("testFilter", config.getFilters().get(0));
}

@Test
public void testGenerateProtocolConfig() {
BackendConfig config = new BackendConfig();
ProtocolConfig protocolConfig = config.generateProtocolConfig("127.0.0.1", 8080, "tcp");
assertNotNull(protocolConfig);
assertEquals("127.0.0.1", protocolConfig.getIp());
assertEquals(8080, protocolConfig.getPort());
assertEquals("tcp", protocolConfig.getNetwork());
}

public static final class RemoteLoggerTest extends RemoteLoggerFilter {

@Override
Expand Down
Loading