Skip to content

Commit

Permalink
Merge branch 'master' into distsql
Browse files Browse the repository at this point in the history
# Conflicts:
#	infra/common/src/main/java/org/apache/shardingsphere/infra/props/PropertiesConverter.java
  • Loading branch information
Pace2Car committed Nov 21, 2023
2 parents 9af67fd + 46fc668 commit 2b2b61b
Show file tree
Hide file tree
Showing 51 changed files with 133 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ ShardingSphere 对在 GraalVM Native Image 下的可用性的验证,是通过
在 GraalVM Native Image 下的单元测试覆盖率。请贡献者不要使用 `io.kotest:kotest-runner-junit5-jvm:5.5.4` 等在 `test listener` mode 下
failed to discover tests 的测试库。

ShardingSphere 定义了 `shardingsphere-infra-nativetest` 的 Maven Module 用于为 native Test 提供小型的单元测试子集,
ShardingSphere 定义了 `shardingsphere-test-native` 的 Maven Module 用于为 native Test 提供小型的单元测试子集,
此单元测试子集避免了使用 Mockito 等 native Test 下无法使用的第三方库。

ShardingSphere 定义了 `nativeTestInShardingSphere` 的 Maven Profile 用于为 `shardingsphere-infra-nativetest` 模块执行 nativeTest 。
ShardingSphere 定义了 `nativeTestInShardingSphere` 的 Maven Profile 用于为 `shardingsphere-test-native` 模块执行 nativeTest 。

假设贡献者处于新的 Ubuntu 22.04.3 LTS 实例下,其可通过如下 bash 命令通过 SDKMAN! 管理 JDK 和工具链,
并为 `shardingsphere-infra-nativetest` 子模块执行 nativeTest。
并为 `shardingsphere-test-native` 子模块执行 nativeTest。

```bash
sudo apt install unzip zip curl sed -y
Expand All @@ -247,11 +247,11 @@ ShardingSphere 定义了 `generateMetadata` 的 Maven Profile 用于在 GraalVM
已有的 GraalVM Reachability Metadata 文件。可通过如下 bash 命令简单处理此流程。贡献者仍可能需要手动调整具体的 JSON 条目,并在适当的时候
调整 Maven Profile 和 GraalVM Tracing Agent 的 Filter 链。

以下命令仅为 `shardingsphere-infra-nativetest` 生成 Conditional 形态的 GraalVM Reachability Metadata 的一个举例。生成的 GraalVM
以下命令仅为 `shardingsphere-test-native` 生成 Conditional 形态的 GraalVM Reachability Metadata 的一个举例。生成的 GraalVM
Reachability Metadata 位于 `shardingsphere-infra-reachability-metadata` 子模块下。

对于测试类和测试文件独立使用的 GraalVM Reachability Metadata,贡献者应该放置到
`${user.dir}/infra/nativetest/src/test/resources/META-INF/native-image/shardingsphere-infra-nativetest-test-metadata/`
`${user.dir}/test/natived/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/`
文件夹下。`${}` 内为相关子模块对应的 POM 4.0 的常规系统变量,自行替换。

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ and then build it as GraalVM Native Image for nativeTest to test Unit Test Cover
Please do not use `io.kotest:kotest-runner-junit5-jvm:5.5.4` and some third-party test libraries, they are in `test listener`
mode failed to discover tests.

ShardingSphere defines the Maven Module of `shardingsphere-infra-nativetest` to provide a small subset of unit tests for native Test.
ShardingSphere defines the Maven Module of `shardingsphere-test-native` to provide a small subset of unit tests for native Test.
This subset of unit tests avoids the use of third-party libraries such as Mockito that are not available under native Test.

ShardingSphere defines the Maven Profile of `nativeTestInShardingSphere` for executing nativeTest for the `shardingsphere-infra-nativetest` module.
ShardingSphere defines the Maven Profile of `nativeTestInShardingSphere` for executing nativeTest for the `shardingsphere-test-native` module.

Assuming that the contributor is under a new Ubuntu 22.04.3 LTS instance, Contributors can manage the JDK and tool chain through
`SDKMAN!` through the following bash command, and execute nativeTest for the `shardingsphere-infra-nativetest` submodule.
`SDKMAN!` through the following bash command, and execute nativeTest for the `shardingsphere-test-native` submodule.

```bash
sudo apt install unzip zip curl sed -y
Expand Down Expand Up @@ -261,11 +261,11 @@ Metadata files in a specific directory.
This process can be easily handled with the following bash command. Contributors may still need to manually adjust specific
JSON entries and GraalVM Tracing Agent Filter chain of Maven Profile.

