-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a41c9aa
commit a8ba175
Showing
16 changed files
with
414 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.tencent.trpc.container.config.system; | ||
|
||
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; | ||
|
||
public class EnvironmentConfigurationTest{ | ||
|
||
private Environment environment; | ||
|
||
@Before | ||
public void init() { | ||
System.setProperty("global.namespace", "${env_type_enhancer}"); | ||
System.setProperty("server.app", "wechat"); | ||
System.setProperty("server.local_ip", "0.0.0.0"); | ||
System.setProperty("server.service[0].name", "trpc.TestApp.TestServer.Greeter2"); | ||
System.setProperty("server.service[0].impls[0]", "com.tencent.trpc.container.demo.GreeterServiceImp2"); | ||
System.setProperty("server.service[0].impls[1]", "com.tencent.trpc.container.demo.GreeterServiceImp3"); | ||
System.setProperty("server.service[0].protocol", "fbp"); | ||
System.setProperty("client.protocol", "fbp"); | ||
System.setProperty("client.service[0].name", "trpc.TestApp.TestServer.Greeter3"); | ||
System.setProperty("client.service[0].naming_url", "ip://127.0.0.1:77777"); | ||
System.setProperty("worker.pool", "30"); | ||
System.setProperty("enable.distribution.transaction", "true"); | ||
System.setProperty("short.test", "1"); | ||
System.setProperty("byte.test", "1"); | ||
System.setProperty("float.test", "1"); | ||
System.setProperty("double.test", "1"); | ||
ApplicationConfigParser parser = ExtensionLoader.getExtensionLoader(ApplicationConfigParser.class) | ||
.getExtension("yaml"); | ||
environment = new Environment(parser); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
System.clearProperty("global.namespace"); | ||
System.clearProperty("server.app"); | ||
System.clearProperty("server.local_ip"); | ||
System.clearProperty("server.service[0].name"); | ||
System.clearProperty("server.service[0].impls[0]"); | ||
System.clearProperty("server.service[0].impls[1]"); | ||
System.clearProperty("server.service[0].protocol"); | ||
System.clearProperty("client.protocol"); | ||
System.clearProperty("client.service[0].name"); | ||
System.clearProperty("client.service[0].naming_url"); | ||
System.clearProperty("worker.pool"); | ||
System.clearProperty("enable.distribution.transaction"); | ||
System.clearProperty("short.test"); | ||
System.clearProperty("byte.test"); | ||
System.clearProperty("float.test"); | ||
System.clearProperty("double.test"); | ||
} | ||
|
||
@Test | ||
public void testGetInternalProperty() { | ||
Object internalProperty = environment.getInternalProperty("server.app"); | ||
Assert.assertEquals(internalProperty,"wechat"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...fault/src/test/java/com/tencent/trpc/container/config/system/SystemConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tencent.trpc.container.config.system; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class SystemConfigurationTest { | ||
|
||
@Test | ||
public void testGetInternalProperty() { | ||
System.setProperty("testSysProperty","1"); | ||
SystemConfiguration systemConfiguration = new SystemConfiguration(); | ||
Object result = systemConfiguration.getInternalProperty("testSysProperty"); | ||
assertEquals("1", result); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...java/com/tencent/trpc/container/config/system/parser/DefaultPropertySourceParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.tencent.trpc.container.config.system.parser; | ||
|
||
import com.tencent.trpc.container.config.system.Configuration; | ||
import com.tencent.trpc.core.utils.YamlParser; | ||
import junit.framework.TestCase; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import java.util.Map; | ||
|
||
public class DefaultPropertySourceParserTest extends TestCase { | ||
|
||
@Test | ||
public void testGetFlattableMap() { | ||
Map<String, Object> yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); | ||
DefaultPropertySourceParser propertySourceParser = new DefaultPropertySourceParser(); | ||
Map<String, Object> flattableMap = propertySourceParser.getFlattableMap(yamlConfigMap); | ||
Assert.assertEquals(146, flattableMap.size()); | ||
} | ||
|
||
@Test | ||
public void testParseFlattableMap() { | ||
Map<String, Object> yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); | ||
DefaultPropertySourceParser propertySourceParser = new DefaultPropertySourceParser(); | ||
Map<String, Object> stringObjectMap = propertySourceParser.parseFlattableMap(yamlConfigMap); | ||
Assert.assertEquals(4, stringObjectMap.size()); | ||
Boolean aBoolean = Configuration.toBooleanObject(true); | ||
Assert.assertTrue(aBoolean); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...default/src/test/java/com/tencent/trpc/container/config/yaml/BackendConfigParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making tRPC available. | ||
* | ||
* 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, | ||
* please note that tRPC source code is licensed under the Apache 2.0 License, | ||
* A copy of the Apache 2.0 License can be found in the LICENSE file. | ||
*/ | ||
|
||
package com.tencent.trpc.container.config.yaml; | ||
|
||
import com.tencent.trpc.core.common.config.BackendConfig; | ||
import com.tencent.trpc.core.utils.YamlParser; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* BackendConfig parser. | ||
*/ | ||
public class BackendConfigParserTest { | ||
|
||
@Test | ||
public void testParseConfigMap() { | ||
BackendConfigParser backendConfigParser = new BackendConfigParser(); | ||
Assert.assertNotNull(backendConfigParser); | ||
Map<String, Object> yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); | ||
List<Map<String, Object>> maps = Arrays.asList(yamlConfigMap); | ||
Map<String, BackendConfig> stringBackendConfigMap = BackendConfigParser.parseConfigMap(maps); | ||
Assert.assertNotNull(stringBackendConfigMap); | ||
} | ||
|
||
@Test | ||
public void testParseConfig() { | ||
Map<String, Object> yamlConfigMap = YamlParser.parseAsFromClassPath("trpc_java_config.yaml", Map.class); | ||
BackendConfig backendConfig = BackendConfigParser.parseConfig(yamlConfigMap); | ||
Assert.assertNotNull(backendConfig); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...-default/src/test/java/com/tencent/trpc/container/config/yaml/ClientConfigParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.tencent.trpc.container.config.yaml; | ||
|
||
import com.tencent.trpc.container.config.YamlUtils; | ||
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 java.util.Map; | ||
|
||
public class ClientConfigParserTest { | ||
|
||
@Test | ||
public void testParseClientConfig() { | ||
ClientConfigParser clientConfigParser = new ClientConfigParser(); | ||
Assert.assertNotNull(clientConfigParser); | ||
Map<String, Object> 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()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...-default/src/test/java/com/tencent/trpc/container/config/yaml/GlobalConfigParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.tencent.trpc.container.config.yaml; | ||
|
||
import com.tencent.trpc.container.config.YamlUtils; | ||
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 java.util.Map; | ||
|
||
public class GlobalConfigParserTest extends TestCase { | ||
|
||
@Test | ||
public void testParseGlobalConfig() { | ||
GlobalConfigParser globalConfigParser = new GlobalConfigParser(); | ||
Assert.assertNotNull(globalConfigParser); | ||
Map<String, Object> yamlConfigMap = YamlParser.parseAsFromClassPath("listener_default.yaml", Map.class); | ||
YamlUtils yamlUtils = new YamlUtils("Label[]"); | ||
Map<String, Object> map = yamlUtils.getMap(yamlConfigMap, ConfigConstants.GLOBAL); | ||
GlobalConfig globalConfig = GlobalConfigParser.parseGlobalConfig(map); | ||
Assert.assertNotNull(globalConfig.getNamespace()); | ||
Assert.assertNotNull(globalConfig.getEnvName()); | ||
GlobalConfigParser.parseGlobalConfig(null); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...iner-default/src/test/java/com/tencent/trpc/container/config/yaml/ParseErrorInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.tencent.trpc.container.config.yaml; | ||
|
||
import junit.framework.TestCase; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ParseErrorInfoTest extends TestCase { | ||
|
||
@Test | ||
public void testInfo() { | ||
ParseErrorInfo parseErrorInfo = new ParseErrorInfo(); | ||
Assert.assertNotNull(parseErrorInfo); | ||
String info = ParseErrorInfo.info("key", "value"); | ||
Assert.assertNotNull(info); | ||
} | ||
|
||
@Test | ||
public void testTestInfo() { | ||
String info = ParseErrorInfo.info("key", "index", "value"); | ||
Assert.assertNotNull(info); | ||
} | ||
} |
Oops, something went wrong.