This is an automated email from the ASF dual-hosted git repository. zhangliang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new 120d4f5f120 Add unit test for Bootstrap use proxy default port from props (#17707) 120d4f5f120 is described below commit 120d4f5f12093ac14c6e37d5d3e03da85623d010 Author: galaxy <galaxy...@tencent.com> AuthorDate: Mon May 16 20:31:39 2022 +0800 Add unit test for Bootstrap use proxy default port from props (#17707) * Add unit test for Bootstrap use proxy default port from props(#17003) * Fix Bootstrap unit test proxy default port bug (#17003) --- .../proxy/arguments/BootstrapArgumentsTest.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java index 368b7e20800..8895ae4d1cb 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java +++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arguments/BootstrapArgumentsTest.java @@ -17,9 +17,15 @@ package org.apache.shardingsphere.proxy.arguments; +import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; +import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; +import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader; +import org.apache.shardingsphere.proxy.backend.config.YamlProxyConfiguration; import org.junit.Test; +import java.io.IOException; import java.util.Optional; +import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; @@ -62,4 +68,19 @@ public final class BootstrapArgumentsTest { assertThat(new BootstrapArguments(new String[]{"3306", "test_conf/"}).getConfigurationPath(), is("/test_conf/")); assertThat(new BootstrapArguments(new String[]{"3306", "/test_conf/"}).getConfigurationPath(), is("/test_conf/")); } + + private Properties createProperties() { + Properties result = new Properties(); + result.setProperty("proxy-default-port", "3306"); + return result; + } + + @Test + public void assertGetPortWithConfiguration() throws IOException { + BootstrapArguments bootstrapArgs = new BootstrapArguments(new String[]{}); + YamlProxyConfiguration yamlConfig = ProxyConfigurationLoader.load("/conf/local"); + yamlConfig.getServerConfiguration().setProps(createProperties()); + int port = bootstrapArgs.getPort().orElseGet(() -> new ConfigurationProperties(yamlConfig.getServerConfiguration().getProps()).getValue(ConfigurationPropertyKey.PROXY_DEFAULT_PORT)); + assertThat(port, is(3306)); + } }