Skip to content

Commit

Permalink
Use PropertiesBuilder in all modules (apache#23308)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
terrymanu authored Jan 3, 2023
1 parent 56c416c commit e02e0e4
Show file tree
Hide file tree
Showing 84 changed files with 489 additions and 454 deletions.
7 changes: 7 additions & 0 deletions agent/plugins/metrics/type/prometheus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
7 changes: 7 additions & 0 deletions agent/plugins/tracing/type/jaeger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
</properties>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
7 changes: 7 additions & 0 deletions agent/plugins/tracing/type/opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
</properties>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
7 changes: 7 additions & 0 deletions agent/plugins/tracing/type/opentracing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
7 changes: 7 additions & 0 deletions distsql/statement/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,12 @@
<artifactId>shardingsphere-sql-parser-statement</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,8 +49,7 @@ public void assertConvert() {

private Collection<DataSourceSegment> createDataSourceSegments() {
Collection<DataSourceSegment> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 7 additions & 1 deletion infra/binder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<artifactId>shardingsphere-sql-parser-engine</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-parser</artifactId>
Expand All @@ -49,5 +48,12 @@
<artifactId>shardingsphere-infra-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,9 +76,8 @@ public void assertDecideWhenNotConfigSqlFederationEnabled() {
@Test
public void assertDecideWhenExecuteNotSelectStatement() {
Collection<ShardingSphereRule> 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());
Expand All @@ -87,9 +88,8 @@ public void assertDecideWhenExecuteNotSelectStatement() {
@Test
public void assertDecideWhenConfigSingleMatchedRule() {
Collection<ShardingSphereRule> 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());
Expand All @@ -100,9 +100,8 @@ public void assertDecideWhenConfigSingleMatchedRule() {
@Test
public void assertDecideWhenConfigSingleNotMatchedRule() {
Collection<ShardingSphereRule> 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());
Expand All @@ -113,9 +112,8 @@ public void assertDecideWhenConfigSingleNotMatchedRule() {
@Test
public void assertDecideWhenConfigMultiRule() {
Collection<ShardingSphereRule> 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());
Expand Down
6 changes: 6 additions & 0 deletions infra/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"));
}
Expand Down
Loading

0 comments on commit e02e0e4

Please sign in to comment.