This is an automated email from the ASF dual-hosted git repository.
azexin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e377596cc4e Simplify PipelineContextUtil mocking; Update ci.yml
triggering (#23895)
e377596cc4e is described below
commit e377596cc4e18a3ee06dd0ba726f1b5b915f1bd5
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Wed Feb 1 15:45:35 2023 +0800
Simplify PipelineContextUtil mocking; Update ci.yml triggering (#23895)
* Simplify PipelineContextUtil mocking
* Trigger CI on test/it/** changed
---
.github/workflows/ci.yml | 4 +-
.../pipeline/core/util/PipelineContextUtil.java | 55 +++++-----------------
.../config_sharding_sphere_jdbc_source.yaml | 12 +++++
3 files changed, 27 insertions(+), 44 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 63dfd5f2a95..a44219895ce 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -26,7 +26,7 @@ on:
- '**/src/main/**'
- '**/src/test/**'
- '!distribution/**'
- - '!test/it/**'
+ - 'test/it/**'
- '!test/e2e/**'
- 'test/e2e/driver/**'
- '!*.md'
@@ -38,7 +38,7 @@ on:
- '**/src/main/**'
- '**/src/test/**'
- '!distribution/**'
- - '!test/it/**'
+ - 'test/it/**'
- '!test/e2e/**'
- 'test/e2e/driver/**'
- '!*.md'
diff --git
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtil.java
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtil.java
index c1ea236aadc..ab3949cc386 100644
---
a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtil.java
+++
b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/util/PipelineContextUtil.java
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.test.it.data.pipeline.core.util;
import lombok.SneakyThrows;
-import org.apache.commons.lang3.concurrent.ConcurrentException;
-import org.apache.commons.lang3.concurrent.LazyInitializer;
import
org.apache.shardingsphere.data.pipeline.api.config.job.MigrationJobConfiguration;
import
org.apache.shardingsphere.data.pipeline.api.config.process.PipelineProcessConfiguration;
import
org.apache.shardingsphere.data.pipeline.api.datasource.config.impl.ShardingSpherePipelineDataSourceConfiguration;
@@ -39,10 +37,11 @@ import
org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineProcessC
import
org.apache.shardingsphere.data.pipeline.yaml.process.YamlPipelineReadConfiguration;
import
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
-import org.apache.shardingsphere.infra.database.DefaultDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
import
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
+import
org.apache.shardingsphere.infra.yaml.config.swapper.mode.YamlModeConfigurationSwapper;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
@@ -56,7 +55,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
public final class PipelineContextUtil {
@@ -64,51 +62,23 @@ public final class PipelineContextUtil {
private static final PipelineChannelCreator PIPELINE_CHANNEL_CREATOR = new
MemoryPipelineChannelCreator();
- private static final ClusterPersistRepositoryConfiguration
PERSIST_REPOSITORY_CONFIG;
-
- private static final LazyInitializer<ClusterPersistRepository>
PERSIST_REPOSITORY_LAZY_INITIALIZER;
-
- static {
- PERSIST_REPOSITORY_CONFIG = new
ClusterPersistRepositoryConfiguration("ZooKeeper", "test",
EmbedTestingServer.getConnectionString(), new Properties());
- PERSIST_REPOSITORY_LAZY_INITIALIZER = new
LazyInitializer<ClusterPersistRepository>() {
-
- @Override
- protected ClusterPersistRepository initialize() {
- ClusterPersistRepository result =
TypedSPILoader.getService(ClusterPersistRepository.class,
PERSIST_REPOSITORY_CONFIG.getType(), PERSIST_REPOSITORY_CONFIG.getProps());
- result.init(PERSIST_REPOSITORY_CONFIG);
- return result;
- }
- };
- }
-
/**
* Mock mode configuration and context manager.
*/
+ @SneakyThrows
public static void mockModeConfigAndContextManager() {
EmbedTestingServer.start();
- mockModeConfig();
- mockContextManager();
- }
-
- private static void mockModeConfig() {
- if (null == PipelineContext.getModeConfig()) {
- PipelineContext.initModeConfig(createModeConfig());
- }
- }
-
- private static ModeConfiguration createModeConfig() {
- return new ModeConfiguration("Cluster", PERSIST_REPOSITORY_CONFIG);
- }
-
- private static void mockContextManager() {
if (null != PipelineContext.getContextManager()) {
return;
}
ShardingSpherePipelineDataSourceConfiguration pipelineDataSourceConfig
= new ShardingSpherePipelineDataSourceConfiguration(
-
ConfigurationFileUtil.readFile("config_sharding_sphere_jdbc_source.yaml"));
+
ConfigurationFileUtil.readFileAndIgnoreComments("config_sharding_sphere_jdbc_source.yaml"));
+ YamlRootConfiguration rootConfig = (YamlRootConfiguration)
pipelineDataSourceConfig.getDataSourceConfiguration();
+ ModeConfiguration modeConfig = new
YamlModeConfigurationSwapper().swapToObject(rootConfig.getMode());
+ PipelineContext.initModeConfig(modeConfig);
ShardingSphereDataSource dataSource = (ShardingSphereDataSource)
PipelineDataSourceFactory.newInstance(pipelineDataSourceConfig).getDataSource();
ContextManager contextManager = getContextManager(dataSource);
- MetaDataPersistService persistService = new
MetaDataPersistService(getClusterPersistRepository());
+ MetaDataPersistService persistService = new
MetaDataPersistService(getClusterPersistRepository((ClusterPersistRepositoryConfiguration)
modeConfig.getRepository()));
MetaDataContexts metaDataContexts =
renewMetaDataContexts(contextManager.getMetaDataContexts(), persistService);
PipelineContext.initContextManager(new
ContextManager(metaDataContexts, contextManager.getInstanceContext()));
}
@@ -118,16 +88,17 @@ public final class PipelineContextUtil {
return (ContextManager)
Plugins.getMemberAccessor().get(ShardingSphereDataSource.class.getDeclaredField("contextManager"),
dataSource);
}
- @SneakyThrows(ConcurrentException.class)
- private static ClusterPersistRepository getClusterPersistRepository() {
- return PERSIST_REPOSITORY_LAZY_INITIALIZER.get();
+ private static ClusterPersistRepository getClusterPersistRepository(final
ClusterPersistRepositoryConfiguration repositoryConfig) {
+ ClusterPersistRepository result =
TypedSPILoader.getService(ClusterPersistRepository.class,
repositoryConfig.getType(), repositoryConfig.getProps());
+ result.init(repositoryConfig);
+ return result;
}
private static MetaDataContexts renewMetaDataContexts(final
MetaDataContexts old, final MetaDataPersistService persistService) {
Map<String, ShardingSphereTable> tables = new HashMap<>(3, 1);
tables.put("t_order", new ShardingSphereTable("t_order",
Arrays.asList(new ShardingSphereColumn("order_id", Types.INTEGER, true, false,
false, true, false),
new ShardingSphereColumn("user_id", Types.VARCHAR, false,
false, false, true, false)), Collections.emptyList(), Collections.emptyList()));
-
old.getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).putAll(tables);
+
old.getMetaData().getDatabase("logic_db").getSchema("logic_db").putAll(tables);
return new MetaDataContexts(persistService, old.getMetaData());
}
diff --git
a/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml
b/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml
index 96c67e79a28..a79c3061d98 100644
---
a/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml
+++
b/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml
@@ -17,6 +17,18 @@
databaseName: logic_db
+mode:
+ type: Cluster
+ repository:
+ type: ZooKeeper
+ props:
+ namespace: test
+ server-lists: localhost:3181
+ retryIntervalMilliseconds: 500
+ timeToLiveSeconds: 60
+ maxRetries: 3
+ operationTimeoutMilliseconds: 500
+
dataSources:
ds_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource