This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 d2d46311d49 Remove getter for ShardingSphereDataSource (#17860)
d2d46311d49 is described below
commit d2d46311d494e49e3aae3f542a83ffecda7cdd28
Author: Liang Zhang <[email protected]>
AuthorDate: Sun May 22 21:36:06 2022 +0800
Remove getter for ShardingSphereDataSource (#17860)
---
.../core/datasource/ShardingSphereDataSource.java | 4 +--
.../datasource/ShardingSphereDataSourceTest.java | 41 +++++++++++++---------
.../spring/boot/SpringBootStarterTest.java | 18 +++++++---
.../boot/jndi/SpringBootJNDIDataSourceTest.java | 12 ++++++-
.../namespace/AbstractSpringNamespaceTest.java | 18 +++++++---
.../pipeline/core/util/PipelineContextUtil.java | 12 +++++--
6 files changed, 74 insertions(+), 31 deletions(-)
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
index 04f0c155a1c..81c09438640 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
@@ -17,13 +17,12 @@
package org.apache.shardingsphere.driver.jdbc.core.datasource;
-import lombok.Getter;
import org.apache.shardingsphere.driver.jdbc.adapter.AbstractDataSourceAdapter;
import org.apache.shardingsphere.driver.state.DriverStateContext;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.checker.RuleConfigurationCheckerFactory;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import
org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.config.scope.GlobalRuleConfiguration;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceType;
@@ -45,7 +44,6 @@ import java.util.stream.Collectors;
/**
* ShardingSphere data source.
*/
-@Getter
public final class ShardingSphereDataSource extends AbstractDataSourceAdapter
implements AutoCloseable {
private final String databaseName;
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
index 784e91d9f3a..963e31d1572 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
@@ -18,17 +18,20 @@
package org.apache.shardingsphere.driver.jdbc.core.datasource;
import com.zaxxer.hikari.HikariDataSource;
+import lombok.SneakyThrows;
import
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
import org.apache.shardingsphere.infra.state.StateType;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
import org.junit.After;
import org.junit.Test;
import javax.sql.DataSource;
+import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
@@ -52,11 +55,10 @@ public final class ShardingSphereDataSourceTest {
@Test
public void assertNewConstructorWithModeConfigurationOnly() throws
SQLException {
ShardingSphereDataSource actual = new
ShardingSphereDataSource(DefaultDatabase.LOGIC_NAME, null);
- assertThat(actual.getDatabaseName(), is(DefaultDatabase.LOGIC_NAME));
-
assertTrue(actual.getContextManager().getMetaDataContexts().getDatabaseMap().containsKey(DefaultDatabase.LOGIC_NAME));
-
assertTrue(actual.getContextManager().getTransactionContexts().getEngines().containsKey(DefaultDatabase.LOGIC_NAME));
-
assertThat(actual.getContextManager().getInstanceContext().getInstance().getState().getCurrentState(),
is(StateType.OK));
-
assertTrue(actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).isEmpty());
+
assertTrue(getContextManager(actual).getMetaDataContexts().getDatabaseMap().containsKey(DefaultDatabase.LOGIC_NAME));
+
assertTrue(getContextManager(actual).getTransactionContexts().getEngines().containsKey(DefaultDatabase.LOGIC_NAME));
+
assertThat(getContextManager(actual).getInstanceContext().getInstance().getState().getCurrentState(),
is(StateType.OK));
+
assertTrue(getContextManager(actual).getDataSourceMap(DefaultDatabase.LOGIC_NAME).isEmpty());
}
@Test
@@ -64,12 +66,11 @@ public final class ShardingSphereDataSourceTest {
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getURL()).thenReturn("jdbc:mock://127.0.0.1/foo_ds");
ShardingSphereDataSource actual = createShardingSphereDataSource(new
MockedDataSource(connection));
- assertThat(actual.getDatabaseName(), is(DefaultDatabase.LOGIC_NAME));
-
assertTrue(actual.getContextManager().getMetaDataContexts().getDatabaseMap().containsKey(DefaultDatabase.LOGIC_NAME));
-
assertTrue(actual.getContextManager().getTransactionContexts().getEngines().containsKey(DefaultDatabase.LOGIC_NAME));
-
assertThat(actual.getContextManager().getInstanceContext().getInstance().getState().getCurrentState(),
is(StateType.OK));
-
assertThat(actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).size(),
is(1));
-
assertThat(actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).get("ds").getConnection().getMetaData().getURL(),
is("jdbc:mock://127.0.0.1/foo_ds"));
+
assertTrue(getContextManager(actual).getMetaDataContexts().getDatabaseMap().containsKey(DefaultDatabase.LOGIC_NAME));
+
assertTrue(getContextManager(actual).getTransactionContexts().getEngines().containsKey(DefaultDatabase.LOGIC_NAME));
+
assertThat(getContextManager(actual).getInstanceContext().getInstance().getState().getCurrentState(),
is(StateType.OK));
+
assertThat(getContextManager(actual).getDataSourceMap(DefaultDatabase.LOGIC_NAME).size(),
is(1));
+
assertThat(getContextManager(actual).getDataSourceMap(DefaultDatabase.LOGIC_NAME).get("ds").getConnection().getMetaData().getURL(),
is("jdbc:mock://127.0.0.1/foo_ds"));
}
@Test
@@ -77,8 +78,7 @@ public final class ShardingSphereDataSourceTest {
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getURL()).thenReturn("jdbc:mock://127.0.0.1/foo_ds");
assertThat(((ShardingSphereConnection) createShardingSphereDataSource(
- new MockedDataSource(connection)).getConnection("",
"")).getConnectionManager().getConnections("ds", 1,
ConnectionMode.MEMORY_STRICTLY).get(0),
- is(connection));
+ new MockedDataSource(connection)).getConnection("",
"")).getConnectionManager().getConnections("ds", 1,
ConnectionMode.MEMORY_STRICTLY).get(0), is(connection));
}
private ShardingSphereDataSource createShardingSphereDataSource(final
DataSource dataSource) throws SQLException {
@@ -88,14 +88,14 @@ public final class ShardingSphereDataSourceTest {
@Test
public void assertEmptyDataSourceMap() throws SQLException {
ShardingSphereDataSource actual = new
ShardingSphereDataSource(DefaultDatabase.LOGIC_NAME, null);
-
assertTrue(actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).isEmpty());
+
assertTrue(getContextManager(actual).getDataSourceMap(DefaultDatabase.LOGIC_NAME).isEmpty());
assertThat(actual.getLoginTimeout(), is(0));
}
@Test
public void assertNotEmptyDataSourceMap() throws SQLException {
ShardingSphereDataSource actual =
createShardingSphereDataSource(createHikariDataSource());
-
assertThat(actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).size(),
is(1));
+
assertThat(getContextManager(actual).getDataSourceMap(DefaultDatabase.LOGIC_NAME).size(),
is(1));
assertThat(actual.getLoginTimeout(), is(15));
}
@@ -110,7 +110,7 @@ public final class ShardingSphereDataSourceTest {
public void assertClose() throws Exception {
ShardingSphereDataSource actual =
createShardingSphereDataSource(createHikariDataSource());
actual.close();
- Map<String, DataSource> dataSourceMap =
actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME);
+ Map<String, DataSource> dataSourceMap =
getContextManager(actual).getDataSourceMap(DefaultDatabase.LOGIC_NAME);
assertTrue(((HikariDataSource) dataSourceMap.get("ds")).isClosed());
}
@@ -118,10 +118,17 @@ public final class ShardingSphereDataSourceTest {
public void assertCloseWithDataSourceNames() throws Exception {
ShardingSphereDataSource actual =
createShardingSphereDataSource(createHikariDataSource());
actual.close(Collections.singleton("ds"));
- Map<String, DataSource> dataSourceMap =
actual.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME);
+ Map<String, DataSource> dataSourceMap =
getContextManager(actual).getDataSourceMap(DefaultDatabase.LOGIC_NAME);
assertTrue(((HikariDataSource) dataSourceMap.get("ds")).isClosed());
}
+ @SneakyThrows(ReflectiveOperationException.class)
+ private ContextManager getContextManager(final ShardingSphereDataSource
dataSource) {
+ Field field =
ShardingSphereDataSource.class.getDeclaredField("contextManager");
+ field.setAccessible(true);
+ return (ContextManager) field.get(dataSource);
+ }
+
private DataSource createHikariDataSource() {
HikariDataSource result = new HikariDataSource();
result.setJdbcUrl("jdbc:h2:mem:demo_ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
index 7b86dd44653..8ca98d18952 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.spring.boot;
+import lombok.SneakyThrows;
import
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
@@ -24,6 +25,7 @@ import
org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.datanode.DataNodeUtil;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RandomReplicaLoadBalanceAlgorithm;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
@@ -47,6 +49,7 @@ import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import javax.sql.DataSource;
+import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -70,7 +73,7 @@ public class SpringBootStarterTest {
@Test
public void assertDataSources() {
- Map<String, DataSource> dataSources =
dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources();
+ Map<String, DataSource> dataSources =
getContextManager(dataSource).getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources();
assertThat(dataSources.size(), is(2));
assertTrue(dataSources.containsKey("ds0"));
assertTrue(dataSources.containsKey("ds1"));
@@ -78,7 +81,7 @@ public class SpringBootStarterTest {
@Test
public void assertRules() {
- Collection<ShardingSphereRule> rules =
dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData("foo_db").getRuleMetaData().getRules();
+ Collection<ShardingSphereRule> rules =
getContextManager(dataSource).getMetaDataContexts().getDatabaseMetaData("foo_db").getRuleMetaData().getRules();
assertThat(rules.size(), is(5));
for (ShardingSphereRule each : rules) {
if (each instanceof ShardingRule) {
@@ -95,6 +98,13 @@ public class SpringBootStarterTest {
}
}
+ @SneakyThrows(ReflectiveOperationException.class)
+ private ContextManager getContextManager(final ShardingSphereDataSource
dataSource) {
+ Field field =
ShardingSphereDataSource.class.getDeclaredField("contextManager");
+ field.setAccessible(true);
+ return (ContextManager) field.get(dataSource);
+ }
+
private void assertShardingRule(final ShardingRule actual) {
assertThat(actual.getDataSourceNames(), is(new
HashSet<>(Arrays.asList("ds0", "ds1"))));
InlineShardingAlgorithm databaseShardingAlgorithm =
(InlineShardingAlgorithm)
actual.getShardingAlgorithms().get("databaseShardingAlgorithm");
@@ -196,7 +206,7 @@ public class SpringBootStarterTest {
@Test
public void assertProperties() {
-
assertTrue(dataSource.getContextManager().getMetaDataContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.SQL_SHOW));
-
assertThat(dataSource.getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE),
is(10));
+
assertTrue(getContextManager(dataSource).getMetaDataContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.SQL_SHOW));
+
assertThat(getContextManager(dataSource).getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.KERNEL_EXECUTOR_SIZE),
is(10));
}
}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java
index 36d0919f6c2..48ed573d283 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/jndi/SpringBootJNDIDataSourceTest.java
@@ -17,7 +17,9 @@
package org.apache.shardingsphere.spring.boot.jndi;
+import lombok.SneakyThrows;
import
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.spring.boot.jndi.fixture.InitialDataSourceInitialContextFactory;
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.BeforeClass;
@@ -31,6 +33,7 @@ import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import javax.naming.Context;
import javax.sql.DataSource;
+import java.lang.reflect.Field;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -55,9 +58,16 @@ public class SpringBootJNDIDataSourceTest {
@Test
public void assertDataSources() {
- Map<String, DataSource> dataSources =
dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources();
+ Map<String, DataSource> dataSources =
getContextManager(dataSource).getMetaDataContexts().getDatabaseMetaData("foo_db").getResource().getDataSources();
assertThat(dataSources.size(), is(2));
assertTrue(dataSources.containsKey("ds0"));
assertTrue(dataSources.containsKey("ds1"));
}
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ private ContextManager getContextManager(final ShardingSphereDataSource
dataSource) {
+ Field field =
ShardingSphereDataSource.class.getDeclaredField("contextManager");
+ field.setAccessible(true);
+ return (ContextManager) field.get(dataSource);
+ }
}
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java
index 2880ddda614..a50deb63e5d 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/namespace/AbstractSpringNamespaceTest.java
@@ -17,14 +17,16 @@
package org.apache.shardingsphere.spring.namespace;
+import lombok.SneakyThrows;
import
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import
org.apache.shardingsphere.readwritesplitting.strategy.type.StaticReadwriteSplittingStrategy;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
+import
org.apache.shardingsphere.readwritesplitting.strategy.type.StaticReadwriteSplittingStrategy;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.spring.transaction.TransactionTypeScanner;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
@@ -33,6 +35,7 @@ import
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import javax.annotation.Resource;
import javax.sql.DataSource;
+import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
@@ -49,9 +52,16 @@ public abstract class AbstractSpringNamespaceTest extends
AbstractJUnit4SpringCo
@Test
public void assertShardingSphereDataSource() {
-
assertDataSources(dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getResource().getDataSources());
-
assertSchemaRules(dataSource.getContextManager().getMetaDataContexts().getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules());
-
assertGlobalRules(dataSource.getContextManager().getMetaDataContexts().getGlobalRuleMetaData().getRules());
+
assertDataSources(getContextManager(dataSource).getMetaDataContexts().getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getResource().getDataSources());
+
assertSchemaRules(getContextManager(dataSource).getMetaDataContexts().getDatabaseMetaData(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRules());
+
assertGlobalRules(getContextManager(dataSource).getMetaDataContexts().getGlobalRuleMetaData().getRules());
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ private ContextManager getContextManager(final ShardingSphereDataSource
dataSource) {
+ Field field =
ShardingSphereDataSource.class.getDeclaredField("contextManager");
+ field.setAccessible(true);
+ return (ContextManager) field.get(dataSource);
}
private void assertDataSources(final Map<String, DataSource> actual) {
diff --git
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java
index c723aaac417..c5cca07f31f 100644
---
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java
+++
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java
@@ -39,6 +39,7 @@ import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositor
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
import
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryFactory;
+import java.lang.reflect.Field;
import java.sql.Types;
import java.util.Arrays;
import java.util.Collections;
@@ -93,13 +94,20 @@ public final class PipelineContextUtil {
}
ShardingSpherePipelineDataSourceConfiguration pipelineDataSourceConfig
= new ShardingSpherePipelineDataSourceConfiguration(
ConfigurationFileUtil.readFile("config_sharding_sphere_jdbc_source.yaml"));
- ShardingSphereDataSource shardingSphereDataSource =
(ShardingSphereDataSource)
PipelineDataSourceFactory.newInstance(pipelineDataSourceConfig).getDataSource();
- ContextManager contextManager =
shardingSphereDataSource.getContextManager();
+ ShardingSphereDataSource dataSource = (ShardingSphereDataSource)
PipelineDataSourceFactory.newInstance(pipelineDataSourceConfig).getDataSource();
+ ContextManager contextManager = getContextManager(dataSource);
MetaDataPersistService metaDataPersistService = new
MetaDataPersistService(getClusterPersistRepository());
MetaDataContexts metaDataContexts =
renewMetaDataContexts(contextManager.getMetaDataContexts(),
metaDataPersistService);
PipelineContext.initContextManager(new
ContextManager(metaDataContexts, contextManager.getTransactionContexts(),
contextManager.getInstanceContext()));
}
+ @SneakyThrows(ReflectiveOperationException.class)
+ private static ContextManager getContextManager(final
ShardingSphereDataSource dataSource) {
+ Field field =
ShardingSphereDataSource.class.getDeclaredField("contextManager");
+ field.setAccessible(true);
+ return (ContextManager) field.get(dataSource);
+ }
+
@SneakyThrows(ConcurrentException.class)
private static ClusterPersistRepository getClusterPersistRepository() {
return PERSIST_REPOSITORY_LAZY_INITIALIZER.get();