The following command is only an example of using `shardingsphere-infra-nativetest` to generate GraalVM Reachability Metadata
The following command is only an example of using `shardingsphere-test-native` to generate GraalVM Reachability Metadata
in Conditional form. Generated GraalVM Reachability Metadata is located under the `shardingsphere-infra-reachability-metadata` submodule.

For GraalVM Reachability Metadata used independently by test classes and test files, contributors should place
`${user.dir}/infra/nativetest/src/test/resources/META-INF/native-image/shardingsphere-infra-nativetest-test-metadata/`
`${user.dir}/infra/nativetest/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/`
folder. `${}` contains the regular system variables of POM 4.0 corresponding to the relevant submodules, which can be replaced by yourself.

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAuditorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
Expand All @@ -46,7 +47,7 @@ public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
while (data.hasNext()) {
Entry<String, AlgorithmConfiguration> entry = data.next();
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps()));
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps())));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingKeyGeneratorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
Expand Down Expand Up @@ -48,7 +49,7 @@ public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
while (data.hasNext()) {
Entry<String, AlgorithmConfiguration> entry = data.next();
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps().toString()));
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps())));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
import org.apache.shardingsphere.sharding.distsql.statement.ShowUnusedShardingAuditorsStatement;
Expand Down Expand Up @@ -50,7 +51,7 @@ public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereDatabase
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
for (Entry<String, AlgorithmConfiguration> entry : shardingRuleConfig.getAuditors().entrySet()) {
if (!inUsedAuditors.contains(entry.getKey())) {
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps().toString()));
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps())));
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingAuditorsExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAuditorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -54,7 +55,7 @@ void assertGetRowData() {
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("sharding_key_required_auditor"));
assertThat(row.getCell(2), is("DML_SHARDING_CONDITIONS"));
assertThat(row.getCell(3).toString(), is("{}"));
assertThat(row.getCell(3).toString(), is("{\"key\":\"value\"}"));
}

@Test
Expand All @@ -70,7 +71,7 @@ void assertGetColumnNames() {

private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", PropertiesBuilder.build(new Property("key", "value"))));
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingKeyGeneratorExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingKeyGeneratorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -55,7 +56,7 @@ void assertGetRowData() {
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("snowflake"));
assertThat(row.getCell(2), is("SNOWFLAKE"));
assertThat(row.getCell(3), is("{}"));
assertThat(row.getCell(3), is("{\"key\":\"value\"}"));
}

