This is an automated email from the ASF dual-hosted git repository. menghaoran 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 420722c7eff Merge similar fixture in module shardingsphere-infra-common (#19700) 420722c7eff is described below commit 420722c7eff90b3649563c97449a09d59e558504 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Fri Jul 29 23:39:38 2022 +0800 Merge similar fixture in module shardingsphere-infra-common (#19700) --- .../infra/datanode/DataNodeBuilder.java | 6 +- .../RuleConfigurationCheckerFactoryTest.java | 4 +- .../checker/RuleConfigurationCheckerFixture.java | 10 +-- .../infra/datanode/DataNodeBuilderFactoryTest.java | 9 +-- .../infra/datanode/DataNodesTest.java | 4 +- ...odeBuilder.java => DataNodeBuilderFixture.java} | 8 +- ...estShardingSphereRule.java => FixtureRule.java} | 4 +- .../infra/fixture/TestRuleConfiguration.java | 24 ------ .../schema/builder/GenericSchemaBuilderTest.java | 52 +++++------- ...uleBasedSchemaMetaDataDecoratorFactoryTest.java | 4 +- ...nedFixtureRuleBasedSchemaMetaDataDecorator.java | 43 ---------- ...> RuleBasedSchemaMetaDataDecoratorFixture.java} | 2 +- .../fixture/rule/DataNodeContainedFixtureRule.java | 94 ---------------------- .../database/DatabaseRuleBuilderFactoryTest.java | 4 +- .../builder/database/DatabaseRulesBuilderTest.java | 4 +- ...e.shardingsphere.infra.datanode.DataNodeBuilder | 2 +- ....decorator.spi.RuleBasedSchemaMetaDataDecorator | 3 +- 17 files changed, 53 insertions(+), 224 deletions(-) diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilder.java index 923533e48ae..6b16748d878 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilder.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilder.java @@ -32,11 +32,11 @@ import java.util.Collection; public interface DataNodeBuilder<T extends ShardingSphereRule> extends OrderedSPI<T> { /** - * Build data node. + * Build data nodes. * - * @param dataNodes data node collection + * @param dataNodes data nodes * @param rule rule - * @return data node collection + * @return data nodes */ Collection<DataNode> build(Collection<DataNode> dataNodes, T rule); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java index 43089cceaba..c7016035565 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.infra.config.checker; -import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration; import org.apache.shardingsphere.infra.config.checker.fixture.TestRuleConfigurationWithoutChecker; +import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.junit.Test; import java.util.Optional; @@ -33,7 +33,7 @@ public final class RuleConfigurationCheckerFactoryTest { @SuppressWarnings("rawtypes") @Test public void assertFindInstance() { - Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(new TestRuleConfiguration()); + Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(new FixtureRuleConfiguration()); assertTrue(checker.isPresent()); assertThat(checker.get(), instanceOf(RuleConfigurationCheckerFixture.class)); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFixture.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFixture.java index 36a817f95c6..551d3aa2a78 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFixture.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFixture.java @@ -17,17 +17,17 @@ package org.apache.shardingsphere.infra.config.checker; -import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration; +import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import javax.sql.DataSource; import java.util.Collection; import java.util.Map; -public final class RuleConfigurationCheckerFixture implements RuleConfigurationChecker<TestRuleConfiguration> { +public final class RuleConfigurationCheckerFixture implements RuleConfigurationChecker<FixtureRuleConfiguration> { @Override - public void check(final String databaseName, final TestRuleConfiguration config, final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules) { + public void check(final String databaseName, final FixtureRuleConfiguration config, final Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule> rules) { } @@ -37,7 +37,7 @@ public final class RuleConfigurationCheckerFixture implements RuleConfigurationC } @Override - public Class<TestRuleConfiguration> getTypeClass() { - return TestRuleConfiguration.class; + public Class<FixtureRuleConfiguration> getTypeClass() { + return FixtureRuleConfiguration.class; } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactoryTest.java index 055783481ec..40c0504e24d 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactoryTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeBuilderFactoryTest.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.infra.datanode; -import org.apache.shardingsphere.infra.fixture.TestDataSourceContainedDataNodeBuilder; -import org.apache.shardingsphere.infra.fixture.TestShardingSphereRule; +import org.apache.shardingsphere.infra.fixture.DataNodeBuilderFixture; +import org.apache.shardingsphere.infra.fixture.FixtureRule; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.junit.Test; @@ -28,16 +28,15 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; public final class DataNodeBuilderFactoryTest { @SuppressWarnings("rawtypes") @Test public void assertGetInstances() { - TestShardingSphereRule rule = mock(TestShardingSphereRule.class); + FixtureRule rule = new FixtureRule(); Map<ShardingSphereRule, DataNodeBuilder> actual = DataNodeBuilderFactory.getInstances(Collections.singleton(rule)); assertThat(actual.size(), is(1)); - assertThat(actual.get(rule), instanceOf(TestDataSourceContainedDataNodeBuilder.class)); + assertThat(actual.get(rule), instanceOf(DataNodeBuilderFixture.class)); } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java index fbb1376bf31..8622dec59aa 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.infra.datanode; -import org.apache.shardingsphere.infra.fixture.TestShardingSphereRule; +import org.apache.shardingsphere.infra.fixture.FixtureRule; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule; @@ -134,7 +134,7 @@ public final class DataNodesTest { } private ShardingSphereRule mockDataSourceContainedRule() { - DataSourceContainedRule result = mock(TestShardingSphereRule.class); + DataSourceContainedRule result = mock(FixtureRule.class); when(result.getDataSourceMapper()).thenReturn(READ_WRITE_SPLITTING_DATASOURCE_MAP); return result; } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestDataSourceContainedDataNodeBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/DataNodeBuilderFixture.java similarity index 85% rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestDataSourceContainedDataNodeBuilder.java rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/DataNodeBuilderFixture.java index 94198fe2747..61a43d3ff74 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestDataSourceContainedDataNodeBuilder.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/DataNodeBuilderFixture.java @@ -24,10 +24,10 @@ import org.apache.shardingsphere.infra.datanode.DataNodeUtil; import java.util.Collection; import java.util.LinkedList; -public final class TestDataSourceContainedDataNodeBuilder implements DataNodeBuilder<TestShardingSphereRule> { +public final class DataNodeBuilderFixture implements DataNodeBuilder<FixtureRule> { @Override - public Collection<DataNode> build(final Collection<DataNode> dataNodes, final TestShardingSphereRule rule) { + public Collection<DataNode> build(final Collection<DataNode> dataNodes, final FixtureRule rule) { Collection<DataNode> result = new LinkedList<>(); for (DataNode each : dataNodes) { result.addAll(DataNodeUtil.buildDataNode(each, rule.getDataSourceMapper())); @@ -41,7 +41,7 @@ public final class TestDataSourceContainedDataNodeBuilder implements DataNodeBui } @Override - public Class<TestShardingSphereRule> getTypeClass() { - return TestShardingSphereRule.class; + public Class<FixtureRule> getTypeClass() { + return FixtureRule.class; } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestShardingSphereRule.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java similarity index 90% rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestShardingSphereRule.java rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java index 1c35962cbe5..de763a3fae4 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestShardingSphereRule.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java @@ -27,7 +27,7 @@ import java.util.Map; import static org.mockito.Mockito.mock; -public final class TestShardingSphereRule implements DatabaseRule, DataSourceContainedRule { +public final class FixtureRule implements DatabaseRule, DataSourceContainedRule { @Override public RuleConfiguration getConfiguration() { @@ -41,6 +41,6 @@ public final class TestShardingSphereRule implements DatabaseRule, DataSourceCon @Override public String getType() { - return TestShardingSphereRule.class.getSimpleName(); + return FixtureRule.class.getSimpleName(); } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestRuleConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestRuleConfiguration.java deleted file mode 100644 index 21b11d9da8f..00000000000 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/fixture/TestRuleConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.infra.fixture; - -import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.config.function.EnhancedRuleConfiguration; - -public final class TestRuleConfiguration implements RuleConfiguration, EnhancedRuleConfiguration { -} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java index ecc8078aa74..200d8737fbd 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java @@ -23,16 +23,13 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.database.schema.fixture.rule.TableContainedFixtureRule; -import org.apache.shardingsphere.infra.metadata.database.schema.fixture.rule.DataNodeContainedFixtureRule; import org.apache.shardingsphere.infra.metadata.database.schema.loader.SchemaMetaDataLoaderEngine; import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.TableMetaData; -import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.junit.MockitoJUnitRunner; @@ -41,9 +38,9 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import java.util.Map; import java.util.Properties; +import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; @@ -56,47 +53,53 @@ import static org.mockito.Mockito.mockStatic; @RunWith(MockitoJUnitRunner.class) public final class GenericSchemaBuilderTest { - @Mock - private DatabaseType databaseType; - private GenericSchemaBuilderMaterials materials; - private MockedStatic<SchemaMetaDataLoaderEngine> schemaMetaDataLoaderEngine; + private MockedStatic<SchemaMetaDataLoaderEngine> engine; @Before public void setUp() { - Collection<ShardingSphereRule> rules = Arrays.asList(new TableContainedFixtureRule(), new DataNodeContainedFixtureRule()); - materials = new GenericSchemaBuilderMaterials(databaseType, databaseType, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, - mock(DataSource.class)), rules, new ConfigurationProperties(new Properties()), DefaultDatabase.LOGIC_NAME); - schemaMetaDataLoaderEngine = mockStatic(SchemaMetaDataLoaderEngine.class); + DatabaseType databaseType = mock(DatabaseType.class); + materials = new GenericSchemaBuilderMaterials(databaseType, databaseType, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, mock(DataSource.class)), + Collections.singleton(new TableContainedFixtureRule()), new ConfigurationProperties(new Properties()), DefaultDatabase.LOGIC_NAME); + engine = mockStatic(SchemaMetaDataLoaderEngine.class); + } + + @After + public void cleanUp() { + engine.close(); } @Test public void assertLoadWithExistedTableName() throws SQLException { Collection<String> tableNames = Collections.singletonList("data_node_routed_table1"); - schemaMetaDataLoaderEngine.when(() -> SchemaMetaDataLoaderEngine.load(any(), any())).thenReturn(mockSchemaMetaDataMap(tableNames, materials)); + engine.when(() -> SchemaMetaDataLoaderEngine.load(any(), any())).thenReturn(createSchemaMetaDataMap(tableNames, materials)); assertFalse(GenericSchemaBuilder.build(tableNames, materials).get(DefaultDatabase.LOGIC_NAME).getTables().isEmpty()); } @Test public void assertLoadWithNotExistedTableName() throws SQLException { Collection<String> tableNames = Collections.singletonList("invalid_table"); - schemaMetaDataLoaderEngine.when(() -> SchemaMetaDataLoaderEngine.load(any(), any())).thenReturn(mockSchemaMetaDataMap(tableNames, materials)); + engine.when(() -> SchemaMetaDataLoaderEngine.load(any(), any())).thenReturn(createSchemaMetaDataMap(tableNames, materials)); assertTrue(GenericSchemaBuilder.build(tableNames, materials).get(DefaultDatabase.LOGIC_NAME).getTables().isEmpty()); } @Test public void assertLoadAllTables() throws SQLException { - Collection<String> tableNames = new DataNodeContainedFixtureRule().getTables(); - schemaMetaDataLoaderEngine.when(() -> SchemaMetaDataLoaderEngine.load(any(), any())).thenReturn(mockSchemaMetaDataMap(tableNames, materials)); + Collection<String> tableNames = Arrays.asList("data_node_routed_table1", "data_node_routed_table2"); + engine.when(() -> SchemaMetaDataLoaderEngine.load(any(), any())).thenReturn(createSchemaMetaDataMap(tableNames, materials)); Map<String, ShardingSphereSchema> actual = GenericSchemaBuilder.build(tableNames, materials); assertThat(actual.size(), is(1)); assertTables(new ShardingSphereSchema(actual.values().iterator().next().getTables()).getTables()); } - @After - public void cleanUp() { - schemaMetaDataLoaderEngine.close(); + private Map<String, SchemaMetaData> createSchemaMetaDataMap(final Collection<String> tableNames, final GenericSchemaBuilderMaterials materials) { + if (!tableNames.isEmpty() && (tableNames.contains("data_node_routed_table1") || tableNames.contains("data_node_routed_table2"))) { + Collection<TableMetaData> tableMetaDataList = tableNames.stream() + .map(each -> new TableMetaData(each, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())).collect(Collectors.toList()); + return Collections.singletonMap(materials.getDefaultSchemaName(), new SchemaMetaData(materials.getDefaultSchemaName(), tableMetaDataList)); + } + return Collections.emptyMap(); } private void assertTables(final Map<String, ShardingSphereTable> actual) { @@ -104,15 +107,4 @@ public final class GenericSchemaBuilderTest { assertTrue(actual.get("data_node_routed_table1").getColumns().isEmpty()); assertTrue(actual.get("data_node_routed_table2").getColumns().isEmpty()); } - - private Map<String, SchemaMetaData> mockSchemaMetaDataMap(final Collection<String> tableNames, final GenericSchemaBuilderMaterials materials) { - if (!tableNames.isEmpty() && (tableNames.contains("data_node_routed_table1") || tableNames.contains("data_node_routed_table2"))) { - Collection<TableMetaData> tableMetaDataList = new LinkedList<>(); - for (String each : tableNames) { - tableMetaDataList.add(new TableMetaData(each, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())); - } - return Collections.singletonMap(materials.getDefaultSchemaName(), new SchemaMetaData(materials.getDefaultSchemaName(), tableMetaDataList)); - } - return Collections.emptyMap(); - } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/spi/RuleBasedSchemaMetaDataDecoratorFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/spi/RuleBasedSchemaMetaDataDecoratorFactoryTest.java index 090dc27bead..3039a3df798 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/spi/RuleBasedSchemaMetaDataDecoratorFactoryTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/spi/RuleBasedSchemaMetaDataDecoratorFactoryTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.metadata.database.schema.builder.spi; import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecoratorFactory; -import org.apache.shardingsphere.infra.metadata.database.schema.fixture.loader.TableContainedFixtureSchemaMetaDataDecorator; +import org.apache.shardingsphere.infra.metadata.database.schema.fixture.loader.RuleBasedSchemaMetaDataDecoratorFixture; import org.apache.shardingsphere.infra.metadata.database.schema.fixture.rule.TableContainedFixtureRule; import org.junit.Test; @@ -32,6 +32,6 @@ public final class RuleBasedSchemaMetaDataDecoratorFactoryTest { @Test public void assertGetInstances() { TableContainedFixtureRule rule = new TableContainedFixtureRule(); - assertThat(RuleBasedSchemaMetaDataDecoratorFactory.getInstances(Collections.singleton(rule)).get(rule), instanceOf(TableContainedFixtureSchemaMetaDataDecorator.class)); + assertThat(RuleBasedSchemaMetaDataDecoratorFactory.getInstances(Collections.singleton(rule)).get(rule), instanceOf(RuleBasedSchemaMetaDataDecoratorFixture.class)); } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/DataNodeContainedFixtureRuleBasedSchemaMetaDataDecorator.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/DataNodeContainedFixtureRuleBasedSchemaMetaDataDecorator.java deleted file mode 100644 index 872126b3095..00000000000 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/DataNodeContainedFixtureRuleBasedSchemaMetaDataDecorator.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.infra.metadata.database.schema.fixture.loader; - -import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterials; -import org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator; -import org.apache.shardingsphere.infra.metadata.database.schema.fixture.rule.DataNodeContainedFixtureRule; -import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.SchemaMetaData; - -import java.util.Map; - -public final class DataNodeContainedFixtureRuleBasedSchemaMetaDataDecorator implements RuleBasedSchemaMetaDataDecorator<DataNodeContainedFixtureRule> { - - @Override - public Map<String, SchemaMetaData> decorate(final Map<String, SchemaMetaData> schemaMetaDataMap, final DataNodeContainedFixtureRule rule, final GenericSchemaBuilderMaterials materials) { - return schemaMetaDataMap; - } - - @Override - public int getOrder() { - return 2; - } - - @Override - public Class<DataNodeContainedFixtureRule> getTypeClass() { - return DataNodeContainedFixtureRule.class; - } -} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/TableContainedFixtureSchemaMetaDataDecorator.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/RuleBasedSchemaMetaDataDecoratorFixture.java similarity index 92% rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/TableContainedFixtureSchemaMetaDataDecorator.java rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/RuleBasedSchemaMetaDataDecoratorFixture.java index 4b9552fa825..5a52a14e90b 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/TableContainedFixtureSchemaMetaDataDecorator.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/loader/RuleBasedSchemaMetaDataDecoratorFixture.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.loader.model.Sch import java.util.Map; -public final class TableContainedFixtureSchemaMetaDataDecorator implements RuleBasedSchemaMetaDataDecorator<TableContainedFixtureRule> { +public final class RuleBasedSchemaMetaDataDecoratorFixture implements RuleBasedSchemaMetaDataDecorator<TableContainedFixtureRule> { @Override public Map<String, SchemaMetaData> decorate(final Map<String, SchemaMetaData> schemaMetaDataMap, final TableContainedFixtureRule rule, final GenericSchemaBuilderMaterials materials) { diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/rule/DataNodeContainedFixtureRule.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/rule/DataNodeContainedFixtureRule.java deleted file mode 100644 index 2402647cbac..00000000000 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/fixture/rule/DataNodeContainedFixtureRule.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.infra.metadata.database.schema.fixture.rule; - -import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule; -import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; - -import static org.mockito.Mockito.mock; - -public final class DataNodeContainedFixtureRule implements DataNodeContainedRule, TableContainedRule { - - private final Map<String, String> actualTableNameMaps = new HashMap<>(4, 1); - - public DataNodeContainedFixtureRule() { - actualTableNameMaps.putIfAbsent("data_node_routed_table1_0", "data_node_routed_table1"); - actualTableNameMaps.putIfAbsent("data_node_routed_table1_1", "data_node_routed_table1"); - actualTableNameMaps.putIfAbsent("data_node_routed_table2_0", "data_node_routed_table2"); - actualTableNameMaps.putIfAbsent("data_node_routed_table2_1", "data_node_routed_table2"); - } - - @Override - public Map<String, Collection<DataNode>> getAllDataNodes() { - return Collections.emptyMap(); - } - - @Override - public Collection<DataNode> getDataNodesByTableName(final String tableName) { - return Collections.emptyList(); - } - - @Override - public Optional<String> findFirstActualTable(final String logicTable) { - return Optional.empty(); - } - - @Override - public boolean isNeedAccumulate(final Collection<String> tables) { - return false; - } - - @Override - public Optional<String> findLogicTableByActualTable(final String actualTable) { - return Optional.ofNullable(actualTableNameMaps.get(actualTable)); - } - - @Override - public Collection<String> getTables() { - return new HashSet<>(actualTableNameMaps.values()); - } - - @Override - public Optional<String> findActualTableByCatalog(final String catalog, final String logicTable) { - return Optional.empty(); - } - - @Override - public Collection<String> getAllTables() { - return Collections.emptyList(); - } - - @Override - public RuleConfiguration getConfiguration() { - return mock(RuleConfiguration.class); - } - - @Override - public String getType() { - return DataNodeContainedFixtureRule.class.getSimpleName(); - } -} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactoryTest.java index b04969bf728..6e7d2706358 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactoryTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilderFactoryTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.rule.builder.database; import org.apache.shardingsphere.infra.config.RuleConfiguration; -import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration; +import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRuleBuilder; import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRuleConfiguration; import org.junit.Test; @@ -51,7 +51,7 @@ public final class DatabaseRuleBuilderFactoryTest { @Test public void assertGetInstanceMapWithComparator() { Iterator<RuleConfiguration> actual = DatabaseRuleBuilderFactory.getInstanceMap( - Arrays.asList(new FixtureDatabaseRuleConfiguration(), new TestRuleConfiguration()), Comparator.naturalOrder()).keySet().iterator(); + Arrays.asList(new FixtureDatabaseRuleConfiguration(), new FixtureRuleConfiguration()), Comparator.naturalOrder()).keySet().iterator(); assertThat(actual.next(), instanceOf(FixtureDatabaseRuleConfiguration.class)); assertFalse(actual.hasNext()); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilderTest.java index 2da4d030c3b..f5a4cdffa1c 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilderTest.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRulesBuilderTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.rule.builder.database; import org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration; -import org.apache.shardingsphere.infra.fixture.TestRuleConfiguration; +import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.builder.fixture.FixtureDatabaseRule; @@ -37,7 +37,7 @@ public final class DatabaseRulesBuilderTest { @Test public void assertBuild() { Iterator<ShardingSphereRule> actual = DatabaseRulesBuilder.build( - "foo_db", new DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), Collections.singleton(new TestRuleConfiguration())), mock(InstanceContext.class)).iterator(); + "foo_db", new DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), Collections.singleton(new FixtureRuleConfiguration())), mock(InstanceContext.class)).iterator(); assertThat(actual.next(), instanceOf(FixtureDatabaseRule.class)); assertFalse(actual.hasNext()); } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datanode.DataNodeBuilder b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datanode.DataNodeBuilder index 6c503539764..0db71dc8ee4 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datanode.DataNodeBuilder +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datanode.DataNodeBuilder @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.infra.fixture.TestDataSourceContainedDataNodeBuilder +org.apache.shardingsphere.infra.fixture.DataNodeBuilderFixture diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator index 95e186c690e..b18ad3c555c 100644 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator +++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.database.schema.decorator.spi.RuleBasedSchemaMetaDataDecorator @@ -15,5 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.infra.metadata.database.schema.fixture.loader.TableContainedFixtureSchemaMetaDataDecorator -org.apache.shardingsphere.infra.metadata.database.schema.fixture.loader.DataNodeContainedFixtureRuleBasedSchemaMetaDataDecorator +org.apache.shardingsphere.infra.metadata.database.schema.fixture.loader.RuleBasedSchemaMetaDataDecoratorFixture