This is an automated email from the ASF dual-hosted git repository.
panjuan 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 3b05715 Finish add test cases for RuleSchemaMetaDataLoader (#6765)
3b05715 is described below
commit 3b057152ae24dbe22099f3fea17acd97280c20b1
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Aug 10 19:25:08 2020 +0800
Finish add test cases for RuleSchemaMetaDataLoader (#6765)
* Add RuleSchemaMetaDataLoaderTest.assertAsyncLoadFullDatabase
* Add RuleSchemaMetaDataLoaderTest.load by table name
---
...DataNodeRoutedFixtureRuleMetaDataDecorator.java | 44 ++++++++++++++++++++++
.../DataNodeRoutedFixtureRuleMetaDataLoader.java | 3 +-
.../schema/RuleSchemaMetaDataLoaderTest.java | 32 ++++++++++++----
...infra.metadata.schema.spi.RuleMetaDataDecorator | 18 +++++++++
4 files changed, 89 insertions(+), 8 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/fixture/decorator/DataNodeRoutedFixtureRuleMetaDataDecorator.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/fixture/decorator/DataNodeRoutedFixtureRuleMetaDataDecorator.java
new file mode 100644
index 0000000..6b9798a
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/fixture/decorator/DataNodeRoutedFixtureRuleMetaDataDecorator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.fixture.decorator;
+
+import
org.apache.shardingsphere.infra.metadata.fixture.rule.DataNodeRoutedFixtureRule;
+import
org.apache.shardingsphere.infra.metadata.schema.spi.RuleMetaDataDecorator;
+import
org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import
org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+
+import java.util.Collections;
+
+public final class DataNodeRoutedFixtureRuleMetaDataDecorator implements
RuleMetaDataDecorator<DataNodeRoutedFixtureRule> {
+
+ @Override
+ public TableMetaData decorate(final String tableName, final TableMetaData
tableMetaData, final DataNodeRoutedFixtureRule rule) {
+ ColumnMetaData columnMetaData = new ColumnMetaData("id", 1, "INT",
true, true, false);
+ return new TableMetaData(Collections.singletonList(columnMetaData),
Collections.emptyList());
+ }
+
+ @Override
+ public int getOrder() {
+ return 1;
+ }
+
+ @Override
+ public Class<DataNodeRoutedFixtureRule> getTypeClass() {
+ return DataNodeRoutedFixtureRule.class;
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/fixture/loader/DataNodeRoutedFixtureRuleMetaDataLoader.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/fixture/loader/DataNodeRoutedFixtureRuleMetaDataLoader.java
index 240ec1d..2230fa9 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/fixture/loader/DataNodeRoutedFixtureRuleMetaDataLoader.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/fixture/loader/DataNodeRoutedFixtureRuleMetaDataLoader.java
@@ -46,7 +46,8 @@ public final class DataNodeRoutedFixtureRuleMetaDataLoader
implements RuleMetaDa
@Override
public Optional<TableMetaData> load(final DatabaseType databaseType, final
Map<String, DataSource> dataSourceMap,
final DataNodes dataNodes, final
String tableName, final DataNodeRoutedFixtureRule rule, final
ConfigurationProperties props) {
- return Optional.empty();
+ return ("data_node_routed_table_0".equals(tableName) ||
"data_node_routed_table_1".equals(tableName))
+ ? Optional.of(new TableMetaData(Collections.emptyList(),
Collections.emptyList())) : Optional.empty();
}
@Override
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/RuleSchemaMetaDataLoaderTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/RuleSchemaMetaDataLoaderTest.java
index 9519e91..a1fa5df 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/RuleSchemaMetaDataLoaderTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/RuleSchemaMetaDataLoaderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.metadata.schema;
+import com.google.common.util.concurrent.MoreExecutors;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -33,8 +34,10 @@ import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
+import java.util.concurrent.Executors;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -53,6 +56,8 @@ public final class RuleSchemaMetaDataLoaderTest {
@Mock
private ConfigurationProperties props;
+ private final RuleSchemaMetaDataLoader loader = new
RuleSchemaMetaDataLoader(Arrays.asList(new CommonFixtureRule(), new
DataNodeRoutedFixtureRule()));
+
@Before
public void setUp() throws SQLException {
ResultSet resultSet = mockResultSet();
@@ -69,22 +74,35 @@ public final class RuleSchemaMetaDataLoaderTest {
@Test
public void assertSyncLoadFullDatabase() throws SQLException {
- RuleSchemaMetaDataLoader loader = new
RuleSchemaMetaDataLoader(Arrays.asList(new CommonFixtureRule(), new
DataNodeRoutedFixtureRule()));
- RuleSchemaMetaData actual = loader.load(databaseType, dataSource,
props, null);
+ assertRuleSchemaMetaData(loader.load(databaseType, dataSource, props,
null));
+ }
+
+ @Test
+ public void assertAsyncLoadFullDatabase() throws SQLException {
+ assertRuleSchemaMetaData(loader.load(databaseType, dataSource, props,
MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1))));
+ }
+
+ private void assertRuleSchemaMetaData(final RuleSchemaMetaData actual) {
assertThat(actual.getConfiguredSchemaMetaData().getAllTableNames().size(),
is(4));
assertTrue(actual.getConfiguredSchemaMetaData().containsTable("common_table_0"));
assertTrue(actual.getConfiguredSchemaMetaData().containsTable("common_table_1"));
assertTrue(actual.getConfiguredSchemaMetaData().containsTable("data_node_routed_table_0"));
+
assertTrue(actual.getConfiguredSchemaMetaData().get("data_node_routed_table_0").getColumns().containsKey("id"));
assertTrue(actual.getConfiguredSchemaMetaData().containsTable("data_node_routed_table_1"));
+
assertTrue(actual.getConfiguredSchemaMetaData().get("data_node_routed_table_1").getColumns().containsKey("id"));
assertThat(actual.getUnconfiguredSchemaMetaDataMap().size(), is(1));
assertTrue(actual.getUnconfiguredSchemaMetaDataMap().containsKey("logic_db"));
assertTrue(actual.getUnconfiguredSchemaMetaDataMap().get("logic_db").containsTable("unconfigured_table_0"));
assertTrue(actual.getUnconfiguredSchemaMetaDataMap().get("logic_db").containsTable("unconfigured_table_1"));
}
-// @Test
-// @Ignore
-// public void assertLoadWithTableName() {
-//
-// }
+ @Test
+ public void assertLoadWithExistedTableName() throws SQLException {
+ assertTrue(loader.load(databaseType, dataSource,
"data_node_routed_table_0", props).isPresent());
+ }
+
+ @Test
+ public void assertLoadWithNotExistedTableName() throws SQLException {
+ assertFalse(loader.load(databaseType, dataSource, "invalid_table",
props).isPresent());
+ }
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.schema.spi.RuleMetaDataDecorator
b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.schema.spi.RuleMetaDataDecorator
new file mode 100644
index 0000000..4ebb0fd
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.schema.spi.RuleMetaDataDecorator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.metadata.fixture.decorator.DataNodeRoutedFixtureRuleMetaDataDecorator