From e02e0e4986f50e76470d2ee989500ab4ea4f7678 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 3 Jan 2023 22:40:56 +0800 Subject: [PATCH] Use PropertiesBuilder in all modules (#23308) * Use PropertiesBuilder in agent module * Use PropertiesBuilder in distsql module * Use PropertiesBuilder in binder module * Use PropertiesBuilder in common module * Use PropertiesBuilder in context module * Use PropertiesBuilder in util module * Use PropertiesBuilder in authority module * Use PropertiesBuilder in data-pipeline module * Use PropertiesBuilder in traffic module * Use PropertiesBuilder in transaction module * Use PropertiesBuilder in mode module * Use PropertiesBuilder in proxy module * Use PropertiesBuilder in test module * Use PropertiesBuilder in test module * Use PropertiesBuilder in all modules * For code format --- agent/plugins/metrics/type/prometheus/pom.xml | 7 ++++ .../PrometheusPluginBootServiceTest.java | 11 ++---- agent/plugins/tracing/type/jaeger/pom.xml | 7 ++++ .../JaegerTracingPluginBootServiceTest.java | 18 ++++----- .../tracing/type/opentelemetry/pom.xml | 7 ++++ ...TelemetryTracingPluginBootServiceTest.java | 26 +++++-------- .../plugins/tracing/type/opentracing/pom.xml | 7 ++++ .../OpenTracingPluginBootServiceTest.java | 12 ++---- distsql/statement/pom.xml | 7 ++++ .../DataSourceSegmentsConverterTest.java | 5 ++- .../ShardingRuleStatementCheckerTest.java | 2 +- infra/binder/pom.xml | 8 +++- .../SQLFederationDeciderEngineTest.java | 22 +++++------ infra/common/pom.xml | 6 +++ .../ShardingSphereAlgorithmFactoryTest.java | 9 ++--- .../props/ConfigurationPropertiesTest.java | 39 ++++++++++--------- .../metadata/url/JdbcUrlAppenderTest.java | 17 +++----- .../database/type/DatabaseTypeEngineTest.java | 5 ++- .../type/DBCPDataSourcePoolCreatorTest.java | 13 ++----- .../type/HikariDataSourcePoolCreatorTest.java | 14 ++----- ...YamlAlgorithmConfigurationSwapperTest.java | 14 ++----- infra/context/pom.xml | 6 +++ .../context/kernel/KernelProcessorTest.java | 11 ++---- infra/util/pom.xml | 7 ++++ .../util/props/PropertiesConverterTest.java | 7 ++-- .../infra/util/props/TypedPropertiesTest.java | 33 ++++++++-------- .../spi/type/typed/TypedSPIRegistryTest.java | 10 ++--- kernel/authority/core/pom.xml | 7 ++++ ...mittedPrivilegesProviderAlgorithmTest.java | 12 +++--- kernel/data-pipeline/core/pom.xml | 7 ++++ .../MemoryPipelineChannelCreatorTest.java | 6 +-- ...pelineProcessConfigurationSwapperTest.java | 29 ++++++-------- kernel/traffic/core/pom.xml | 7 ++++ .../segment/SQLMatchTrafficAlgorithmTest.java | 13 ++----- .../segment/SQLRegexTrafficAlgorithmTest.java | 13 ++----- .../traffic/rule/TrafficRuleTest.java | 7 ++-- kernel/traffic/distsql/handler/pom.xml | 7 ++++ .../query/TrafficRuleResultSetTest.java | 12 ++---- .../AlterTrafficRuleStatementUpdaterTest.java | 14 +++---- ...CreateTrafficRuleStatementUpdaterTest.java | 14 +++---- .../DropTrafficRuleStatementUpdaterTest.java | 12 ++---- kernel/transaction/distsql/handler/pom.xml | 7 ++++ .../query/TransactionRuleResultSetTest.java | 11 ++---- ...erTransactionRuleStatementUpdaterTest.java | 12 ++---- mode/core/pom.xml | 6 +++ .../ContextManagerBuilderParameterTest.java | 12 ++---- .../mode/manager/ContextManagerTest.java | 6 +-- .../persist/MetaDataPersistServiceTest.java | 13 ++----- mode/type/cluster/core/pom.xml | 6 +++ .../ClusterWorkerIdGeneratorTest.java | 6 +-- .../ConfigurationChangedSubscriberTest.java | 6 +-- mode/type/cluster/repository/api/pom.xml | 7 ++++ .../props/DefaultLockTypedPropertiesTest.java | 8 ++-- .../repository/provider/consul/pom.xml | 6 +++ .../consul/props/ConsulPropertiesTest.java | 11 ++---- .../cluster/repository/provider/etcd/pom.xml | 6 +++ .../etcd/props/EtcdPropertiesTest.java | 10 ++--- .../cluster/repository/provider/nacos/pom.xml | 6 +++ .../nacos/props/NacosPropertiesTest.java | 13 ++++--- .../repository/provider/zookeeper/pom.xml | 6 +++ .../zookeeper/ZookeeperRepositoryTest.java | 33 +++++++--------- .../props/ZookeeperPropertiesTest.java | 15 +++---- mode/type/standalone/core/pom.xml | 6 +++ .../StandaloneWorkerIdGeneratorTest.java | 10 ++--- .../repository/provider/jdbc/core/pom.xml | 7 ++++ .../standalone/jdbc/JDBCRepositoryTest.java | 18 ++++----- .../repository/provider/jdbc/h2/pom.xml | 7 ++++ .../standalone/h2/H2JDBCRepositoryTest.java | 12 +++--- .../repository/provider/jdbc/mysql/pom.xml | 8 ++++ .../MySQLJDBCRepositoryProviderTest.java | 17 ++++---- proxy/backend/pom.xml | 6 +++ .../DistSQLBackendHandlerFactoryTest.java | 10 ++--- ...xportDatabaseConfigurationHandlerTest.java | 16 +++----- .../ShowComputeNodeModeHandlerTest.java | 11 ++---- .../ShowDistVariableBackendHandlerTest.java | 11 +++--- .../ShowDistVariablesHandlerTest.java | 8 ++-- .../RefreshTableMetaDataHandlerTest.java | 32 ++++----------- .../SetDistVariableBackendHandlerTest.java | 14 +++---- proxy/frontend/core/pom.xml | 6 +++ .../FrontDatabaseProtocolTypeFactoryTest.java | 13 +++---- test/e2e/pipeline/pom.xml | 7 ++++ .../cases/base/PipelineBaseE2EIT.java | 12 +++--- .../cases/task/PostgreSQLIncrementTask.java | 7 ++-- .../compose/NativeContainerComposer.java | 9 +++-- 84 files changed, 489 insertions(+), 454 deletions(-) diff --git a/agent/plugins/metrics/type/prometheus/pom.xml b/agent/plugins/metrics/type/prometheus/pom.xml index 399b9005b4964..c201837cb7bc6 100644 --- a/agent/plugins/metrics/type/prometheus/pom.xml +++ b/agent/plugins/metrics/type/prometheus/pom.xml @@ -64,6 +64,13 @@ provided + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + io.prometheus simpleclient diff --git a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginBootServiceTest.java b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginBootServiceTest.java index 23d9f776ed3ca..8e9304eee2b4c 100644 --- a/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginBootServiceTest.java +++ b/agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/PrometheusPluginBootServiceTest.java @@ -31,13 +31,14 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.After; import org.junit.Test; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; -import java.util.Properties; import static org.mockito.Mockito.mock; @@ -57,13 +58,7 @@ public void assertStart() throws IOException { new ComputeNodeInstance(mock(InstanceMetaData.class)), new StandaloneWorkerIdGenerator(), new ModeConfiguration("Standalone", null), mock(ModeContextManager.class), mock(LockContext.class), new EventBusContext()); ProxyContext.init(new ContextManager(metaDataContexts, instanceContext)); - pluginBootService.start(new PluginConfiguration("localhost", 8090, "", createProperties()), true); + pluginBootService.start(new PluginConfiguration("localhost", 8090, "", PropertiesBuilder.build(new Property("JVM_INFORMATION_COLLECTOR_ENABLED", Boolean.TRUE.toString()))), true); new Socket().connect(new InetSocketAddress("localhost", 8090)); } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("JVM_INFORMATION_COLLECTOR_ENABLED", Boolean.TRUE.toString()); - return result; - } } diff --git a/agent/plugins/tracing/type/jaeger/pom.xml b/agent/plugins/tracing/type/jaeger/pom.xml index 5030b490788bb..ff183b5250127 100644 --- a/agent/plugins/tracing/type/jaeger/pom.xml +++ b/agent/plugins/tracing/type/jaeger/pom.xml @@ -32,6 +32,13 @@ + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + io.opentracing opentracing-api diff --git a/agent/plugins/tracing/type/jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/JaegerTracingPluginBootServiceTest.java b/agent/plugins/tracing/type/jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/JaegerTracingPluginBootServiceTest.java index 448b91be5b19e..739c4af40a751 100644 --- a/agent/plugins/tracing/type/jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/JaegerTracingPluginBootServiceTest.java +++ b/agent/plugins/tracing/type/jaeger/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/JaegerTracingPluginBootServiceTest.java @@ -20,6 +20,8 @@ import io.opentracing.noop.NoopTracerFactory; import io.opentracing.util.GlobalTracer; import org.apache.shardingsphere.agent.api.PluginConfiguration; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.After; import org.junit.Test; import org.mockito.internal.configuration.plugins.Plugins; @@ -40,16 +42,12 @@ public void close() throws ReflectiveOperationException { @Test public void assertStart() { - pluginBootService.start(new PluginConfiguration("localhost", 5775, "", createProperties()), true); + Properties props = PropertiesBuilder.build( + new Property("JAEGER_SAMPLER_TYPE", "const"), + new Property("JAEGER_SAMPLER_PARAM", "1"), + new Property("JAEGER_REPORTER_LOG_SPANS", Boolean.TRUE.toString()), + new Property("JAEGER_REPORTER_FLUSH_INTERVAL", "1")); + pluginBootService.start(new PluginConfiguration("localhost", 5775, "", props), true); assertTrue(GlobalTracer.isRegistered()); } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("JAEGER_SAMPLER_TYPE", "const"); - result.setProperty("JAEGER_SAMPLER_PARAM", "1"); - result.setProperty("JAEGER_REPORTER_LOG_SPANS", Boolean.TRUE.toString()); - result.setProperty("JAEGER_REPORTER_FLUSH_INTERVAL", "1"); - return result; - } } diff --git a/agent/plugins/tracing/type/opentelemetry/pom.xml b/agent/plugins/tracing/type/opentelemetry/pom.xml index fae1a87990638..c8b1e5ebcf536 100644 --- a/agent/plugins/tracing/type/opentelemetry/pom.xml +++ b/agent/plugins/tracing/type/opentelemetry/pom.xml @@ -33,6 +33,13 @@ + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + io.opentelemetry opentelemetry-api diff --git a/agent/plugins/tracing/type/opentelemetry/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginBootServiceTest.java b/agent/plugins/tracing/type/opentelemetry/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginBootServiceTest.java index c6ed4d5aac7c4..cbf61baa1bee8 100644 --- a/agent/plugins/tracing/type/opentelemetry/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginBootServiceTest.java +++ b/agent/plugins/tracing/type/opentelemetry/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentelemetry/OpenTelemetryTracingPluginBootServiceTest.java @@ -19,34 +19,28 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import org.apache.shardingsphere.agent.api.PluginConfiguration; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.After; import org.junit.Test; -import java.util.Properties; - import static org.junit.Assert.assertNotNull; public final class OpenTelemetryTracingPluginBootServiceTest { private final OpenTelemetryTracingPluginBootService pluginBootService = new OpenTelemetryTracingPluginBootService(); - @Test - public void assertStart() { - pluginBootService.start(new PluginConfiguration(null, 0, null, createProperties()), true); - assertNotNull(GlobalOpenTelemetry.getTracerProvider()); - assertNotNull(GlobalOpenTelemetry.getTracer("shardingsphere-agent")); - } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("otel.resource.attributes", "service.name=shardingsphere-agent"); - result.setProperty("otel.traces.exporter", "zipkin"); - return result; - } - @After public void close() { pluginBootService.close(); GlobalOpenTelemetry.resetForTest(); } + + @Test + public void assertStart() { + pluginBootService.start(new PluginConfiguration(null, 0, null, + PropertiesBuilder.build(new Property("otel.resource.attributes", "service.name=shardingsphere-agent"), new Property("otel.traces.exporter", "zipkin"))), true); + assertNotNull(GlobalOpenTelemetry.getTracerProvider()); + assertNotNull(GlobalOpenTelemetry.getTracer("shardingsphere-agent")); + } } diff --git a/agent/plugins/tracing/type/opentracing/pom.xml b/agent/plugins/tracing/type/opentracing/pom.xml index 225822d66d0be..c15282cd72050 100644 --- a/agent/plugins/tracing/type/opentracing/pom.xml +++ b/agent/plugins/tracing/type/opentracing/pom.xml @@ -28,6 +28,13 @@ ${project.artifactId} + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + io.opentracing opentracing-api diff --git a/agent/plugins/tracing/type/opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/OpenTracingPluginBootServiceTest.java b/agent/plugins/tracing/type/opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/OpenTracingPluginBootServiceTest.java index 3370d21113c5e..887c2526cf174 100644 --- a/agent/plugins/tracing/type/opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/OpenTracingPluginBootServiceTest.java +++ b/agent/plugins/tracing/type/opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/OpenTracingPluginBootServiceTest.java @@ -19,11 +19,11 @@ import io.opentracing.util.GlobalTracer; import org.apache.shardingsphere.agent.api.PluginConfiguration; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.After; import org.junit.Test; -import java.util.Properties; - import static org.junit.Assert.assertTrue; public final class OpenTracingPluginBootServiceTest { @@ -37,13 +37,7 @@ public void close() { @Test public void assertStart() { - pluginBootService.start(new PluginConfiguration("localhost", 8090, "", createProperties()), true); + pluginBootService.start(new PluginConfiguration("localhost", 8090, "", PropertiesBuilder.build(new Property("opentracing-tracer-class-name", "io.opentracing.mock.MockTracer"))), true); assertTrue(GlobalTracer.isRegistered()); } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("opentracing-tracer-class-name", "io.opentracing.mock.MockTracer"); - return result; - } } diff --git a/distsql/statement/pom.xml b/distsql/statement/pom.xml index 968a7e2de79bc..f070deaee1b55 100644 --- a/distsql/statement/pom.xml +++ b/distsql/statement/pom.xml @@ -38,5 +38,12 @@ shardingsphere-sql-parser-statement ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/parser/segment/converter/DataSourceSegmentsConverterTest.java b/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/parser/segment/converter/DataSourceSegmentsConverterTest.java index b8947894a4e80..6a6b69b02c36d 100644 --- a/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/parser/segment/converter/DataSourceSegmentsConverterTest.java +++ b/distsql/statement/src/test/java/org/apache/shardingsphere/distsql/parser/segment/converter/DataSourceSegmentsConverterTest.java @@ -22,6 +22,8 @@ import org.apache.shardingsphere.distsql.parser.segment.URLBasedDataSourceSegment; import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Arrays; @@ -47,8 +49,7 @@ public void assertConvert() { private Collection createDataSourceSegments() { Collection result = new LinkedList<>(); - Properties customPoolProps = new Properties(); - customPoolProps.setProperty("maxPoolSize", "30"); + Properties customPoolProps = PropertiesBuilder.build(new Property("maxPoolSize", "30")); result.add(new HostnameAndPortBasedDataSourceSegment("ds0", "127.0.0.1", "3306", "demo_ds_0", "root0", "root0", customPoolProps)); result.add(new URLBasedDataSourceSegment("ds1", "jdbc:mysql://127.0.0.1:3306/demo_ds_1?useSSL=false", "root1", "root1", customPoolProps)); return result; diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java index 83467c509d2eb..24ece07795a7a 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/checker/ShardingRuleStatementCheckerTest.java @@ -293,7 +293,7 @@ private TableRuleSegment createCompleteTableRule() { Properties props = new Properties(); result.setTableStrategySegment(new ShardingStrategySegment("hint", "product_id", new AlgorithmSegment("CORE.HINT.FIXTURE", props))); result.setDatabaseStrategySegment(new ShardingStrategySegment("hint", "product_id", new AlgorithmSegment("CORE.HINT.FIXTURE", props))); - result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()))); + result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", props))); return result; } } diff --git a/infra/binder/pom.xml b/infra/binder/pom.xml index 03f8b7f487e30..097ef54036d13 100644 --- a/infra/binder/pom.xml +++ b/infra/binder/pom.xml @@ -38,7 +38,6 @@ shardingsphere-sql-parser-engine ${project.version} - org.apache.shardingsphere shardingsphere-infra-parser @@ -49,5 +48,12 @@ shardingsphere-infra-common ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngineTest.java index daa034ea5e1c5..364283d2a5f90 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngineTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/decider/engine/SQLFederationDeciderEngineTest.java @@ -32,6 +32,8 @@ import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Arrays; @@ -74,9 +76,8 @@ public void assertDecideWhenNotConfigSqlFederationEnabled() { @Test public void assertDecideWhenExecuteNotSelectStatement() { Collection rules = Collections.singletonList(new SQLFederationDeciderRuleMatchFixture()); - Properties props = new Properties(); - props.put(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL"); - SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, new ConfigurationProperties(props)); + SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, + new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL")))); QueryContext queryContext = new QueryContext(mock(CommonSQLStatementContext.class), "", Collections.emptyList()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(rules), Collections.emptyMap()); @@ -87,9 +88,8 @@ public void assertDecideWhenExecuteNotSelectStatement() { @Test public void assertDecideWhenConfigSingleMatchedRule() { Collection rules = Collections.singletonList(new SQLFederationDeciderRuleMatchFixture()); - Properties props = new Properties(); - props.put(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL"); - SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, new ConfigurationProperties(props)); + SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, + new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL")))); QueryContext queryContext = new QueryContext(mock(SelectStatementContext.class, RETURNS_DEEP_STUBS), "", Collections.emptyList()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(rules), Collections.emptyMap()); @@ -100,9 +100,8 @@ public void assertDecideWhenConfigSingleMatchedRule() { @Test public void assertDecideWhenConfigSingleNotMatchedRule() { Collection rules = Collections.singletonList(new SQLFederationDeciderRuleNotMatchFixture()); - Properties props = new Properties(); - props.put(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL"); - SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, new ConfigurationProperties(props)); + SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, + new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL")))); QueryContext queryContext = new QueryContext(mock(SelectStatementContext.class, RETURNS_DEEP_STUBS), "", Collections.emptyList()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(rules), Collections.emptyMap()); @@ -113,9 +112,8 @@ public void assertDecideWhenConfigSingleNotMatchedRule() { @Test public void assertDecideWhenConfigMultiRule() { Collection rules = Arrays.asList(new SQLFederationDeciderRuleNotMatchFixture(), new SQLFederationDeciderRuleMatchFixture()); - Properties props = new Properties(); - props.put(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL"); - SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, new ConfigurationProperties(props)); + SQLFederationDeciderEngine deciderEngine = new SQLFederationDeciderEngine(rules, + new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL")))); QueryContext queryContext = new QueryContext(mock(SelectStatementContext.class, RETURNS_DEEP_STUBS), "", Collections.emptyList()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(rules), Collections.emptyMap()); diff --git a/infra/common/pom.xml b/infra/common/pom.xml index c3942a8add79f..77603d209738a 100644 --- a/infra/common/pom.xml +++ b/infra/common/pom.xml @@ -46,6 +46,12 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + com.h2database diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactoryTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactoryTest.java index a2941a294a829..56f565eedccd7 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactoryTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithmFactoryTest.java @@ -19,10 +19,10 @@ import org.apache.shardingsphere.infra.algorithm.fixture.ShardingSphereAlgorithmFixture; import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; -import java.util.Properties; - import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,9 +31,8 @@ public final class ShardingSphereAlgorithmFactoryTest { @Test public void assertCreateAlgorithm() { - Properties props = new Properties(); - props.setProperty("key", "value"); - ShardingSphereAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("FIXTURE", props), ShardingSphereAlgorithm.class); + ShardingSphereAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm( + new AlgorithmConfiguration("FIXTURE", PropertiesBuilder.build(new Property("key", "value"))), ShardingSphereAlgorithm.class); assertThat(actual, instanceOf(ShardingSphereAlgorithmFixture.class)); assertThat(((ShardingSphereAlgorithmFixture) actual).getTestValue(), is("value")); } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java index f6751156f2327..a7d2f44db9106 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/props/ConfigurationPropertiesTest.java @@ -17,13 +17,15 @@ package org.apache.shardingsphere.infra.config.props; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public final class ConfigurationPropertiesTest { @@ -50,24 +52,23 @@ public void assertGetValue() { } private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString()); - result.setProperty(ConfigurationPropertyKey.SQL_SIMPLE.getKey(), Boolean.TRUE.toString()); - result.setProperty(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE.getKey(), "20"); - result.setProperty(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY.getKey(), "20"); - result.setProperty(ConfigurationPropertyKey.CHECK_TABLE_META_DATA_ENABLED.getKey(), Boolean.TRUE.toString()); - result.setProperty(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL"); - result.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(), "PostgreSQL"); - result.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD.getKey(), "20"); - result.setProperty(ConfigurationPropertyKey.PROXY_HINT_ENABLED.getKey(), Boolean.TRUE.toString()); - result.setProperty(ConfigurationPropertyKey.PROXY_BACKEND_QUERY_FETCH_SIZE.getKey(), "20"); - result.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_EXECUTOR_SIZE.getKey(), "20"); - result.setProperty(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), BackendExecutorType.OLTP.name()); - result.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_MAX_CONNECTIONS.getKey(), "20"); - result.setProperty(ConfigurationPropertyKey.PROXY_MYSQL_DEFAULT_VERSION.getKey(), "5.7.22"); - result.setProperty(ConfigurationPropertyKey.PROXY_DEFAULT_PORT.getKey(), "3308"); - result.setProperty(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG.getKey(), "1024"); - return result; + return PropertiesBuilder.build( + new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString()), + new Property(ConfigurationPropertyKey.SQL_SIMPLE.getKey(), Boolean.TRUE.toString()), + new Property(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE.getKey(), "20"), + new Property(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY.getKey(), "20"), + new Property(ConfigurationPropertyKey.CHECK_TABLE_META_DATA_ENABLED.getKey(), Boolean.TRUE.toString()), + new Property(ConfigurationPropertyKey.SQL_FEDERATION_TYPE.getKey(), "ORIGINAL"), + new Property(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(), "PostgreSQL"), + new Property(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD.getKey(), "20"), + new Property(ConfigurationPropertyKey.PROXY_HINT_ENABLED.getKey(), Boolean.TRUE.toString()), + new Property(ConfigurationPropertyKey.PROXY_BACKEND_QUERY_FETCH_SIZE.getKey(), "20"), + new Property(ConfigurationPropertyKey.PROXY_FRONTEND_EXECUTOR_SIZE.getKey(), "20"), + new Property(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), BackendExecutorType.OLTP.name()), + new Property(ConfigurationPropertyKey.PROXY_FRONTEND_MAX_CONNECTIONS.getKey(), "20"), + new Property(ConfigurationPropertyKey.PROXY_MYSQL_DEFAULT_VERSION.getKey(), "5.7.22"), + new Property(ConfigurationPropertyKey.PROXY_DEFAULT_PORT.getKey(), "3308"), + new Property(ConfigurationPropertyKey.PROXY_NETTY_BACKLOG.getKey(), "1024")); } @Test diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/JdbcUrlAppenderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/JdbcUrlAppenderTest.java index 8d262b188bafa..404911e49fb8c 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/JdbcUrlAppenderTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/metadata/url/JdbcUrlAppenderTest.java @@ -17,10 +17,10 @@ package org.apache.shardingsphere.infra.database.metadata.url; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; -import java.util.Properties; - import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; @@ -29,7 +29,8 @@ public final class JdbcUrlAppenderTest { @Test public void assertAppendQueryPropertiesWithoutOriginalQueryProperties() { - String actual = new JdbcUrlAppender().appendQueryProperties("jdbc:mysql://192.168.0.1:3306/foo_ds", createQueryProperties()); + String actual = new JdbcUrlAppender().appendQueryProperties("jdbc:mysql://192.168.0.1:3306/foo_ds", + PropertiesBuilder.build(new Property("useSSL", Boolean.FALSE.toString()), new Property("rewriteBatchedStatements", Boolean.TRUE.toString()))); assertThat(actual, startsWith("jdbc:mysql://192.168.0.1:3306/foo_ds?")); assertThat(actual, containsString("rewriteBatchedStatements=true")); assertThat(actual, containsString("useSSL=false")); @@ -38,17 +39,11 @@ public void assertAppendQueryPropertiesWithoutOriginalQueryProperties() { @Test public void assertAppendQueryPropertiesWithOriginalQueryProperties() { String actual = new JdbcUrlAppender().appendQueryProperties( - "jdbc:mysql://192.168.0.1:3306/foo_ds?serverTimezone=UTC&useSSL=false&rewriteBatchedStatements=true", createQueryProperties()); + "jdbc:mysql://192.168.0.1:3306/foo_ds?serverTimezone=UTC&useSSL=false&rewriteBatchedStatements=true", + PropertiesBuilder.build(new Property("useSSL", Boolean.FALSE.toString()), new Property("rewriteBatchedStatements", Boolean.TRUE.toString()))); assertThat(actual, startsWith("jdbc:mysql://192.168.0.1:3306/foo_ds?")); assertThat(actual, containsString("serverTimezone=UTC")); assertThat(actual, containsString("rewriteBatchedStatements=true")); assertThat(actual, containsString("useSSL=false")); } - - private Properties createQueryProperties() { - Properties result = new Properties(); - result.put("useSSL", Boolean.FALSE.toString()); - result.put("rewriteBatchedStatements", Boolean.TRUE.toString()); - return result; - } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java index a2471bae54f12..ca695198302e1 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java @@ -28,6 +28,8 @@ import org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper.SQLWrapperException; import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import javax.sql.DataSource; @@ -50,8 +52,7 @@ public final class DatabaseTypeEngineTest { @Test public void assertGetProtocolTypeFromConfiguredProperties() { - Properties props = new Properties(); - props.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(), "MySQL"); + Properties props = PropertiesBuilder.build(new Property(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(), "MySQL")); DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), Collections.singleton(new FixtureRuleConfiguration())); assertThat(DatabaseTypeEngine.getProtocolType("sharding_db", databaseConfig, new ConfigurationProperties(props)), instanceOf(MySQLDatabaseType.class)); assertThat(DatabaseTypeEngine.getProtocolType(Collections.singletonMap("foo_db", databaseConfig), new ConfigurationProperties(props)), instanceOf(MySQLDatabaseType.class)); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/DBCPDataSourcePoolCreatorTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/DBCPDataSourcePoolCreatorTest.java index 74175bcac3479..1f54baf4cb4ad 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/DBCPDataSourcePoolCreatorTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/DBCPDataSourcePoolCreatorTest.java @@ -22,6 +22,8 @@ import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import org.mockito.internal.configuration.plugins.Plugins; @@ -40,7 +42,7 @@ public void assertCreateDataSource() { assertThat(actual.getUrl(), is("jdbc:mock://127.0.0.1/foo_ds")); assertThat(actual.getUsername(), is("root")); assertThat(actual.getPassword(), is("root")); - assertThat(getConnectionProperties(actual), is(createJdbcUrlProperties())); + assertThat(getConnectionProperties(actual), is(PropertiesBuilder.build(new Property("foo", "foo_value"), new Property("bar", "bar_value")))); } private Map createDataSourceProperties() { @@ -49,14 +51,7 @@ private Map createDataSourceProperties() { result.put("driverClassName", MockedDataSource.class.getName()); result.put("username", "root"); result.put("password", "root"); - result.put("connectionProperties", createJdbcUrlProperties()); - return result; - } - - private Properties createJdbcUrlProperties() { - Properties result = new Properties(); - result.put("foo", "foo_value"); - result.put("bar", "bar_value"); + result.put("connectionProperties", PropertiesBuilder.build(new Property("foo", "foo_value"), new Property("bar", "bar_value"))); return result; } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/HikariDataSourcePoolCreatorTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/HikariDataSourcePoolCreatorTest.java index bb5b34252edb9..4f72bd7db88e9 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/HikariDataSourcePoolCreatorTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/type/HikariDataSourcePoolCreatorTest.java @@ -21,11 +21,12 @@ import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator; import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,7 +39,7 @@ public void assertCreateDataSource() { assertThat(actual.getJdbcUrl(), is("jdbc:mock://127.0.0.1/foo_ds")); assertThat(actual.getUsername(), is("root")); assertThat(actual.getPassword(), is("root")); - assertThat(actual.getDataSourceProperties(), is(createJdbcUrlProperties())); + assertThat(actual.getDataSourceProperties(), is(PropertiesBuilder.build(new Property("foo", "foo_value"), new Property("bar", "bar_value")))); } private Map createDataSourceProperties() { @@ -47,14 +48,7 @@ private Map createDataSourceProperties() { result.put("driverClassName", MockedDataSource.class.getName()); result.put("username", "root"); result.put("password", "root"); - result.put("dataSourceProperties", createJdbcUrlProperties()); - return result; - } - - private Properties createJdbcUrlProperties() { - Properties result = new Properties(); - result.put("foo", "foo_value"); - result.put("bar", "bar_value"); + result.put("dataSourceProperties", PropertiesBuilder.build(new Property("foo", "foo_value"), new Property("bar", "bar_value"))); return result; } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/algorithm/YamlAlgorithmConfigurationSwapperTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/algorithm/YamlAlgorithmConfigurationSwapperTest.java index 345aceafdb44f..b705524971ab2 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/algorithm/YamlAlgorithmConfigurationSwapperTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/algorithm/YamlAlgorithmConfigurationSwapperTest.java @@ -19,10 +19,10 @@ import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; -import java.util.Properties; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -31,22 +31,16 @@ public final class YamlAlgorithmConfigurationSwapperTest { @Test public void assertSwapToYaml() { YamlAlgorithmConfiguration actual = new YamlAlgorithmConfigurationSwapper().swapToYamlConfiguration( - new AlgorithmConfiguration("TEST", createProps())); + new AlgorithmConfiguration("TEST", PropertiesBuilder.build(new Property("key", "value")))); assertThat(actual.getType(), is("TEST")); assertThat(actual.getProps().getProperty("key"), is("value")); } @Test public void assertSwapToObject() { - YamlAlgorithmConfiguration yamlConfig = new YamlAlgorithmConfiguration("TEST", createProps()); + YamlAlgorithmConfiguration yamlConfig = new YamlAlgorithmConfiguration("TEST", PropertiesBuilder.build(new Property("key", "value"))); AlgorithmConfiguration actual = new YamlAlgorithmConfigurationSwapper().swapToObject(yamlConfig); assertThat(actual.getType(), is("TEST")); assertThat(actual.getProps().getProperty("key"), is("value")); } - - private Properties createProps() { - Properties result = new Properties(); - result.setProperty("key", "value"); - return result; - } } diff --git a/infra/context/pom.xml b/infra/context/pom.xml index 49e3c7d59c966..34aba338e7b52 100644 --- a/infra/context/pom.xml +++ b/infra/context/pom.xml @@ -65,5 +65,11 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/infra/context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java b/infra/context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java index a442c1da16916..fa7a91f6c80d9 100644 --- a/infra/context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java +++ b/infra/context/src/test/java/org/apache/shardingsphere/infra/context/kernel/KernelProcessorTest.java @@ -32,10 +32,11 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement; import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Collections; -import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -53,15 +54,9 @@ public void assertGenerateExecutionContext() { QueryContext queryContext = new QueryContext(sqlStatementContext, "SELECT * FROM tbl", Collections.emptyList()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, mock(DatabaseType.class), mock(ShardingSphereResourceMetaData.class, RETURNS_DEEP_STUBS), new ShardingSphereRuleMetaData(Collections.singleton(mock(SQLTranslatorRule.class))), Collections.emptyMap()); - ConfigurationProperties props = new ConfigurationProperties(createProperties()); + ConfigurationProperties props = new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString()))); ExecutionContext actual = new KernelProcessor().generateExecutionContext(queryContext, database, new ShardingSphereRuleMetaData(Collections.singleton(mock(SQLTranslatorRule.class))), props, mock(ConnectionContext.class)); assertThat(actual.getExecutionUnits().size(), is(1)); } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString()); - return result; - } } diff --git a/infra/util/pom.xml b/infra/util/pom.xml index 5b1d4e5ff9b09..b27a1de450982 100644 --- a/infra/util/pom.xml +++ b/infra/util/pom.xml @@ -27,6 +27,13 @@ shardingsphere-infra-util + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + org.yaml snakeyaml diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/PropertiesConverterTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/PropertiesConverterTest.java index 676e33645ddb9..e51a12ecb3afe 100644 --- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/PropertiesConverterTest.java +++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/PropertiesConverterTest.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.infra.util.props; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -28,10 +30,7 @@ public final class PropertiesConverterTest { @Test public void assertConvert() { - Properties actual = new Properties(); - actual.setProperty("foo", "foo_value"); - actual.setProperty("bar", "bar_value"); - assertThat(PropertiesConverter.convert(actual), is("bar=bar_value,foo=foo_value")); + assertThat(PropertiesConverter.convert(PropertiesBuilder.build(new Property("foo", "foo_value"), new Property("bar", "bar_value"))), is("bar=bar_value,foo=foo_value")); } @Test diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java index a104168493a1d..7068ca5a652b4 100644 --- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java +++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/props/TypedPropertiesTest.java @@ -20,13 +20,15 @@ import org.apache.shardingsphere.infra.util.props.exception.TypedPropertiesServerException; import org.apache.shardingsphere.infra.util.props.fixture.TypedPropertiesFixture; import org.apache.shardingsphere.infra.util.props.fixture.TypedPropertyKeyFixture; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public final class TypedPropertiesTest { @@ -46,15 +48,14 @@ public void assertGetValue() { } private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(TypedPropertyKeyFixture.BOOLEAN_VALUE.getKey(), Boolean.TRUE.toString()); - result.setProperty(TypedPropertyKeyFixture.BOOLEAN_OBJECT_VALUE.getKey(), Boolean.TRUE.toString()); - result.setProperty(TypedPropertyKeyFixture.INT_VALUE.getKey(), "100"); - result.setProperty(TypedPropertyKeyFixture.INT_OBJECT_VALUE.getKey(), "100"); - result.setProperty(TypedPropertyKeyFixture.LONG_VALUE.getKey(), "10000"); - result.setProperty(TypedPropertyKeyFixture.LONG_OBJECT_VALUE.getKey(), "10000"); - result.setProperty(TypedPropertyKeyFixture.STRING_VALUE.getKey(), "new_value"); - return result; + return PropertiesBuilder.build( + new Property(TypedPropertyKeyFixture.BOOLEAN_VALUE.getKey(), Boolean.TRUE.toString()), + new Property(TypedPropertyKeyFixture.BOOLEAN_OBJECT_VALUE.getKey(), Boolean.TRUE.toString()), + new Property(TypedPropertyKeyFixture.INT_VALUE.getKey(), "100"), + new Property(TypedPropertyKeyFixture.INT_OBJECT_VALUE.getKey(), "100"), + new Property(TypedPropertyKeyFixture.LONG_VALUE.getKey(), "10000"), + new Property(TypedPropertyKeyFixture.LONG_OBJECT_VALUE.getKey(), "10000"), + new Property(TypedPropertyKeyFixture.STRING_VALUE.getKey(), "new_value")); } @Test @@ -71,12 +72,12 @@ public void assertGetDefaultValue() { @Test(expected = TypedPropertiesServerException.class) public void assertGetInvalidValue() { - Properties props = new Properties(); - props.setProperty(TypedPropertyKeyFixture.BOOLEAN_VALUE.getKey(), "test"); - props.setProperty(TypedPropertyKeyFixture.BOOLEAN_OBJECT_VALUE.getKey(), "test"); - props.setProperty(TypedPropertyKeyFixture.INT_VALUE.getKey(), "test"); - props.setProperty(TypedPropertyKeyFixture.INT_OBJECT_VALUE.getKey(), "test"); - props.setProperty(TypedPropertyKeyFixture.LONG_VALUE.getKey(), "test"); + Properties props = PropertiesBuilder.build( + new Property(TypedPropertyKeyFixture.BOOLEAN_VALUE.getKey(), "test"), + new Property(TypedPropertyKeyFixture.BOOLEAN_OBJECT_VALUE.getKey(), "test"), + new Property(TypedPropertyKeyFixture.INT_VALUE.getKey(), "test"), + new Property(TypedPropertyKeyFixture.INT_OBJECT_VALUE.getKey(), "test"), + new Property(TypedPropertyKeyFixture.LONG_VALUE.getKey(), "test")); new TypedPropertiesFixture(props); } } diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistryTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistryTest.java index 8a0efa4e2b114..0041cb97ef112 100644 --- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistryTest.java +++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistryTest.java @@ -20,6 +20,8 @@ import org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException; import org.apache.shardingsphere.infra.util.spi.type.typed.fixture.TypedSPIFixture; import org.apache.shardingsphere.infra.util.spi.type.typed.fixture.impl.TypedSPIFixtureImpl; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -50,16 +52,12 @@ public void assertGetRegisteredServiceWithoutProperties() { @Test public void assertGetRegisteredServiceWithProperties() { - Properties props = new Properties(); - props.put("key", 1); - TypedSPIFixtureImpl actual = (TypedSPIFixtureImpl) TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", props); - assertThat(actual.getValue(), is("1")); + assertThat(((TypedSPIFixtureImpl) TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", PropertiesBuilder.build(new Property("key", "1")))).getValue(), is("1")); } @Test public void assertGetRegisteredServiceWithNullProperties() { - TypedSPIFixtureImpl actual = (TypedSPIFixtureImpl) TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", null); - assertNull(actual.getValue()); + assertNull(((TypedSPIFixtureImpl) TypedSPIRegistry.getRegisteredService(TypedSPIFixture.class, "TYPED.FIXTURE", null)).getValue()); } @Test diff --git a/kernel/authority/core/pom.xml b/kernel/authority/core/pom.xml index af6892a7e27ac..f8d98f013087f 100644 --- a/kernel/authority/core/pom.xml +++ b/kernel/authority/core/pom.xml @@ -38,5 +38,12 @@ shardingsphere-infra-executor ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java index ad443988d8893..2e8a3694d9ac1 100644 --- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java +++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/provider/schema/DatabasePermittedPrivilegesProviderAlgorithmTest.java @@ -25,6 +25,8 @@ import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Collections; @@ -37,18 +39,14 @@ public final class DatabasePermittedPrivilegesProviderAlgorithmTest { @Test public void assertBuildAuthorityRegistry() { + Properties props = PropertiesBuilder.build( + new Property(DatabasePermittedPrivilegesProviderAlgorithm.PROP_USER_DATABASE_MAPPINGS, "root@localhost=test, user1@127.0.0.1=db_dal_admin, user1@=test, user1@=test1, user1@=*")); DatabasePermittedPrivilegesProviderAlgorithm algorithm = ShardingSphereAlgorithmFactory.createAlgorithm( - new AlgorithmConfiguration("DATABASE_PERMITTED", createProperties()), AuthorityProviderAlgorithm.class); + new AlgorithmConfiguration("DATABASE_PERMITTED", props), AuthorityProviderAlgorithm.class); AuthorityRegistry actual = algorithm.buildAuthorityRegistry(Collections.emptyMap(), Collections.singletonList(new ShardingSphereUser("user1", "", "127.0.0.2"))); Optional privileges = actual.findPrivileges(new Grantee("user1", "127.0.0.2")); assertTrue(privileges.isPresent()); assertTrue(privileges.get().hasPrivileges("test")); assertTrue(privileges.get().hasPrivileges("db_dal_admin")); } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(DatabasePermittedPrivilegesProviderAlgorithm.PROP_USER_DATABASE_MAPPINGS, "root@localhost=test, user1@127.0.0.1=db_dal_admin, user1@=test, user1@=test1, user1@=*"); - return result; - } } diff --git a/kernel/data-pipeline/core/pom.xml b/kernel/data-pipeline/core/pom.xml index 1d430e9cbdacf..1f7f2ed97ac8f 100644 --- a/kernel/data-pipeline/core/pom.xml +++ b/kernel/data-pipeline/core/pom.xml @@ -64,5 +64,12 @@ shardingsphere-cluster-mode-repository-zookeeper ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/MemoryPipelineChannelCreatorTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/MemoryPipelineChannelCreatorTest.java index 62f4e7cb25d6c..60ee0874122cf 100644 --- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/MemoryPipelineChannelCreatorTest.java +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/channel/memory/MemoryPipelineChannelCreatorTest.java @@ -19,6 +19,8 @@ import org.apache.shardingsphere.data.pipeline.api.ingest.channel.AckCallback; import org.apache.shardingsphere.data.pipeline.spi.ingest.channel.PipelineChannelCreator; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import org.mockito.internal.configuration.plugins.Plugins; @@ -33,10 +35,8 @@ public final class MemoryPipelineChannelCreatorTest { @Test public void assertInitWithBlockQueueSize() throws Exception { - Properties props = new Properties(); - props.setProperty("block-queue-size", "200"); PipelineChannelCreator creator = new MemoryPipelineChannelCreator(); - creator.init(props); + creator.init(PropertiesBuilder.build(new Property("block-queue-size", "200"))); assertThat(Plugins.getMemberAccessor().get(MemoryPipelineChannelCreator.class.getDeclaredField("blockQueueSize"), creator), is(200)); } diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/yaml/process/YamlPipelineProcessConfigurationSwapperTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/yaml/process/YamlPipelineProcessConfigurationSwapperTest.java index ac4f7062286e5..d3deb82385407 100644 --- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/yaml/process/YamlPipelineProcessConfigurationSwapperTest.java +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/yaml/process/YamlPipelineProcessConfigurationSwapperTest.java @@ -22,10 +22,10 @@ import org.apache.shardingsphere.data.pipeline.api.config.process.PipelineWriteConfiguration; import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlAlgorithmConfiguration; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; -import java.util.Properties; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertNull; @@ -51,32 +51,25 @@ public void assertSwapToObject() { } private YamlPipelineProcessConfiguration createYamlConfiguration() { - Properties rateLimiterProps = new Properties(); - rateLimiterProps.setProperty("batch-size", "1000"); - rateLimiterProps.setProperty("qps", "50"); YamlPipelineReadConfiguration yamlInputConfig = YamlPipelineReadConfiguration.buildWithDefaultValue(); - yamlInputConfig.setRateLimiter(new YamlAlgorithmConfiguration("INPUT", rateLimiterProps)); + yamlInputConfig.setRateLimiter(new YamlAlgorithmConfiguration("INPUT", PropertiesBuilder.build(new Property("batch-size", "1000"), new Property("qps", "50")))); YamlPipelineProcessConfiguration result = new YamlPipelineProcessConfiguration(); result.setRead(yamlInputConfig); YamlPipelineWriteConfiguration yamlOutputConfig = YamlPipelineWriteConfiguration.buildWithDefaultValue(); - yamlOutputConfig.setRateLimiter(new YamlAlgorithmConfiguration("OUTPUT", rateLimiterProps)); + yamlOutputConfig.setRateLimiter(new YamlAlgorithmConfiguration("OUTPUT", PropertiesBuilder.build(new Property("batch-size", "1000"), new Property("qps", "50")))); result.setWrite(yamlOutputConfig); - Properties streamChannelProps = new Properties(); - streamChannelProps.setProperty("block-queue-size", "10000"); - result.setStreamChannel(new YamlAlgorithmConfiguration("MEMORY", streamChannelProps)); + result.setStreamChannel(new YamlAlgorithmConfiguration("MEMORY", PropertiesBuilder.build(new Property("block-queue-size", "10000")))); return result; } @Test public void assertSwapToYamlConfiguration() { - Properties rateLimiterProps = new Properties(); - rateLimiterProps.setProperty("batch-size", "1000"); - rateLimiterProps.setProperty("qps", "50"); - PipelineReadConfiguration readConfig = new PipelineReadConfiguration(40, 1000, 10000000, new AlgorithmConfiguration("INPUT", rateLimiterProps)); - PipelineWriteConfiguration writeConfig = new PipelineWriteConfiguration(40, 1000, new AlgorithmConfiguration("OUTPUT", rateLimiterProps)); - Properties streamChannelProps = new Properties(); - streamChannelProps.setProperty("block-queue-size", "10000"); - PipelineProcessConfiguration config = new PipelineProcessConfiguration(readConfig, writeConfig, new AlgorithmConfiguration("MEMORY", streamChannelProps)); + PipelineReadConfiguration readConfig = new PipelineReadConfiguration(40, 1000, 10000000, + new AlgorithmConfiguration("INPUT", PropertiesBuilder.build(new Property("batch-size", "1000"), new Property("qps", "50")))); + PipelineWriteConfiguration writeConfig = new PipelineWriteConfiguration(40, 1000, + new AlgorithmConfiguration("OUTPUT", PropertiesBuilder.build(new Property("batch-size", "1000"), new Property("qps", "50")))); + PipelineProcessConfiguration config = new PipelineProcessConfiguration(readConfig, writeConfig, + new AlgorithmConfiguration("MEMORY", PropertiesBuilder.build(new Property("block-queue-size", "10000")))); YamlPipelineProcessConfiguration actual = new YamlPipelineProcessConfigurationSwapper().swapToYamlConfiguration(config); assertThat(actual.getRead().getWorkerThread(), is(40)); assertThat(actual.getRead().getBatchSize(), is(1000)); diff --git a/kernel/traffic/core/pom.xml b/kernel/traffic/core/pom.xml index 6ad546941d90a..082389bca95fc 100644 --- a/kernel/traffic/core/pom.xml +++ b/kernel/traffic/core/pom.xml @@ -48,5 +48,12 @@ shardingsphere-cluster-mode-core ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java index fe70d4b1f1ba6..1169424ccffef 100644 --- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java +++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithmTest.java @@ -21,13 +21,13 @@ import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.traffic.api.traffic.segment.SegmentTrafficValue; import org.apache.shardingsphere.traffic.spi.TrafficAlgorithm; import org.junit.Before; import org.junit.Test; -import java.util.Properties; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -38,13 +38,8 @@ public final class SQLMatchTrafficAlgorithmTest { @Before public void setUp() { - sqlMatchAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SQL_MATCH", createProperties()), TrafficAlgorithm.class); - } - - private Properties createProperties() { - Properties result = new Properties(); - result.put("sql", "SELECT * FROM t_order; UPDATE t_order SET order_id = ? WHERE user_id = ?;"); - return result; + sqlMatchAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SQL_MATCH", + PropertiesBuilder.build(new Property("sql", "SELECT * FROM t_order; UPDATE t_order SET order_id = ? WHERE user_id = ?;"))), TrafficAlgorithm.class); } @Test diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java index 8845d812586d0..eac643d58a82c 100644 --- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java +++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithmTest.java @@ -21,13 +21,13 @@ import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.traffic.api.traffic.segment.SegmentTrafficValue; import org.apache.shardingsphere.traffic.spi.TrafficAlgorithm; import org.junit.Before; import org.junit.Test; -import java.util.Properties; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -38,13 +38,8 @@ public final class SQLRegexTrafficAlgorithmTest { @Before public void setUp() { - sqlRegexAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new AlgorithmConfiguration("SQL_REGEX", createProperties()), TrafficAlgorithm.class); - } - - private Properties createProperties() { - Properties result = new Properties(); - result.put("regex", "(?i)^(UPDATE|SELECT).*WHERE user_id.*"); - return result; + sqlRegexAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm( + new AlgorithmConfiguration("SQL_REGEX", PropertiesBuilder.build(new Property("regex", "(?i)^(UPDATE|SELECT).*WHERE user_id.*"))), TrafficAlgorithm.class); } @Test diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java index c68a5c6c01a85..d4e1c87e0899a 100644 --- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java +++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/rule/TrafficRuleTest.java @@ -29,6 +29,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.CommentSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.traffic.algorithm.loadbalance.RandomTrafficLoadBalanceAlgorithm; import org.apache.shardingsphere.traffic.algorithm.traffic.hint.SQLHintTrafficAlgorithm; import org.apache.shardingsphere.traffic.algorithm.traffic.transaction.ProxyTrafficAlgorithm; @@ -40,7 +42,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.Optional; -import java.util.Properties; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; @@ -113,9 +114,7 @@ private TrafficRuleConfiguration createTrafficRuleConfig() { private AlgorithmConfiguration createSQLHintTrafficAlgorithm() { AlgorithmConfiguration result = mock(AlgorithmConfiguration.class); when(result.getType()).thenReturn("SQL_HINT"); - Properties props = new Properties(); - props.put("traffic", true); - when(result.getProps()).thenReturn(props); + when(result.getProps()).thenReturn(PropertiesBuilder.build(new Property("traffic", Boolean.TRUE.toString()))); return result; } diff --git a/kernel/traffic/distsql/handler/pom.xml b/kernel/traffic/distsql/handler/pom.xml index 840481bc84530..3c4fbe36c4128 100644 --- a/kernel/traffic/distsql/handler/pom.xml +++ b/kernel/traffic/distsql/handler/pom.xml @@ -48,5 +48,12 @@ shardingsphere-traffic-distsql-parser ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRuleResultSetTest.java b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRuleResultSetTest.java index edba189a83545..3ba1ad0174a60 100644 --- a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRuleResultSetTest.java +++ b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRuleResultSetTest.java @@ -17,9 +17,11 @@ package org.apache.shardingsphere.traffic.distsql.handler.query; -import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.distsql.handler.resultset.GlobalRuleDistSQLResultSet; +import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration; import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration; import org.apache.shardingsphere.traffic.distsql.parser.statement.queryable.ShowTrafficRulesStatement; @@ -69,14 +71,8 @@ private TrafficRuleConfiguration createTrafficRuleConfiguration() { result.getTrafficStrategies().add(new TrafficStrategyConfiguration("rule_name_2", Collections.singletonList("oltp"), "algorithm_2", "load_balancer_2")); result.getLoadBalancers().put("load_balancer_1", new AlgorithmConfiguration("RANDOM", new Properties())); result.getLoadBalancers().put("load_balancer_2", new AlgorithmConfiguration("ROBIN", new Properties())); - result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", createProperties())); + result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", PropertiesBuilder.build(new Property("sql", "select * from t_order")))); result.getTrafficAlgorithms().put("algorithm_2", new AlgorithmConfiguration("SQL_HINT", new Properties())); return result; } - - private Properties createProperties() { - Properties result = new Properties(); - result.put("sql", "select * from t_order"); - return result; - } } diff --git a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java index e2e39ccaa0efb..96341023bc30a 100644 --- a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java +++ b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java @@ -17,12 +17,14 @@ package org.apache.shardingsphere.traffic.distsql.handler.update; -import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; -import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException; +import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; +import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration; import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration; import org.apache.shardingsphere.traffic.distsql.parser.segment.TrafficRuleSegment; @@ -117,16 +119,10 @@ private TrafficRuleConfiguration createTrafficRuleConfiguration() { TrafficRuleConfiguration result = new TrafficRuleConfiguration(); result.getTrafficStrategies().add(new TrafficStrategyConfiguration("rule_name_1", Arrays.asList("olap", "order_by"), "algorithm_1", "load_balancer_1")); result.getTrafficStrategies().add(new TrafficStrategyConfiguration("rule_name_2", Collections.singletonList("oltp"), "algorithm_2", "load_balancer_2")); - result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", createProperties())); + result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", PropertiesBuilder.build(new Property("sql", "select * from t_order")))); result.getTrafficAlgorithms().put("algorithm_2", new AlgorithmConfiguration("SQL_HINT", new Properties())); result.getLoadBalancers().put("load_balancer_1", new AlgorithmConfiguration("RANDOM", new Properties())); result.getLoadBalancers().put("load_balancer_2", new AlgorithmConfiguration("ROUND_ROBIN", new Properties())); return result; } - - private Properties createProperties() { - Properties result = new Properties(); - result.put("sql", "select * from t_order"); - return result; - } } diff --git a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java index 823808ba9a6c1..b9cdf7fc75eb4 100644 --- a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java +++ b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java @@ -17,12 +17,14 @@ package org.apache.shardingsphere.traffic.distsql.handler.update; +import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException; +import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException; import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; -import org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException; -import org.apache.shardingsphere.distsql.handler.exception.algorithm.InvalidAlgorithmConfigurationException; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration; import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration; import org.apache.shardingsphere.traffic.distsql.parser.segment.TrafficRuleSegment; @@ -121,16 +123,10 @@ private TrafficRuleConfiguration createTrafficRuleConfiguration() { TrafficRuleConfiguration result = new TrafficRuleConfiguration(); result.getTrafficStrategies().add(new TrafficStrategyConfiguration("rule_name_1", Arrays.asList("olap", "order_by"), "algorithm_1", "load_balancer_1")); result.getTrafficStrategies().add(new TrafficStrategyConfiguration("rule_name_2", Collections.singleton("oltp"), "algorithm_2", "load_balancer_2")); - result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", createProperties())); + result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", PropertiesBuilder.build(new Property("sql", "select * from t_order")))); result.getTrafficAlgorithms().put("algorithm_2", new AlgorithmConfiguration("SQL_HINT", new Properties())); result.getLoadBalancers().put("load_balancer_1", new AlgorithmConfiguration("RANDOM", new Properties())); result.getLoadBalancers().put("load_balancer_2", new AlgorithmConfiguration("ROUND_ROBIN", new Properties())); return result; } - - private Properties createProperties() { - Properties result = new Properties(); - result.put("sql", "select * from t_order"); - return result; - } } diff --git a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java index c0036db53f7dd..6176274324221 100644 --- a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java +++ b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java @@ -17,10 +17,12 @@ package org.apache.shardingsphere.traffic.distsql.handler.update; -import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException; +import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration; import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration; import org.apache.shardingsphere.traffic.distsql.parser.statement.updatable.DropTrafficRuleStatement; @@ -85,16 +87,10 @@ private TrafficRuleConfiguration createTrafficRuleConfiguration() { TrafficRuleConfiguration result = new TrafficRuleConfiguration(); result.getTrafficStrategies().add(new TrafficStrategyConfiguration("rule_name_1", Arrays.asList("olap", "order_by"), "algorithm_1", "load_balancer_1")); result.getTrafficStrategies().add(new TrafficStrategyConfiguration("rule_name_2", Collections.singleton("oltp"), "algorithm_2", "load_balancer_2")); - result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", createProperties())); + result.getTrafficAlgorithms().put("algorithm_1", new AlgorithmConfiguration("SQL_MATCH", PropertiesBuilder.build(new Property("sql", "select * from t_order")))); result.getTrafficAlgorithms().put("algorithm_2", new AlgorithmConfiguration("SQL_HINT", new Properties())); result.getLoadBalancers().put("load_balancer_1", new AlgorithmConfiguration("RANDOM", new Properties())); result.getLoadBalancers().put("load_balancer_2", new AlgorithmConfiguration("ROUND_ROBIN", new Properties())); return result; } - - private Properties createProperties() { - Properties result = new Properties(); - result.put("sql", "select * from t_order"); - return result; - } } diff --git a/kernel/transaction/distsql/handler/pom.xml b/kernel/transaction/distsql/handler/pom.xml index 88184e5c85393..363bdb8675a98 100644 --- a/kernel/transaction/distsql/handler/pom.xml +++ b/kernel/transaction/distsql/handler/pom.xml @@ -48,5 +48,12 @@ shardingsphere-transaction-distsql-parser ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleResultSetTest.java b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleResultSetTest.java index 6a9df4a6d9f36..7710647a4298d 100644 --- a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleResultSetTest.java +++ b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleResultSetTest.java @@ -18,6 +18,8 @@ package org.apache.shardingsphere.transaction.distsql.handler.query; import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; import org.apache.shardingsphere.transaction.distsql.parser.statement.queryable.ShowTransactionRuleStatement; import org.apache.shardingsphere.transaction.rule.TransactionRule; @@ -40,7 +42,7 @@ public final class TransactionRuleResultSetTest { @Test public void assertExecuteWithXA() { TransactionRuleResultSet resultSet = new TransactionRuleResultSet(); - ShardingSphereRuleMetaData ruleMetaData = mockGlobalRuleMetaData("XA", "Atomikos", createProperties()); + ShardingSphereRuleMetaData ruleMetaData = mockGlobalRuleMetaData("XA", "Atomikos", PropertiesBuilder.build(new Property("host", "127.0.0.1"), new Property("databaseName", "jbossts"))); resultSet.init(ruleMetaData, mock(ShowTransactionRuleStatement.class)); Collection actual = resultSet.getRowData(); Iterator rowData = actual.iterator(); @@ -73,11 +75,4 @@ private ShardingSphereRuleMetaData mockGlobalRuleMetaData(final String defaultTy private TransactionRuleConfiguration createAuthorityRuleConfiguration(final String defaultType, final String providerType, final Properties props) { return new TransactionRuleConfiguration(defaultType, providerType, props); } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("host", "127.0.0.1"); - result.setProperty("databaseName", "jbossts"); - return result; - } } diff --git a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java index 7f60cc9921a8c..277e43128e9bf 100644 --- a/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java +++ b/kernel/transaction/distsql/handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java @@ -23,6 +23,8 @@ import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData; import org.apache.shardingsphere.infra.util.props.PropertiesConverter; import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.transaction.api.TransactionType; import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; import org.apache.shardingsphere.transaction.distsql.handler.fixture.ShardingSphereTransactionManagerFixture; @@ -58,7 +60,8 @@ public void assertExecuteWithXA() { () -> ShardingSphereServiceLoader.getServiceInstances(ShardingSphereTransactionManager.class)).thenReturn(Collections.singleton(new ShardingSphereTransactionManagerFixture())); AlterTransactionRuleStatementUpdater updater = new AlterTransactionRuleStatementUpdater(); ShardingSphereMetaData metaData = createMetaData(); - updater.executeUpdate(metaData, new AlterTransactionRuleStatement("XA", new TransactionProviderSegment("Atomikos", createProperties()))); + updater.executeUpdate(metaData, new AlterTransactionRuleStatement("XA", + new TransactionProviderSegment("Atomikos", PropertiesBuilder.build(new Property("host", "127.0.0.1"), new Property("databaseName", "jbossts"))))); TransactionRule updatedRule = metaData.getGlobalRuleMetaData().getSingleRule(TransactionRule.class); assertThat(updatedRule.getDefaultType(), is(TransactionType.XA)); assertThat(updatedRule.getProviderType(), is("Atomikos")); @@ -96,11 +99,4 @@ private ShardingSphereDatabase mockDatabase() { when(result.getResourceMetaData().getDataSources()).thenReturn(Collections.singletonMap("foo_ds", mock(DataSource.class, RETURNS_DEEP_STUBS))); return result; } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("host", "127.0.0.1"); - result.setProperty("databaseName", "jbossts"); - return result; - } } diff --git a/mode/core/pom.xml b/mode/core/pom.xml index 2eb96bcb4906a..c9bafe294f493 100644 --- a/mode/core/pom.xml +++ b/mode/core/pom.xml @@ -46,5 +46,11 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java index 9dfade3982871..724f4fff8a026 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java @@ -21,6 +21,8 @@ import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Collections; @@ -28,10 +30,10 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -56,7 +58,7 @@ public void assertIsNotEmptyWhenGlobalRuleIsNotEmpty() { @Test public void assertIsNotEmptyWhenPropsIsNotEmpty() { - assertFalse(new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyList(), createProperties(), null, null, false).isEmpty()); + assertFalse(new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyList(), PropertiesBuilder.build(new Property("foo", "foo_value")), null, null, false).isEmpty()); } @Test @@ -76,12 +78,6 @@ private Map mockDatabaseConfigurations(final bool return Collections.singletonMap("foo_ds", databaseConfig); } - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("foo", "foo_value"); - return result; - } - @Test public void assertGetDefaultModeConfiguration() { ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false); diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index ad998d2b1a143..124c3e6cab684 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -38,6 +38,8 @@ import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.metadata.persist.service.DatabaseMetaDataPersistService; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; import org.junit.Before; import org.junit.Test; @@ -263,9 +265,7 @@ public void assertAlterGlobalRuleConfiguration() { @Test public void assertAlterProperties() { - Properties props = new Properties(); - props.put("foo", "foo_value"); - contextManager.alterProperties(props); + contextManager.alterProperties(PropertiesBuilder.build(new Property("foo", "foo_value"))); assertThat(contextManager.getMetaDataContexts().getMetaData().getProps().getProps().getProperty("foo"), is("foo_value")); } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistServiceTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistServiceTest.java index bfa50a50caca8..f5ae7b7cbbd10 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistServiceTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistServiceTest.java @@ -32,6 +32,8 @@ import org.apache.shardingsphere.mode.metadata.persist.service.config.global.PropertiesPersistService; import org.apache.shardingsphere.mode.persist.PersistRepository; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -93,9 +95,8 @@ public void assertConditionalPersistConfigurations() { Map dataSourceMap = createDataSourceMap(); Collection ruleConfigs = createRuleConfigurations(); Collection globalRuleConfigs = createGlobalRuleConfigurations(); - Properties props = createProperties(); - metaDataPersistService.persistConfigurations( - Collections.singletonMap("foo_db", new DataSourceProvidedDatabaseConfiguration(dataSourceMap, ruleConfigs)), globalRuleConfigs, props); + Properties props = PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.FALSE.toString())); + metaDataPersistService.persistConfigurations(Collections.singletonMap("foo_db", new DataSourceProvidedDatabaseConfiguration(dataSourceMap, ruleConfigs)), globalRuleConfigs, props); verify(dataSourceService).conditionalPersist("foo_db", createDataSourcePropertiesMap(dataSourceMap)); verify(databaseRulePersistService).conditionalPersist("foo_db", ruleConfigs); verify(globalRuleService).conditionalPersist(globalRuleConfigs); @@ -132,12 +133,6 @@ private Collection createGlobalRuleConfigurations() { return Collections.emptyList(); } - private Properties createProperties() { - Properties result = new Properties(); - result.put(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.FALSE); - return result; - } - @SneakyThrows({IOException.class, URISyntaxException.class}) private String readYAML(final String yamlFile) { return Files.readAllLines(Paths.get(ClassLoader.getSystemResource(yamlFile).toURI())).stream().map(each -> each + System.lineSeparator()).collect(Collectors.joining()); diff --git a/mode/type/cluster/core/pom.xml b/mode/type/cluster/core/pom.xml index 230a591d2d8d8..89b378dca8e78 100644 --- a/mode/type/cluster/core/pom.xml +++ b/mode/type/cluster/core/pom.xml @@ -55,5 +55,11 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java index 26beaaae12c1d..a47f3205e54a8 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/workerid/generator/ClusterWorkerIdGeneratorTest.java @@ -21,6 +21,8 @@ import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator; import org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import org.mockito.stubbing.Answer; @@ -39,13 +41,11 @@ public final class ClusterWorkerIdGeneratorTest { @Test public void assertGenerateWithExistedWorkerId() { - Properties props = new Properties(); - props.setProperty(WorkerIdGenerator.WORKER_ID_KEY, "1"); InstanceMetaData instanceMetaData = mock(InstanceMetaData.class); when(instanceMetaData.getId()).thenReturn("foo_id"); RegistryCenter registryCenter = mock(RegistryCenter.class, RETURNS_DEEP_STUBS); when(registryCenter.getComputeNodeStatusService().loadInstanceWorkerId("foo_id")).thenReturn(Optional.of(10)); - assertThat(new ClusterWorkerIdGenerator(registryCenter, instanceMetaData).generate(props), is(10)); + assertThat(new ClusterWorkerIdGenerator(registryCenter, instanceMetaData).generate(PropertiesBuilder.build(new Property(WorkerIdGenerator.WORKER_ID_KEY, "1"))), is(10)); } @Test diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java index 836f6ce237d9e..273870b2a361d 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriberTest.java @@ -52,6 +52,8 @@ import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.transaction.rule.TransactionRule; import org.junit.Before; import org.junit.Test; @@ -185,9 +187,7 @@ public void assertRenewDatabaseVersionChangedEvent() { @Test public void assertRenewProperties() { - Properties props = new Properties(); - props.setProperty(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString()); - subscriber.renew(new PropertiesChangedEvent(props)); + subscriber.renew(new PropertiesChangedEvent(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.SQL_SHOW.getKey(), Boolean.TRUE.toString())))); assertThat(contextManager.getMetaDataContexts().getMetaData().getProps().getProps().getProperty(ConfigurationPropertyKey.SQL_SHOW.getKey()), is(Boolean.TRUE.toString())); } diff --git a/mode/type/cluster/repository/api/pom.xml b/mode/type/cluster/repository/api/pom.xml index 692e85535a210..18955250b5200 100644 --- a/mode/type/cluster/repository/api/pom.xml +++ b/mode/type/cluster/repository/api/pom.xml @@ -38,5 +38,12 @@ shardingsphere-mode-core ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/mode/type/cluster/repository/api/src/test/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/props/DefaultLockTypedPropertiesTest.java b/mode/type/cluster/repository/api/src/test/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/props/DefaultLockTypedPropertiesTest.java index b94b38d85d5c5..fa65d43c3d709 100644 --- a/mode/type/cluster/repository/api/src/test/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/props/DefaultLockTypedPropertiesTest.java +++ b/mode/type/cluster/repository/api/src/test/java/org/apache/shardingsphere/mode/repository/cluster/lock/impl/props/DefaultLockTypedPropertiesTest.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.mode.repository.cluster.lock.impl.props; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -24,13 +26,11 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -public class DefaultLockTypedPropertiesTest { +public final class DefaultLockTypedPropertiesTest { @Test public void assertGetValue() { - Properties lockProperties = new Properties(); - lockProperties.setProperty("instanceId", "instance-id"); - DefaultLockTypedProperties actual = new DefaultLockTypedProperties(lockProperties); + DefaultLockTypedProperties actual = new DefaultLockTypedProperties(PropertiesBuilder.build(new Property("instanceId", "instance-id"))); assertThat(actual.getValue(DefaultLockPropertyKey.INSTANCE_ID), is("instance-id")); } diff --git a/mode/type/cluster/repository/provider/consul/pom.xml b/mode/type/cluster/repository/provider/consul/pom.xml index 09a89ae003c9f..912a8e568ef2e 100644 --- a/mode/type/cluster/repository/provider/consul/pom.xml +++ b/mode/type/cluster/repository/provider/consul/pom.xml @@ -38,6 +38,12 @@ shardingsphere-cluster-mode-repository-api ${project.version} + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + com.ecwid.consul diff --git a/mode/type/cluster/repository/provider/consul/src/test/java/org/apache/shardingsphere/mode/repository/cluster/consul/props/ConsulPropertiesTest.java b/mode/type/cluster/repository/provider/consul/src/test/java/org/apache/shardingsphere/mode/repository/cluster/consul/props/ConsulPropertiesTest.java index ec455d5c87855..2208d15710384 100644 --- a/mode/type/cluster/repository/provider/consul/src/test/java/org/apache/shardingsphere/mode/repository/cluster/consul/props/ConsulPropertiesTest.java +++ b/mode/type/cluster/repository/provider/consul/src/test/java/org/apache/shardingsphere/mode/repository/cluster/consul/props/ConsulPropertiesTest.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.mode.repository.cluster.consul.props; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -28,13 +30,8 @@ public final class ConsulPropertiesTest { @Test public void assertGetValue() { - assertThat(new ConsulProperties(createProperties()).getValue(ConsulPropertyKey.BLOCK_QUERY_TIME_TO_SECONDS), is(60L)); - } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(ConsulPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "50"); - return result; + assertThat(new ConsulProperties(PropertiesBuilder.build(new Property(ConsulPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "50"))).getValue(ConsulPropertyKey.BLOCK_QUERY_TIME_TO_SECONDS), + is(60L)); } @Test diff --git a/mode/type/cluster/repository/provider/etcd/pom.xml b/mode/type/cluster/repository/provider/etcd/pom.xml index 0473de74870b0..e679455a8e7de 100644 --- a/mode/type/cluster/repository/provider/etcd/pom.xml +++ b/mode/type/cluster/repository/provider/etcd/pom.xml @@ -33,6 +33,12 @@ shardingsphere-cluster-mode-repository-api ${project.version} + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + io.etcd diff --git a/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java b/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java index 29632f16492ee..501d3e6ad71a1 100644 --- a/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java +++ b/mode/type/cluster/repository/provider/etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/props/EtcdPropertiesTest.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.mode.repository.cluster.etcd.props; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -28,13 +30,7 @@ public final class EtcdPropertiesTest { @Test public void assertGetValue() { - assertThat(new EtcdProperties(createProperties()).getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS), is(50L)); - } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(EtcdPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "50"); - return result; + assertThat(new EtcdProperties(PropertiesBuilder.build(new Property(EtcdPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "50"))).getValue(EtcdPropertyKey.TIME_TO_LIVE_SECONDS), is(50L)); } @Test diff --git a/mode/type/cluster/repository/provider/nacos/pom.xml b/mode/type/cluster/repository/provider/nacos/pom.xml index e8846f1830cb4..aefa1b715f339 100644 --- a/mode/type/cluster/repository/provider/nacos/pom.xml +++ b/mode/type/cluster/repository/provider/nacos/pom.xml @@ -37,6 +37,12 @@ shardingsphere-cluster-mode-repository-api ${project.version} + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + com.alibaba.nacos diff --git a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java index dec672608df0c..d881033d76106 100644 --- a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java +++ b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/props/NacosPropertiesTest.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.mode.repository.cluster.nacos.props; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -36,12 +38,11 @@ public void assertGetValue() { } private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(NacosPropertyKey.CLUSTER_IP.getKey(), "127.0.0.1"); - result.setProperty(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "1000"); - result.setProperty(NacosPropertyKey.MAX_RETRIES.getKey(), "5"); - result.setProperty(NacosPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "60"); - return result; + return PropertiesBuilder.build( + new Property(NacosPropertyKey.CLUSTER_IP.getKey(), "127.0.0.1"), + new Property(NacosPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "1000"), + new Property(NacosPropertyKey.MAX_RETRIES.getKey(), "5"), + new Property(NacosPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "60")); } @Test diff --git a/mode/type/cluster/repository/provider/zookeeper/pom.xml b/mode/type/cluster/repository/provider/zookeeper/pom.xml index 62e4dd46b6add..1d4642648498a 100644 --- a/mode/type/cluster/repository/provider/zookeeper/pom.xml +++ b/mode/type/cluster/repository/provider/zookeeper/pom.xml @@ -33,6 +33,12 @@ shardingsphere-cluster-mode-repository-api ${project.version} + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + org.apache.curator diff --git a/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepositoryTest.java b/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepositoryTest.java index d16641466ca12..b8f27afadb530 100644 --- a/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepositoryTest.java +++ b/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/ZookeeperRepositoryTest.java @@ -41,6 +41,8 @@ import org.apache.shardingsphere.mode.repository.cluster.zookeeper.lock.ZookeeperDistributedLock; import org.apache.shardingsphere.mode.repository.cluster.zookeeper.props.ZookeeperProperties; import org.apache.shardingsphere.mode.repository.cluster.zookeeper.props.ZookeeperPropertyKey; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.data.Stat; import org.junit.Before; @@ -249,37 +251,30 @@ private VoidAnswer1 getListenerAnswer(final CuratorCacheLi @Test public void assertBuildCuratorClientWithCustomConfig() { - Properties props = new Properties(); - props.setProperty(ZookeeperPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "1000"); - props.setProperty(ZookeeperPropertyKey.MAX_RETRIES.getKey(), "1"); - props.setProperty(ZookeeperPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "1000"); - props.setProperty(ZookeeperPropertyKey.OPERATION_TIMEOUT_MILLISECONDS.getKey(), "2000"); - ClusterPersistRepositoryConfiguration config = new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, props); - REPOSITORY.init(config); + Properties props = PropertiesBuilder.build( + new Property(ZookeeperPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "1000"), + new Property(ZookeeperPropertyKey.MAX_RETRIES.getKey(), "1"), + new Property(ZookeeperPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "1000"), + new Property(ZookeeperPropertyKey.OPERATION_TIMEOUT_MILLISECONDS.getKey(), "2000")); + REPOSITORY.init(new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, props)); } @Test public void assertBuildCuratorClientWithTimeToLiveSecondsEqualsZero() { - Properties props = new Properties(); - props.setProperty(ZookeeperPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "0"); - ClusterPersistRepositoryConfiguration config = new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, props); - REPOSITORY.init(config); + REPOSITORY.init(new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, + PropertiesBuilder.build(new Property(ZookeeperPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "0")))); } @Test public void assertBuildCuratorClientWithOperationTimeoutMillisecondsEqualsZero() { - Properties props = new Properties(); - props.setProperty(ZookeeperPropertyKey.OPERATION_TIMEOUT_MILLISECONDS.getKey(), "0"); - ClusterPersistRepositoryConfiguration config = new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, props); - REPOSITORY.init(config); + REPOSITORY.init(new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, + PropertiesBuilder.build(new Property(ZookeeperPropertyKey.OPERATION_TIMEOUT_MILLISECONDS.getKey(), "0")))); } @Test public void assertBuildCuratorClientWithDigest() { - Properties props = new Properties(); - props.setProperty(ZookeeperPropertyKey.DIGEST.getKey(), "any"); - ClusterPersistRepositoryConfiguration config = new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, props); - REPOSITORY.init(config); + REPOSITORY.init(new ClusterPersistRepositoryConfiguration(REPOSITORY.getType(), "governance", SERVER_LISTS, + PropertiesBuilder.build(new Property(ZookeeperPropertyKey.DIGEST.getKey(), "any")))); verify(builder).aclProvider(any(ACLProvider.class)); } diff --git a/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/props/ZookeeperPropertiesTest.java b/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/props/ZookeeperPropertiesTest.java index cb708c4dadf99..e086e724c6683 100644 --- a/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/props/ZookeeperPropertiesTest.java +++ b/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/props/ZookeeperPropertiesTest.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.mode.repository.cluster.zookeeper.props; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -37,13 +39,12 @@ public void assertGetValue() { } private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(ZookeeperPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "3000"); - result.setProperty(ZookeeperPropertyKey.MAX_RETRIES.getKey(), "2"); - result.setProperty(ZookeeperPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "600"); - result.setProperty(ZookeeperPropertyKey.OPERATION_TIMEOUT_MILLISECONDS.getKey(), "6000"); - result.setProperty(ZookeeperPropertyKey.DIGEST.getKey(), "any"); - return result; + return PropertiesBuilder.build( + new Property(ZookeeperPropertyKey.RETRY_INTERVAL_MILLISECONDS.getKey(), "3000"), + new Property(ZookeeperPropertyKey.MAX_RETRIES.getKey(), "2"), + new Property(ZookeeperPropertyKey.TIME_TO_LIVE_SECONDS.getKey(), "600"), + new Property(ZookeeperPropertyKey.OPERATION_TIMEOUT_MILLISECONDS.getKey(), "6000"), + new Property(ZookeeperPropertyKey.DIGEST.getKey(), "any")); } @Test diff --git a/mode/type/standalone/core/pom.xml b/mode/type/standalone/core/pom.xml index 50f17dba2d6db..a950d090ebb0b 100644 --- a/mode/type/standalone/core/pom.xml +++ b/mode/type/standalone/core/pom.xml @@ -45,5 +45,11 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java index 1ef9ce97de098..5769dc6b791ca 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java @@ -18,6 +18,8 @@ package org.apache.shardingsphere.mode.manager.standalone.workerid.generator; import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Properties; @@ -39,15 +41,11 @@ public void assertGenerateWithEmptyProperties() { @Test public void assertGenerateWithProperties() { - Properties props = new Properties(); - props.setProperty(WorkerIdGenerator.WORKER_ID_KEY, "1"); - assertThat(new StandaloneWorkerIdGenerator().generate(props), is(1)); + assertThat(new StandaloneWorkerIdGenerator().generate(PropertiesBuilder.build(new Property(WorkerIdGenerator.WORKER_ID_KEY, "1"))), is(1)); } @Test(expected = IllegalStateException.class) public void assertGenerateWithInvalidProperties() { - Properties props = new Properties(); - props.setProperty(WorkerIdGenerator.WORKER_ID_KEY, "1024"); - new StandaloneWorkerIdGenerator().generate(props); + new StandaloneWorkerIdGenerator().generate(PropertiesBuilder.build(new Property(WorkerIdGenerator.WORKER_ID_KEY, "1024"))); } } diff --git a/mode/type/standalone/repository/provider/jdbc/core/pom.xml b/mode/type/standalone/repository/provider/jdbc/core/pom.xml index a342b0cddf1a2..d98c394b2adb5 100644 --- a/mode/type/standalone/repository/provider/jdbc/core/pom.xml +++ b/mode/type/standalone/repository/provider/jdbc/core/pom.xml @@ -33,6 +33,13 @@ ${project.version} + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + com.zaxxer HikariCP diff --git a/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java b/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java index ac557cbb9e75a..56614eae77fbd 100644 --- a/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java +++ b/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java @@ -19,6 +19,8 @@ import com.zaxxer.hikari.HikariDataSource; import org.apache.shardingsphere.mode.repository.standalone.jdbc.fixture.JDBCRepositoryProviderFixture; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.h2.jdbc.JdbcCallableStatement; import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcResultSet; @@ -72,7 +74,12 @@ public void setup() throws Exception { this.mockedConstruction = mockConstruction(HikariDataSource.class, (mock, context) -> when(mock.getConnection()).thenReturn(mockJdbcConnection)); when(mockJdbcConnection.createStatement()).thenReturn(mockStatement); repository = new JDBCRepository(); - repository.init(createProperties()); + Properties props = PropertiesBuilder.build( + new Property("jdbc_url", "jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL"), + new Property("username", "sa"), + new Property("password", ""), + new Property("provider", "FIXTURE")); + repository.init(props); } @After @@ -252,13 +259,4 @@ public void assertClose() { HikariDataSource hikariDataSource = mockedConstruction.constructed().get(0); verify(hikariDataSource).close(); } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("jdbc_url", "jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL"); - result.setProperty("username", "sa"); - result.setProperty("password", ""); - result.setProperty("provider", "FIXTURE"); - return result; - } } diff --git a/mode/type/standalone/repository/provider/jdbc/h2/pom.xml b/mode/type/standalone/repository/provider/jdbc/h2/pom.xml index fc2741f19b3ef..28056db4fabfa 100644 --- a/mode/type/standalone/repository/provider/jdbc/h2/pom.xml +++ b/mode/type/standalone/repository/provider/jdbc/h2/pom.xml @@ -38,6 +38,13 @@ ${project.version} + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + com.h2database h2 diff --git a/mode/type/standalone/repository/provider/jdbc/h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2JDBCRepositoryTest.java b/mode/type/standalone/repository/provider/jdbc/h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2JDBCRepositoryTest.java index 58fcca88405b6..a20782dda890e 100644 --- a/mode/type/standalone/repository/provider/jdbc/h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2JDBCRepositoryTest.java +++ b/mode/type/standalone/repository/provider/jdbc/h2/src/test/java/org/apache/shardingsphere/mode/repository/standalone/h2/H2JDBCRepositoryTest.java @@ -18,6 +18,8 @@ package org.apache.shardingsphere.mode.repository.standalone.h2; import org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -34,11 +36,11 @@ public final class H2JDBCRepositoryTest { @Before public void setUp() { - Properties props = new Properties(); - props.setProperty("jdbc_url", "jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL"); - props.setProperty("username", "sa"); - props.setProperty("password", ""); - props.setProperty("provider", "H2"); + Properties props = PropertiesBuilder.build( + new Property("jdbc_url", "jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL"), + new Property("username", "sa"), + new Property("password", ""), + new Property("provider", "H2")); repository.init(props); } diff --git a/mode/type/standalone/repository/provider/jdbc/mysql/pom.xml b/mode/type/standalone/repository/provider/jdbc/mysql/pom.xml index f4769990412f0..e3b6b2f640058 100644 --- a/mode/type/standalone/repository/provider/jdbc/mysql/pom.xml +++ b/mode/type/standalone/repository/provider/jdbc/mysql/pom.xml @@ -38,6 +38,14 @@ shardingsphere-standalone-mode-repository-jdbc-core ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + + mysql mysql-connector-java diff --git a/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java b/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java index 95397a6727da7..9b9848c893777 100644 --- a/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java +++ b/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java @@ -19,6 +19,8 @@ import com.zaxxer.hikari.HikariDataSource; import org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -28,18 +30,17 @@ import org.mockito.junit.MockitoJUnitRunner; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.Statement; import java.sql.SQLException; -import java.sql.PreparedStatement; +import java.sql.Statement; import java.util.List; -import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockConstruction; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.mock; @RunWith(MockitoJUnitRunner.class) public class MySQLJDBCRepositoryProviderTest { @@ -63,12 +64,8 @@ public class MySQLJDBCRepositoryProviderTest { public void setUp() throws SQLException { construction = mockConstruction(HikariDataSource.class, (mock, context) -> when(mock.getConnection()).thenReturn(connection)); when(connection.createStatement()).thenReturn(mock(Statement.class)); - Properties props = new Properties(); - props.setProperty("jdbc_url", "jdbc:mysql://localhost:3306/config"); - props.setProperty("username", "sa"); - props.setProperty("password", ""); - props.setProperty("provider", "MySQL"); - repository.init(props); + repository.init(PropertiesBuilder.build(new Property("jdbc_url", "jdbc:mysql://localhost:3306/config"), + new Property("username", "sa"), new Property("password", ""), new Property("provider", "MySQL"))); } @After diff --git a/proxy/backend/pom.xml b/proxy/backend/pom.xml index e8c97e906956d..17ec2862c883e 100644 --- a/proxy/backend/pom.xml +++ b/proxy/backend/pom.xml @@ -206,6 +206,12 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + com.zaxxer diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java index e14f9b8670e33..82a39fed460a0 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/DistSQLBackendHandlerFactoryTest.java @@ -17,13 +17,13 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql; +import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException; import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; import org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterStorageUnitStatement; import org.apache.shardingsphere.distsql.parser.statement.rdl.create.RegisterStorageUnitStatement; import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.UnregisterStorageUnitStatement; import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowStorageUnitsStatement; import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; -import org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException; import org.apache.shardingsphere.infra.instance.mode.ModeContextManager; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData; @@ -51,6 +51,8 @@ import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowRulesStatement; import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowTableRulesStatement; import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -59,7 +61,6 @@ import java.sql.SQLException; import java.util.Collections; -import java.util.Properties; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.MatcherAssert.assertThat; @@ -146,9 +147,8 @@ public void assertExecuteDropShadowRuleContext() throws SQLException { @Test public void assertExecuteAlterDefaultShadowAlgorithm() throws SQLException { mockShardingSphereRuleMetaData(); - Properties props = new Properties(); - props.setProperty("type", "value"); - AlterDefaultShadowAlgorithmStatement statement = new AlterDefaultShadowAlgorithmStatement(new ShadowAlgorithmSegment("foo", new AlgorithmSegment("SIMPLE_HINT", props))); + AlterDefaultShadowAlgorithmStatement statement = new AlterDefaultShadowAlgorithmStatement( + new ShadowAlgorithmSegment("foo", new AlgorithmSegment("SIMPLE_HINT", PropertiesBuilder.build(new Property("type", "value"))))); assertThat(RDLBackendHandlerFactory.newInstance(statement, connectionSession).execute(), instanceOf(UpdateResponseHeader.class)); } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationHandlerTest.java index a126c1db2ff89..b97101855cf52 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationHandlerTest.java @@ -18,10 +18,10 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable; import lombok.SneakyThrows; -import org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ExportDatabaseConfigurationStatement; -import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException; +import org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ExportDatabaseConfigurationStatement; +import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereIndex; @@ -41,6 +41,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseSegment; import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Before; import org.junit.Test; @@ -58,8 +60,8 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertFalse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -117,7 +119,7 @@ private ShardingRuleConfiguration createShardingRuleConfiguration() { result.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "ds_inline")); result.setDefaultTableShardingStrategy(new NoneShardingStrategyConfiguration()); result.getKeyGenerators().put("snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties())); - result.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", createProperties())); + result.getShardingAlgorithms().put("ds_inline", new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", "ds_${order_id % 2}")))); return result; } @@ -127,12 +129,6 @@ private ShardingTableRuleConfiguration createTableRuleConfiguration() { return result; } - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty("algorithm-expression", "ds_${order_id % 2}"); - return result; - } - private Map createTables() { Collection columns = Collections.singleton(new ShardingSphereColumn("order_id", 0, false, false, false, true, false)); Collection indexes = Collections.singleton(new ShardingSphereIndex("primary")); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeModeHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeModeHandlerTest.java index 1707db70b75fd..b26275a83e663 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeModeHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodeModeHandlerTest.java @@ -24,11 +24,12 @@ import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.sql.SQLException; import java.util.List; -import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,13 +60,7 @@ private InstanceContext createInstanceContext() { InstanceContext result = mock(InstanceContext.class, RETURNS_DEEP_STUBS); when(result.getInstance().getMetaData().getId()).thenReturn("127.0.0.1@3309"); when(result.getModeConfiguration()).thenReturn(new ModeConfiguration("Cluster", - new ClusterPersistRepositoryConfiguration("ZooKeeper", "governance_ds", "127.0.0.1:2181", createProperties("key", "value1,value2")))); - return result; - } - - private Properties createProperties(final String key, final String value) { - Properties result = new Properties(); - result.put(key, value); + new ClusterPersistRepositoryConfiguration("ZooKeeper", "governance_ds", "127.0.0.1:2181", PropertiesBuilder.build(new Property("key", "value1,value2"))))); return result; } } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableBackendHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableBackendHandlerTest.java index 65a67a4ec162b..f80b81d534902 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableBackendHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableBackendHandlerTest.java @@ -25,20 +25,21 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; +import org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException; +import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; -import org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum; -import org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.transaction.api.TransactionType; import org.junit.Before; import org.junit.Test; import java.sql.SQLException; import java.util.List; -import java.util.Properties; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; @@ -116,9 +117,7 @@ public void assertShowPropsVariable() throws SQLException { ProxyContext.init(contextManager); MetaDataContexts metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); - Properties props = new Properties(); - props.put("sql-show", Boolean.TRUE.toString()); - when(metaDataContexts.getMetaData().getProps()).thenReturn(new ConfigurationProperties(props)); + when(metaDataContexts.getMetaData().getProps()).thenReturn(new ConfigurationProperties(PropertiesBuilder.build(new Property("sql-show", Boolean.TRUE.toString())))); ShowDistVariableHandler backendHandler = new ShowDistVariableHandler(); backendHandler.init(new ShowDistVariableStatement("SQL_SHOW"), connectionSession); ResponseHeader actual = backendHandler.execute(); diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandlerTest.java index b9fe9605849b3..282c2fc0b51cf 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandlerTest.java @@ -29,13 +29,14 @@ import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.transaction.api.TransactionType; import org.junit.Before; import org.junit.Test; import java.sql.SQLException; import java.util.List; -import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -55,9 +56,8 @@ public void setup() { private MetaDataContexts mockMetaDataContexts() { MetaDataContexts result = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS); - Properties props = new Properties(); - props.setProperty(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), "OLAP"); - when(result.getMetaData().getProps()).thenReturn(new ConfigurationProperties(props)); + when(result.getMetaData().getProps()).thenReturn( + new ConfigurationProperties(PropertiesBuilder.build(new Property(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), "OLAP")))); return result; } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataHandlerTest.java index 0b16f39a52b6d..41774cde816f8 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataHandlerTest.java @@ -19,11 +19,11 @@ import org.apache.shardingsphere.dialect.exception.syntax.database.NoDatabaseSelectedException; import org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDatabaseException; +import org.apache.shardingsphere.distsql.handler.exception.storageunit.EmptyStorageUnitException; +import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException; import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.RefreshTableMetaDataStatement; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; -import org.apache.shardingsphere.distsql.handler.exception.storageunit.EmptyStorageUnitException; -import org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -32,15 +32,13 @@ import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Before; import org.junit.Test; -import javax.sql.DataSource; import java.sql.SQLException; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,9 +57,9 @@ public final class RefreshTableMetaDataHandlerTest extends ProxyContextRestorer @Before public void setup() { ProxyContext.init(contextManager); - ConfigurationProperties configurationProps = new ConfigurationProperties(createProperties()); when(contextManager.getMetaDataContexts().getMetaData()).thenReturn(shardingSphereMetaData); - when(shardingSphereMetaData.getProps()).thenReturn(configurationProps); + when(shardingSphereMetaData.getProps()).thenReturn(new ConfigurationProperties( + PropertiesBuilder.build(new Property(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getDefaultValue())))); connectionSession = mock(ConnectionSession.class, RETURNS_DEEP_STUBS); } @@ -94,8 +92,7 @@ public void assertEmptyResource() throws SQLException { public void assertMissingRequiredResources() throws SQLException { when(connectionSession.getDatabaseName()).thenReturn("sharding_db"); when(shardingSphereMetaData.containsDatabase("sharding_db")).thenReturn(true); - Map dataSources = createDataSources(); - when(contextManager.getDataSourceMap("sharding_db")).thenReturn(dataSources); + when(contextManager.getDataSourceMap("sharding_db")).thenReturn(Collections.singletonMap("ds_0", new MockedDataSource())); RefreshTableMetaDataHandler backendHandler = new RefreshTableMetaDataHandler(); backendHandler.init(new RefreshTableMetaDataStatement("t_order", "ds_1", null), connectionSession); backendHandler.execute(); @@ -105,23 +102,10 @@ public void assertMissingRequiredResources() throws SQLException { public void assertUpdate() throws SQLException { when(connectionSession.getDatabaseName()).thenReturn("sharding_db"); when(shardingSphereMetaData.containsDatabase("sharding_db")).thenReturn(true); - Map dataSources = createDataSources(); - when(contextManager.getDataSourceMap("sharding_db")).thenReturn(dataSources); + when(contextManager.getDataSourceMap("sharding_db")).thenReturn(Collections.singletonMap("ds_0", new MockedDataSource())); RefreshTableMetaDataHandler backendHandler = new RefreshTableMetaDataHandler(); backendHandler.init(new RefreshTableMetaDataStatement(), connectionSession); ResponseHeader actual = backendHandler.execute(); assertThat(actual, instanceOf(UpdateResponseHeader.class)); } - - private Map createDataSources() { - Map result = new HashMap<>(1, 1); - result.put("ds_0", new MockedDataSource()); - return result; - } - - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getDefaultValue()); - return result; - } } diff --git a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableBackendHandlerTest.java b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableBackendHandlerTest.java index 833f548a06ad5..ed889a498bef0 100644 --- a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableBackendHandlerTest.java +++ b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetDistVariableBackendHandlerTest.java @@ -39,6 +39,8 @@ import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer; import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.apache.shardingsphere.transaction.api.TransactionType; import org.junit.Before; import org.junit.Test; @@ -64,8 +66,10 @@ public final class SetDistVariableBackendHandlerTest extends ProxyContextRestore @Before public void setUp() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(createDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(createProperties()))); + Properties props = PropertiesBuilder.build( + new Property(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getDefaultValue())); + MetaDataContexts metaDataContexts = new MetaDataContexts( + mock(MetaDataPersistService.class), new ShardingSphereMetaData(createDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(props))); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts); ProxyContext.init(contextManager); @@ -84,12 +88,6 @@ private Map createDatabases() { return result; } - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(), ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getDefaultValue()); - return result; - } - @Test public void assertSwitchTransactionTypeXA() throws SQLException { connectionSession.setCurrentDatabase(String.format(DATABASE_PATTERN, 0)); diff --git a/proxy/frontend/core/pom.xml b/proxy/frontend/core/pom.xml index b21c8ab636065..23c1ce7665dba 100644 --- a/proxy/frontend/core/pom.xml +++ b/proxy/frontend/core/pom.xml @@ -50,6 +50,12 @@ ${project.version} test + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + io.netty diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java index 2a6766ffe32b6..3de8c4f59e900 100644 --- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java +++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/protocol/FrontDatabaseProtocolTypeFactoryTest.java @@ -31,6 +31,8 @@ import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.frontend.ProxyContextRestorer; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Test; import java.util.Collections; @@ -74,8 +76,9 @@ public void assertGetDatabaseTypeInstanceOfMySQLDatabaseTypeFromMetaDataContexts @Test public void assertGetDatabaseTypeOfPostgreSQLDatabaseTypeFromMetaDataContextsProps() { - MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), - new ShardingSphereMetaData(mockDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(createProperties()))); + Properties props = PropertiesBuilder.build(new Property(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(), "PostgreSQL")); + MetaDataContexts metaDataContexts = new MetaDataContexts( + mock(MetaDataPersistService.class), new ShardingSphereMetaData(mockDatabases(), mock(ShardingSphereRuleMetaData.class), new ConfigurationProperties(props))); ProxyContext.init(new ContextManager(metaDataContexts, mock(InstanceContext.class))); assertFalse(metaDataContexts.getMetaData().getDatabases().isEmpty()); String configuredDatabaseType = metaDataContexts.getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE); @@ -87,12 +90,6 @@ public void assertGetDatabaseTypeOfPostgreSQLDatabaseTypeFromMetaDataContextsPro assertThat(metaDataContexts.getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME).getProtocolType(), instanceOf(MySQLDatabaseType.class)); } - private Properties createProperties() { - Properties result = new Properties(); - result.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(), "PostgreSQL"); - return result; - } - private Map mockDatabases() { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getProtocolType()).thenReturn(new MySQLDatabaseType()); diff --git a/test/e2e/pipeline/pom.xml b/test/e2e/pipeline/pom.xml index cb6e5c624baf7..4153fc7150a2e 100644 --- a/test/e2e/pipeline/pom.xml +++ b/test/e2e/pipeline/pom.xml @@ -47,6 +47,13 @@ shardingsphere-jdbc-core ${project.version} + + + org.apache.shardingsphere + shardingsphere-test-util + ${project.version} + test + org.apache.shardingsphere shardingsphere-test-e2e-env diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/base/PipelineBaseE2EIT.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/base/PipelineBaseE2EIT.java index 3e3d11ed76e9b..1bceb9b61f437 100644 --- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/base/PipelineBaseE2EIT.java +++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/base/PipelineBaseE2EIT.java @@ -38,6 +38,8 @@ import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DatabaseTypeUtil; import org.apache.shardingsphere.test.e2e.env.container.atomic.util.StorageContainerUtil; import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.Rule; import javax.sql.DataSource; @@ -57,7 +59,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -162,12 +163,9 @@ protected void addResource(final String distSQL) throws SQLException { } protected String appendExtraParam(final String jdbcUrl) { - if (DatabaseTypeUtil.isMySQL(getDatabaseType())) { - Properties addProps = new Properties(); - addProps.setProperty("rewriteBatchedStatements", "true"); - return new JdbcUrlAppender().appendQueryProperties(jdbcUrl, addProps); - } - return jdbcUrl; + return DatabaseTypeUtil.isMySQL(getDatabaseType()) + ? new JdbcUrlAppender().appendQueryProperties(jdbcUrl, PropertiesBuilder.build(new Property("rewriteBatchedStatements", Boolean.TRUE.toString()))) + : jdbcUrl; } protected String getActualJdbcUrlTemplate(final String databaseName, final boolean isInContainer) { diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/task/PostgreSQLIncrementTask.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/task/PostgreSQLIncrementTask.java index 69c0fd1bf294e..03fcf985a1cb3 100644 --- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/task/PostgreSQLIncrementTask.java +++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/task/PostgreSQLIncrementTask.java @@ -25,10 +25,11 @@ import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.BaseIncrementTask; import org.apache.shardingsphere.test.e2e.data.pipeline.framework.helper.PipelineCaseHelper; import org.apache.shardingsphere.test.e2e.data.pipeline.util.DataSourceExecuteUtil; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import javax.sql.DataSource; import java.time.Instant; -import java.util.Properties; import java.util.concurrent.ThreadLocalRandom; @RequiredArgsConstructor @@ -46,9 +47,7 @@ public final class PostgreSQLIncrementTask extends BaseIncrementTask { private final int executeCountLimit; static { - Properties props = new Properties(); - props.setProperty("max-vibration-offset", "2"); - KEY_GENERATE_ALGORITHM.init(props); + KEY_GENERATE_ALGORITHM.init(PropertiesBuilder.build(new Property("max-vibration-offset", "2"))); } @Override diff --git a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java index fe77ca21adcce..4321940f4142d 100644 --- a/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java +++ b/test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java @@ -22,6 +22,8 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.test.e2e.data.pipeline.env.PipelineE2EEnvironment; import org.apache.shardingsphere.test.e2e.env.runtime.DataSourceEnvironment; +import org.apache.shardingsphere.test.util.PropertiesBuilder; +import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import java.sql.Connection; import java.sql.DriverManager; @@ -29,7 +31,6 @@ import java.sql.SQLException; import java.util.LinkedList; import java.util.List; -import java.util.Properties; /** * Native composed container, you need start ShardingSphere-Proxy at firstly. @@ -62,9 +63,9 @@ public void cleanUpDatabase(final String databaseName) { case "MySQL": String queryAllTables = String.format("select table_name from information_schema.tables where table_schema='%s' and table_type='BASE TABLE'", databaseName); jdbcUrl = DataSourceEnvironment.getURL(databaseType, "localhost", actualDatabasePort, databaseName); - Properties props = new Properties(); - props.setProperty("allowPublicKeyRetrieval", "true"); - try (Connection connection = DriverManager.getConnection(jdbcUrlAppender.appendQueryProperties(jdbcUrl, props), username, password)) { + try ( + Connection connection = DriverManager.getConnection( + jdbcUrlAppender.appendQueryProperties(jdbcUrl, PropertiesBuilder.build(new Property("allowPublicKeyRetrieval", Boolean.TRUE.toString()))), username, password)) { try (ResultSet resultSet = connection.createStatement().executeQuery(queryAllTables)) { List actualTableNames = getFirstColumnValueFromResult(resultSet); for (String each : actualTableNames) {