@Test
Expand All @@ -72,7 +73,7 @@ void assertGetColumnNames() {

private ShardingRuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getKeyGenerators().put("snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
result.getKeyGenerators().put("snowflake", new AlgorithmConfiguration("SNOWFLAKE", PropertiesBuilder.build(new Property("key", "value"))));
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.shardingsphere.sharding.distsql.handler.query.ShowUnusedShardingAuditorsExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.ShowUnusedShardingAuditorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;

import java.util.Collection;
Expand All @@ -53,7 +55,7 @@ void assertGetRowData() {
LocalDataQueryResultRow row = iterator.next();
assertThat(row.getCell(1), is("fixture"));
assertThat(row.getCell(2), is("FIXTURE"));
assertThat(row.getCell(3), is("{}"));
assertThat(row.getCell(3), is("{\"key\":\"value\"}"));
}

@Test
Expand All @@ -78,7 +80,7 @@ private ShardingSphereDatabase mockDatabase() {
private RuleConfiguration createRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
result.getAuditors().put("fixture", new AlgorithmConfiguration("FIXTURE", null));
result.getAuditors().put("fixture", new AlgorithmConfiguration("FIXTURE", PropertiesBuilder.build(new Property("key", "value"))));
result.getAutoTables().add(createShardingAutoTableRuleConfiguration());
return result;
}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion infra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<module>expr</module>
<module>util</module>
<module>reachability-metadata</module>
<module>nativetest</module>
<module>algorithm</module>
</modules>
</project>
1 change: 0 additions & 1 deletion infra/reachability-metadata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
</parent>
<artifactId>shardingsphere-infra-reachability-metadata</artifactId>
<name>${project.artifactId}</name>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.globalclock.distsql.statement.queryable.ShowGlobalClockRuleStatement;
import org.apache.shardingsphere.infra.props.PropertiesConverter;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -36,7 +37,8 @@ public final class ShowGlobalClockRuleExecutor implements MetaDataRequiredQuerya
@Override
public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereMetaData metaData, final ShowGlobalClockRuleStatement sqlStatement) {
GlobalClockRuleConfiguration ruleConfig = metaData.getGlobalRuleMetaData().getSingleRule(GlobalClockRule.class).getConfiguration();
return Collections.singleton(new LocalDataQueryResultRow(ruleConfig.getType(), ruleConfig.getProvider(), String.valueOf(ruleConfig.isEnabled()), ruleConfig.getProps().toString()));
return Collections.singleton(new LocalDataQueryResultRow(ruleConfig.getType(), ruleConfig.getProvider(),
String.valueOf(ruleConfig.isEnabled()), PropertiesConverter.convert(ruleConfig.getProps())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package org.apache.shardingsphere.globalclock.distsql.handler.query;

import org.apache.shardingsphere.globalclock.api.config.GlobalClockRuleConfiguration;
import org.apache.shardingsphere.globalclock.core.rule.GlobalClockRule;
import org.apache.shardingsphere.globalclock.core.rule.builder.DefaultGlobalClockRuleConfigurationBuilder;
import org.apache.shardingsphere.globalclock.distsql.statement.queryable.ShowGlobalClockRuleStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.globalclock.distsql.statement.queryable.ShowGlobalClockRuleStatement;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;

import java.util.Collection;
Expand All @@ -51,7 +53,7 @@ void assertGlobalClockRule() {
assertThat(row.getCell(1), is("TSO"));
assertThat(row.getCell(2), is("local"));
assertThat(row.getCell(3), is("false"));
assertThat(row.getCell(4), is("{}"));
assertThat(row.getCell(4), is("{\"key\":\"value\"}"));
}

@Test
Expand All @@ -68,7 +70,8 @@ void assertGetColumnNames() {

private ShardingSphereMetaData mockMetaData() {
GlobalClockRule sqlParserRule = mock(GlobalClockRule.class);
when(sqlParserRule.getConfiguration()).thenReturn(new DefaultGlobalClockRuleConfigurationBuilder().build());
GlobalClockRuleConfiguration globalClockRuleConfig = new GlobalClockRuleConfiguration("TSO", "local", false, PropertiesBuilder.build(new Property("key", "value")));
when(sqlParserRule.getConfiguration()).thenReturn(globalClockRuleConfig);
return new ShardingSphereMetaData(new LinkedHashMap<>(), mock(ResourceMetaData.class),
new RuleMetaData(Collections.singleton(sqlParserRule)), new ConfigurationProperties(new Properties()));
}
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<include>org.apache.shardingsphere.infra.nativetest.**</include>
<include>org.apache.shardingsphere.test.natived.**</include>
</includes>
</configuration>
</plugin>
Expand All @@ -1041,8 +1041,8 @@
<defaultMode>Conditional</defaultMode>
<modes>
<conditional>
<userCodeFilterPath>${user.dir}/infra/nativetest/native-image-filter/user-code-filter.json</userCodeFilterPath>
<extraFilterPath>${user.dir}/infra/nativetest/native-image-filter/extra-filter.json</extraFilterPath>
<userCodeFilterPath>${user.dir}/test/natived/native-image-filter/user-code-filter.json</userCodeFilterPath>
<extraFilterPath>${user.dir}/test/natived/native-image-filter/extra-filter.json</extraFilterPath>
<parallel>true</parallel>
</conditional>
</modes>
Expand Down Expand Up @@ -1088,7 +1088,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>org.apache.shardingsphere.infra.nativetest.**</include>
<include>org.apache.shardingsphere.test.natived.**</include>
</includes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
<column name="type" />
<column name="props" />
</metadata>
<row values="auditor_constant| IT.AUDITOR.FIXTURE| {}" />
<row values="auditor_constant| IT.AUDITOR.FIXTURE| " />
</dataset>
Loading

0 comments on commit 2b2b61b

Please sign in to comment.