This is an automated email from the ASF dual-hosted git repository.
menghaoranss 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 eb5d3518638 Consolidate identifier metadata refresh tests into Core
test classes (#39068)
eb5d3518638 is described below
commit eb5d3518638c4bb198b408504b2d002c4eaa66bb
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Jul 10 13:59:28 2026 +0800
Consolidate identifier metadata refresh tests into Core test classes
(#39068)
* Consolidate identifier metadata refresh tests into Core test classes
* Fix ShardingSphereSchemaTest
---
.../ShardingSphereMetaDataIdentifierTest.java | 122 ------------
.../infra/metadata/ShardingSphereMetaDataTest.java | 88 +++++++++
...hardingSphereDatabaseFactoryIdentifierTest.java | 38 ----
.../ShardingSphereDatabaseFactoryTest.java | 8 +
.../ShardingSphereDatabaseIdentifierTest.java | 208 ---------------------
.../database/ShardingSphereDatabaseTest.java | 166 ++++++++++++++++
.../schema/model/ShardingSphereSchemaTest.java | 203 +++++++++++++++++---
.../model/ShardingSphereTableIdentifierTest.java | 92 ---------
.../schema/model/ShardingSphereTableTest.java | 60 ++++++
...ushDownMetaDataRefreshEngineIdentifierTest.java | 70 -------
.../PushDownMetaDataRefreshEngineTest.java | 47 +++++
.../util/TableRefreshUtilsIdentifierTest.java | 110 -----------
.../refresher/util/TableRefreshUtilsTest.java | 40 +++-
13 files changed, 583 insertions(+), 669 deletions(-)
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataIdentifierTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataIdentifierTest.java
deleted file mode 100644
index 7af85ea33ee..00000000000
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataIdentifierTest.java
+++ /dev/null
@@ -1,122 +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;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabaseFactory;
-import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class ShardingSphereMetaDataIdentifierTest {
-
- private final DatabaseType postgreSQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
-
- private final DatabaseType oracleDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "Oracle");
-
- @Test
- void assertContainsDatabaseByString() {
- assertTrue(createMetaData(postgreSQLDatabaseType,
createDatabase("foo_db", postgreSQLDatabaseType)).containsDatabase("FOO_DB"));
- }
-
- @Test
- void assertContainsDatabaseWithOracleRule() {
- assertTrue(createMetaData(oracleDatabaseType, createDatabase("FOO_DB",
oracleDatabaseType)).containsDatabase("foo_db"));
- }
-
- @Test
- void assertGetDatabaseByString() {
- ShardingSphereDatabase database = createDatabase("foo_db",
postgreSQLDatabaseType);
- assertThat(createMetaData(postgreSQLDatabaseType,
database).getDatabase("FOO_DB"), is(database));
- }
-
- @Test
- void assertGetDatabaseWithOracleRule() {
- ShardingSphereDatabase database = createDatabase("FOO_DB",
oracleDatabaseType);
- assertThat(createMetaData(oracleDatabaseType,
database).getDatabase("foo_db"), is(database));
- }
-
- @Test
- void assertContainsLowerCaseLogicalDatabaseWithOracleProtocol() {
- assertTrue(createMetaData(oracleDatabaseType, createDatabase("foo_db",
oracleDatabaseType)).containsDatabase("FOO_DB"));
- }
-
- @Test
- void assertGetLowerCaseLogicalDatabaseWithOracleProtocol() {
- ShardingSphereDatabase database = createDatabase("foo_db",
oracleDatabaseType);
- assertThat(createMetaData(oracleDatabaseType,
database).getDatabase("FOO_DB"), is(database));
- }
-
- @Test
- void assertAddDatabase() {
- ShardingSphereMetaData metaData =
createMetaData(postgreSQLDatabaseType);
- metaData.addDatabase("foo_db", postgreSQLDatabaseType, new
ConfigurationProperties(new Properties()));
- assertTrue(metaData.containsDatabase("FOO_DB"));
- }
-
- @Test
- void assertPutDatabase() {
- ShardingSphereMetaData metaData =
createMetaData(postgreSQLDatabaseType);
- ShardingSphereDatabase database = createDatabase("foo_db",
postgreSQLDatabaseType);
- metaData.putDatabase(database);
- assertThat(metaData.getDatabase("FOO_DB"), is(database));
- }
-
- @Test
- void assertDropDatabase() {
- ShardingSphereMetaData metaData =
createMetaData(postgreSQLDatabaseType, createDatabase("foo_db",
postgreSQLDatabaseType));
- metaData.dropDatabase("FOO_DB");
- assertFalse(metaData.containsDatabase("foo_db"));
- }
-
- @Test
- void assertLegacyConstructorUsesInsensitiveLookup() {
- ShardingSphereMetaData metaData = new
ShardingSphereMetaData(Collections.singleton(createDatabase("foo_db",
postgreSQLDatabaseType)),
- new ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new
Properties()));
- assertTrue(metaData.containsDatabase("FOO_DB"));
- }
-
- private ShardingSphereMetaData createMetaData(final DatabaseType
databaseType, final ShardingSphereDatabase database) {
- return createMetaData(databaseType, new ConfigurationProperties(new
Properties()), database);
- }
-
- private ShardingSphereMetaData createMetaData(final DatabaseType
databaseType, final ConfigurationProperties props, final ShardingSphereDatabase
database) {
- return new ShardingSphereMetaData(Collections.singleton(database),
- new ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), props, databaseType);
- }
-
- private ShardingSphereMetaData createMetaData(final DatabaseType
databaseType) {
- return new ShardingSphereMetaData(Collections.emptyList(),
- new ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new
Properties()), databaseType);
- }
-
- private ShardingSphereDatabase createDatabase(final String databaseName,
final DatabaseType databaseType) {
- return ShardingSphereDatabaseFactory.create(databaseName,
databaseType, new ConfigurationProperties(new Properties()));
- }
-}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
index 22e6b9a3cfb..92bc9d17bdf 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
@@ -32,6 +32,7 @@ import
org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
import
org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.rule.scope.GlobalRule;
import
org.apache.shardingsphere.infra.rule.scope.GlobalRule.GlobalRuleChangedType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.infra.fixture.jdbc.MockedDataSource;
import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
@@ -62,6 +63,10 @@ import static org.mockito.Mockito.withSettings;
@MockitoSettings(strictness = Strictness.LENIENT)
class ShardingSphereMetaDataTest {
+ private final DatabaseType postgreSQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+
+ private final DatabaseType oracleDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "Oracle");
+
@SuppressWarnings("resource")
@Test
void assertAddDatabase() {
@@ -75,6 +80,16 @@ class ShardingSphereMetaDataTest {
assertThat(metaData.getDatabase("foo_db"), is(database));
}
+ @Test
+ void assertAddDatabaseWithInsensitiveLookup() {
+ ConfigurationProperties configProps = new ConfigurationProperties(new
Properties());
+ ShardingSphereDatabase database = mockDatabase("foo_db",
postgreSQLDatabaseType);
+ when(ShardingSphereDatabaseFactory.create("foo_db",
postgreSQLDatabaseType, configProps)).thenReturn(database);
+ ShardingSphereMetaData metaData =
createMetaData(postgreSQLDatabaseType);
+ metaData.addDatabase("foo_db", postgreSQLDatabaseType, configProps);
+ assertTrue(metaData.containsDatabase("FOO_DB"));
+ }
+
@Test
void assertDropDatabase() {
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class,
RETURNS_DEEP_STUBS);
@@ -95,6 +110,13 @@ class ShardingSphereMetaDataTest {
verify(staticDataSourceRuleAttribute).cleanStorageNodeDataSources();
}
+ @Test
+ void assertDropDatabaseWithInsensitiveLookup() {
+ ShardingSphereMetaData metaData =
createMetaData(postgreSQLDatabaseType, mockDatabase("foo_db",
postgreSQLDatabaseType));
+ metaData.dropDatabase("FOO_DB");
+ assertFalse(metaData.containsDatabase("foo_db"));
+ }
+
@SuppressWarnings("resource")
@Test
void assertContainsDatabase() {
@@ -105,6 +127,21 @@ class ShardingSphereMetaDataTest {
assertTrue(metaData.containsDatabase("foo_db"));
}
+ @Test
+ void assertContainsDatabaseWithInsensitiveLookup() {
+ assertTrue(createMetaData(postgreSQLDatabaseType,
mockDatabase("foo_db", postgreSQLDatabaseType)).containsDatabase("FOO_DB"));
+ }
+
+ @Test
+ void assertContainsDatabaseWithOracleRule() {
+ assertTrue(createMetaData(oracleDatabaseType, mockDatabase("FOO_DB",
oracleDatabaseType)).containsDatabase("foo_db"));
+ }
+
+ @Test
+ void assertContainsLowerCaseLogicalDatabaseWithOracleProtocol() {
+ assertTrue(createMetaData(oracleDatabaseType, mockDatabase("foo_db",
oracleDatabaseType)).containsDatabase("FOO_DB"));
+ }
+
@SuppressWarnings("resource")
@Test
void assertGetAllDatabases() {
@@ -134,6 +171,24 @@ class ShardingSphereMetaDataTest {
assertThat(metaData.getDatabase("foo_db"), is(database));
}
+ @Test
+ void assertGetDatabaseWithInsensitiveLookup() {
+ ShardingSphereDatabase database = mockDatabase("foo_db",
postgreSQLDatabaseType);
+ assertThat(createMetaData(postgreSQLDatabaseType,
database).getDatabase("FOO_DB"), is(database));
+ }
+
+ @Test
+ void assertGetDatabaseWithOracleRule() {
+ ShardingSphereDatabase database = mockDatabase("FOO_DB",
oracleDatabaseType);
+ assertThat(createMetaData(oracleDatabaseType,
database).getDatabase("foo_db"), is(database));
+ }
+
+ @Test
+ void assertGetLowerCaseLogicalDatabaseWithOracleProtocol() {
+ ShardingSphereDatabase database = mockDatabase("foo_db",
oracleDatabaseType);
+ assertThat(createMetaData(oracleDatabaseType,
database).getDatabase("FOO_DB"), is(database));
+ }
+
@SuppressWarnings("resource")
@Test
void assertPutDatabase() {
@@ -144,6 +199,21 @@ class ShardingSphereMetaDataTest {
assertThat(metaData.getDatabase("foo_db"), is(database));
}
+ @Test
+ void assertPutDatabaseWithInsensitiveLookup() {
+ ShardingSphereMetaData metaData =
createMetaData(postgreSQLDatabaseType);
+ ShardingSphereDatabase database = mockDatabase("foo_db",
postgreSQLDatabaseType);
+ metaData.putDatabase(database);
+ assertThat(metaData.getDatabase("FOO_DB"), is(database));
+ }
+
+ @Test
+ void assertLegacyConstructorUsesInsensitiveLookup() {
+ ShardingSphereMetaData metaData = new
ShardingSphereMetaData(Collections.singleton(mockDatabase("foo_db",
postgreSQLDatabaseType)),
+ new ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new
Properties()));
+ assertTrue(metaData.containsDatabase("FOO_DB"));
+ }
+
@Test
void assertCloseClosesAllRules() throws Exception {
GlobalRule closableGlobalRule = mock(GlobalRule.class,
withSettings().extraInterfaces(AutoCloseable.class));
@@ -154,6 +224,24 @@ class ShardingSphereMetaDataTest {
verify((AutoCloseable) closableGlobalRule).close();
}
+ private ShardingSphereMetaData createMetaData(final DatabaseType
databaseType, final ShardingSphereDatabase database) {
+ return new ShardingSphereMetaData(Collections.singleton(database),
+ new ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new
Properties()), databaseType);
+ }
+
+ private ShardingSphereMetaData createMetaData(final DatabaseType
databaseType) {
+ return new ShardingSphereMetaData(Collections.emptyList(),
+ new ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new
Properties()), databaseType);
+ }
+
+ private ShardingSphereDatabase mockDatabase(final String databaseName,
final DatabaseType databaseType) {
+ ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
+ when(result.getName()).thenReturn(databaseName);
+ when(result.getProtocolType()).thenReturn(databaseType);
+ when(result.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.emptyList()));
+ return result;
+ }
+
private ShardingSphereDatabase mockDatabase(final ResourceMetaData
resourceMetaData, final DataSource dataSource, final ShardingSphereRule...
rules) {
ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
when(result.getName()).thenReturn("foo_db");
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseFactoryIdentifierTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseFactoryIdentifierTest.java
deleted file mode 100644
index 5792533d1b3..00000000000
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseFactoryIdentifierTest.java
+++ /dev/null
@@ -1,38 +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;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.junit.jupiter.api.Test;
-
-import java.util.Properties;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class ShardingSphereDatabaseFactoryIdentifierTest {
-
- private final DatabaseType postgreSQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
-
- @Test
- void assertCreateSystemDatabaseUsesProtocolAwareLookup() {
- ShardingSphereDatabase database =
ShardingSphereDatabaseFactory.create("foo_db", postgreSQLDatabaseType, new
ConfigurationProperties(new Properties()));
- assertTrue(database.containsSchema("PUBLIC"));
- }
-}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseFactoryTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseFactoryTest.java
index 8ad9d5bec51..7cf1cd5a401 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseFactoryTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseFactoryTest.java
@@ -61,6 +61,8 @@ class ShardingSphereDatabaseFactoryTest {
private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+ private final DatabaseType postgreSQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+
private final ConfigurationProperties props = new
ConfigurationProperties(new Properties());
private final DatabaseConfiguration databaseConfig = new
DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(),
Collections.singleton(new FixtureRuleConfiguration()));
@@ -137,6 +139,12 @@ class ShardingSphereDatabaseFactoryTest {
assertTrue(actual.containsSchema("foo_schema"));
}
+ @Test
+ void assertCreateSystemDatabaseUsesProtocolAwareLookup() {
+ ShardingSphereDatabase database =
ShardingSphereDatabaseFactory.create("foo_db", postgreSQLDatabaseType, new
ConfigurationProperties(new Properties()));
+ assertTrue(database.containsSchema("PUBLIC"));
+ }
+
private static Stream<Arguments> createWithSystemDatabaseArguments() {
return Stream.of(
Arguments.of("fixture database adds default schema",
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), "system_db",
"system_db", 1),
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseIdentifierTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseIdentifierTest.java
deleted file mode 100644
index f7ab0e0062e..00000000000
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseIdentifierTest.java
+++ /dev/null
@@ -1,208 +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;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.config.props.MetadataIdentifierCaseSensitivity;
-import
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
-import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
-import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
-import
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
-import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.junit.jupiter.api.Test;
-
-import javax.sql.DataSource;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Logger;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class ShardingSphereDatabaseIdentifierTest {
-
- private final DatabaseType postgreSQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
-
- private final DatabaseType oracleDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "Oracle");
-
- private final DatabaseType mySQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
-
- @Test
- void assertContainsSchemaByString() {
- assertTrue(createDatabase(postgreSQLDatabaseType,
"foo_schema").containsSchema("FOO_SCHEMA"));
- }
-
- @Test
- void assertGetSchemaByString() {
- ShardingSphereSchema schema = createSchema("foo_schema",
postgreSQLDatabaseType);
- assertThat(createDatabase(postgreSQLDatabaseType,
schema).getSchema("FOO_SCHEMA"), is(schema));
- }
-
- @Test
- void assertAddSchema() {
- ShardingSphereSchema schema = createSchema("foo_schema",
postgreSQLDatabaseType);
- ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType);
- database.addSchema(schema);
- assertThat(database.getSchema("FOO_SCHEMA"), is(schema));
- }
-
- @Test
- void assertDropSchema() {
- ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType, "foo_schema");
- database.dropSchema("FOO_SCHEMA");
- assertFalse(database.containsSchema("foo_schema"));
- }
-
- @Test
- void assertContainsSchemaWithOracleRule() {
- assertTrue(createDatabase(oracleDatabaseType,
"FOO_SCHEMA").containsSchema("foo_schema"));
- }
-
- @Test
- void assertContainsProtocolDefaultSchemaWithOracleStorageRule() {
- ShardingSphereSchema schema = new ShardingSphereSchema("test_db",
mySQLDatabaseType,
- Collections.singleton(new ShardingSphereTable("T_ORDER",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
Collections.emptyList());
- ShardingSphereDatabase database = new
ShardingSphereDatabase("test_db", mySQLDatabaseType,
createOracleResourceMetaData(),
- new RuleMetaData(Collections.emptyList()),
Collections.singleton(schema), new ConfigurationProperties(new Properties()));
- assertTrue(database.containsSchema("TEST_DB"));
- assertTrue(database.getSchema("test_db").containsTable("t_order"));
- }
-
- @Test
- void assertAttachIdentifierContextToSchema() {
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType,
- Collections.singleton(new ShardingSphereTable("Foo_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
Collections.emptyList());
- ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType, schema);
- assertFalse(database.getSchema("foo_schema").containsTable("FOO_TBL"));
- }
-
- @Test
- void assertDefaultPropsUseInsensitiveLookup() {
- ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db",
postgreSQLDatabaseType, createResourceMetaData(),
- new RuleMetaData(Collections.emptyList()),
Collections.singleton(createSchema("foo_schema", postgreSQLDatabaseType)), new
ConfigurationProperties(new Properties()));
- assertTrue(database.containsSchema("FOO_SCHEMA"));
- }
-
- @Test
- void assertRefreshIdentifierContext() {
- ShardingSphereColumn column = new ShardingSphereColumn("foo_col",
java.sql.Types.INTEGER, false, true, false, true, false, false);
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
- ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType, schema);
- Properties props = new Properties();
-
props.setProperty(TemporaryConfigurationPropertyKey.METADATA_IDENTIFIER_CASE_SENSITIVITY.getKey(),
MetadataIdentifierCaseSensitivity.INSENSITIVE.name());
- database.refreshIdentifierContext(new ConfigurationProperties(props));
- assertTrue(database.containsSchema("FOO_SCHEMA"));
- assertTrue(database.getSchema("foo_schema").containsTable("FOO_TBL"));
-
assertTrue(database.getSchema("foo_schema").getTable("foo_tbl").containsColumn("FOO_COL"));
- }
-
- private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType, final String schemaName) {
- return createDatabase(databaseType, createSchema(schemaName,
databaseType));
- }
-
- private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType, final ShardingSphereSchema schema) {
- return createDatabase(databaseType, new ConfigurationProperties(new
Properties()), schema);
- }
-
- private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType, final ConfigurationProperties props, final ShardingSphereSchema
schema) {
- return new ShardingSphereDatabase("foo_db", databaseType,
createResourceMetaData(), new RuleMetaData(Collections.emptyList()),
Collections.singleton(schema), props);
- }
-
- private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType) {
- return new ShardingSphereDatabase("foo_db", databaseType,
createResourceMetaData(),
- new RuleMetaData(Collections.emptyList()),
Collections.emptyList(), new ConfigurationProperties(new Properties()));
- }
-
- private ShardingSphereSchema createSchema(final String schemaName, final
DatabaseType databaseType) {
- return new ShardingSphereSchema(schemaName, databaseType);
- }
-
- private ResourceMetaData createResourceMetaData() {
- return new ResourceMetaData(Collections.emptyMap(),
Collections.emptyMap());
- }
-
- private ResourceMetaData createOracleResourceMetaData() {
- Map<String, Object> props = new LinkedHashMap<>(2, 1F);
- props.put("url", "jdbc:oracle:thin:@localhost:1521:xe");
- props.put("username", "root");
- Map<String, StorageUnit> storageUnits = new LinkedHashMap<>(1, 1F);
- storageUnits.put("ds_0", new StorageUnit(new StorageNode("ds_0"), new
DataSourcePoolProperties("com.zaxxer.hikari.HikariDataSource", props), new
FixtureDataSource()));
- return new ResourceMetaData(Collections.emptyMap(), storageUnits);
- }
-
- private static final class FixtureDataSource implements DataSource {
-
- @Override
- public Connection getConnection() throws SQLException {
- throw new SQLFeatureNotSupportedException("Not supported in
fixture.");
- }
-
- @Override
- public Connection getConnection(final String username, final String
password) throws SQLException {
- throw new SQLFeatureNotSupportedException("Not supported in
fixture.");
- }
-
- @Override
- public PrintWriter getLogWriter() {
- return null;
- }
-
- @Override
- public void setLogWriter(final PrintWriter out) {
- }
-
- @Override
- public void setLoginTimeout(final int seconds) {
- }
-
- @Override
- public int getLoginTimeout() {
- return 0;
- }
-
- @Override
- public Logger getParentLogger() {
- return Logger.getGlobal();
- }
-
- @Override
- public <T> T unwrap(final Class<T> iface) throws SQLException {
- throw new SQLFeatureNotSupportedException("Not supported in
fixture.");
- }
-
- @Override
- public boolean isWrapperFor(final Class<?> iface) {
- return false;
- }
- }
-}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java
index 86b5d8f100c..96331e811ab 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java
@@ -28,10 +28,15 @@ import
org.apache.shardingsphere.infra.config.props.MetadataIdentifierCaseSensit
import
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.decorator.RuleConfigurationDecorator;
+import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
+import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
import
org.apache.shardingsphere.infra.metadata.identifier.DatabaseIdentifierContext;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
@@ -50,6 +55,10 @@ import org.mockito.MockedStatic;
import org.mockito.internal.configuration.plugins.Plugins;
import javax.sql.DataSource;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -59,6 +68,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
+import java.util.logging.Logger;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -81,6 +91,12 @@ class ShardingSphereDatabaseTest {
private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+ private final DatabaseType postgreSQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+
+ private final DatabaseType oracleDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "Oracle");
+
+ private final DatabaseType mySQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
+
@Test
void assertGetAllSchemas() {
ShardingSphereDatabase database = new ShardingSphereDatabase(
@@ -330,4 +346,154 @@ class ShardingSphereDatabaseTest {
}
return new ResourceMetaData(dataSources);
}
+
+ private ResourceMetaData createResourceMetaData() {
+ return new ResourceMetaData(Collections.emptyMap(),
Collections.emptyMap());
+ }
+
+ @Test
+ void assertContainsSchemaByString() {
+ assertTrue(createDatabase(postgreSQLDatabaseType,
"foo_schema").containsSchema("FOO_SCHEMA"));
+ }
+
+ @Test
+ void assertGetSchemaByString() {
+ ShardingSphereSchema schema = createSchema("foo_schema",
postgreSQLDatabaseType);
+ assertThat(createDatabase(postgreSQLDatabaseType,
schema).getSchema("FOO_SCHEMA"), is(schema));
+ }
+
+ @Test
+ void assertAddUpperCaseSchema() {
+ ShardingSphereSchema schema = createSchema("foo_schema",
postgreSQLDatabaseType);
+ ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType);
+ database.addSchema(schema);
+ assertThat(database.getSchema("FOO_SCHEMA"), is(schema));
+ }
+
+ @Test
+ void assertDropUpperCaseSchema() {
+ ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType, "foo_schema");
+ database.dropSchema("FOO_SCHEMA");
+ assertFalse(database.containsSchema("foo_schema"));
+ }
+
+ @Test
+ void assertContainsSchemaWithOracleRule() {
+ assertTrue(createDatabase(oracleDatabaseType,
"FOO_SCHEMA").containsSchema("foo_schema"));
+ }
+
+ @Test
+ void assertContainsProtocolDefaultSchemaWithOracleStorageRule() {
+ ShardingSphereSchema schema = new ShardingSphereSchema("test_db",
mySQLDatabaseType,
+ Collections.singleton(new ShardingSphereTable("T_ORDER",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
Collections.emptyList());
+ ShardingSphereDatabase database = new
ShardingSphereDatabase("test_db", mySQLDatabaseType,
createOracleResourceMetaData(),
+ new RuleMetaData(Collections.emptyList()),
Collections.singleton(schema), new ConfigurationProperties(new Properties()));
+ assertTrue(database.containsSchema("TEST_DB"));
+ assertTrue(database.getSchema("test_db").containsTable("t_order"));
+ }
+
+ @Test
+ void assertAttachIdentifierContextToSchema() {
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType,
+ Collections.singleton(new ShardingSphereTable("Foo_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
Collections.emptyList());
+ ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType, schema);
+ assertFalse(database.getSchema("foo_schema").containsTable("FOO_TBL"));
+ }
+
+ @Test
+ void assertDefaultPropsUseInsensitiveLookup() {
+ ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db",
postgreSQLDatabaseType, createResourceMetaData(),
+ new RuleMetaData(Collections.emptyList()),
Collections.singleton(createSchema("foo_schema", postgreSQLDatabaseType)), new
ConfigurationProperties(new Properties()));
+ assertTrue(database.containsSchema("FOO_SCHEMA"));
+ }
+
+ @Test
+ void assertRefreshIdentifierContextWithUpperCaseSchema() {
+ ShardingSphereColumn column = new ShardingSphereColumn("foo_col",
java.sql.Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ ShardingSphereDatabase database =
createDatabase(postgreSQLDatabaseType, schema);
+ Properties props = new Properties();
+
props.setProperty(TemporaryConfigurationPropertyKey.METADATA_IDENTIFIER_CASE_SENSITIVITY.getKey(),
MetadataIdentifierCaseSensitivity.INSENSITIVE.name());
+ database.refreshIdentifierContext(new ConfigurationProperties(props));
+ assertTrue(database.containsSchema("FOO_SCHEMA"));
+ assertTrue(database.getSchema("foo_schema").containsTable("FOO_TBL"));
+
assertTrue(database.getSchema("foo_schema").getTable("foo_tbl").containsColumn("FOO_COL"));
+ }
+
+ private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType, final String schemaName) {
+ return createDatabase(databaseType, createSchema(schemaName,
databaseType));
+ }
+
+ private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType, final ShardingSphereSchema schema) {
+ return createDatabase(databaseType, new ConfigurationProperties(new
Properties()), schema);
+ }
+
+ private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType, final ConfigurationProperties props, final ShardingSphereSchema
schema) {
+ return new ShardingSphereDatabase("foo_db", databaseType,
createResourceMetaData(), new RuleMetaData(Collections.emptyList()),
Collections.singleton(schema), props);
+ }
+
+ private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType) {
+ return new ShardingSphereDatabase("foo_db", databaseType,
createResourceMetaData(),
+ new RuleMetaData(Collections.emptyList()),
Collections.emptyList(), new ConfigurationProperties(new Properties()));
+ }
+
+ private ShardingSphereSchema createSchema(final String schemaName, final
DatabaseType databaseType) {
+ return new ShardingSphereSchema(schemaName, databaseType);
+ }
+
+ private ResourceMetaData createOracleResourceMetaData() {
+ Map<String, Object> props = new LinkedHashMap<>(2, 1F);
+ props.put("url", "jdbc:oracle:thin:@localhost:1521:xe");
+ props.put("username", "root");
+ Map<String, StorageUnit> storageUnits = new LinkedHashMap<>(1, 1F);
+ storageUnits.put("ds_0", new StorageUnit(new StorageNode("ds_0"), new
DataSourcePoolProperties("com.zaxxer.hikari.HikariDataSource", props), new
FixtureDataSource()));
+ return new ResourceMetaData(Collections.emptyMap(), storageUnits);
+ }
+
+ private static final class FixtureDataSource implements DataSource {
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ throw new SQLFeatureNotSupportedException("Not supported in
fixture.");
+ }
+
+ @Override
+ public Connection getConnection(final String username, final String
password) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Not supported in
fixture.");
+ }
+
+ @Override
+ public PrintWriter getLogWriter() {
+ return null;
+ }
+
+ @Override
+ public void setLogWriter(final PrintWriter out) {
+ }
+
+ @Override
+ public void setLoginTimeout(final int seconds) {
+ }
+
+ @Override
+ public int getLoginTimeout() {
+ return 0;
+ }
+
+ @Override
+ public Logger getParentLogger() {
+ return Logger.getGlobal();
+ }
+
+ @Override
+ public <T> T unwrap(final Class<T> iface) throws SQLException {
+ throw new SQLFeatureNotSupportedException("Not supported in
fixture.");
+ }
+
+ @Override
+ public boolean isWrapperFor(final Class<?> iface) {
+ return false;
+ }
+ }
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaTest.java
index a3fc3bca4fe..bef49d08ce0 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchemaTest.java
@@ -17,11 +17,18 @@
package org.apache.shardingsphere.infra.metadata.database.schema.model;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicy;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyFactory;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicySet;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierScope;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import
org.apache.shardingsphere.infra.metadata.identifier.DatabaseIdentifierContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.junit.jupiter.api.Test;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.EnumMap;
import java.util.HashSet;
import java.util.Map;
@@ -33,30 +40,32 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class ShardingSphereSchemaTest {
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+ private final DatabaseType postgreSQLDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+
+ private final DatabaseType oracleDatabaseType =
TypedSPILoader.getService(DatabaseType.class, "Oracle");
@Test
void assertGetAllTables() {
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
- assertThat(new HashSet<>(new ShardingSphereSchema("foo_db",
databaseType, Collections.singleton(table), Collections.emptyList())
+ assertThat(new HashSet<>(new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList())
.getAllTables()), is(Collections.singleton(table)));
}
@Test
void assertContainsTable() {
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
- assertTrue(new ShardingSphereSchema("foo_db", databaseType,
Collections.singleton(table),
Collections.emptyList()).containsTable("foo_tbl"));
+ assertTrue(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.singleton(table),
Collections.emptyList()).containsTable("foo_tbl"));
}
@Test
void assertGetTable() {
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
- assertThat(new ShardingSphereSchema("foo_db", databaseType,
Collections.singleton(table), Collections.emptyList()).getTable("foo_tbl"),
is(table));
+ assertThat(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.singleton(table), Collections.emptyList()).getTable("foo_tbl"),
is(table));
}
@Test
void assertPutTable() {
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType);
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType);
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
schema.putTable(table);
assertThat(schema.getTable("foo_tbl"), is(table));
@@ -65,7 +74,7 @@ class ShardingSphereSchemaTest {
@Test
void assertRemoveTable() {
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType, Collections.singleton(table), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
schema.removeTable("foo_tbl");
assertNull(schema.getTable("foo_tbl"));
}
@@ -73,32 +82,32 @@ class ShardingSphereSchemaTest {
@Test
void assertGetAllViews() {
ShardingSphereView view = new ShardingSphereView("foo_view", "SELECT
1");
- assertThat(new HashSet<>(new ShardingSphereSchema("foo_db",
databaseType, Collections.emptyList(), Collections.singleton(view))
+ assertThat(new HashSet<>(new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.emptyList(), Collections.singleton(view))
.getAllViews()), is(Collections.singleton(view)));
}
@Test
void assertContainsView() {
ShardingSphereView view = new ShardingSphereView("foo_view", "SELECT
1");
- assertTrue(new ShardingSphereSchema("foo_db", databaseType,
Collections.emptyList(), Collections.singleton(view)).containsView("foo_view"));
+ assertTrue(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.emptyList(), Collections.singleton(view)).containsView("foo_view"));
}
@Test
void assertGetView() {
ShardingSphereView view = new ShardingSphereView("foo_view", "SELECT
1");
- assertThat(new ShardingSphereSchema("foo_db", databaseType,
Collections.emptyList(), Collections.singleton(view)).getView("foo_view"),
is(view));
+ assertThat(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.emptyList(), Collections.singleton(view)).getView("foo_view"),
is(view));
}
@Test
void assertPutView() {
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType, Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.emptyList(), Collections.emptyList());
schema.putView(new ShardingSphereView("foo_view", "SELECT * FROM
test_table"));
assertTrue(schema.containsView("foo_view"));
}
@Test
void assertRemoveView() {
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType, Collections.emptyList(),
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.emptyList(),
Collections.singleton(new ShardingSphereView("foo_view",
"SELECT * FROM test_table")));
schema.removeView("foo_view");
assertFalse(schema.containsView("foo_view"));
@@ -107,32 +116,32 @@ class ShardingSphereSchemaTest {
@Test
void assertGetAllSequences() {
ShardingSphereSequence sequence = new
ShardingSphereSequence("foo_seq");
- assertThat(new HashSet<>(new ShardingSphereSchema("foo_db",
databaseType, Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence))
+ assertThat(new HashSet<>(new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence))
.getAllSequences()), is(Collections.singleton(sequence)));
}
@Test
void assertContainsSequence() {
ShardingSphereSequence sequence = new
ShardingSphereSequence("foo_seq");
- assertTrue(new ShardingSphereSchema("foo_db", databaseType,
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence)).containsSequence("foo_seq"));
+ assertTrue(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence)).containsSequence("foo_seq"));
}
@Test
void assertGetSequence() {
ShardingSphereSequence sequence = new
ShardingSphereSequence("foo_seq");
- assertThat(new ShardingSphereSchema("foo_db", databaseType,
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence)).getSequence("foo_seq"), is(sequence));
+ assertThat(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence)).getSequence("foo_seq"), is(sequence));
}
@Test
void assertPutSequence() {
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType);
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType);
schema.putSequence(new ShardingSphereSequence("foo_seq"));
assertTrue(schema.containsSequence("foo_seq"));
}
@Test
void assertRemoveSequence() {
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType, Collections.emptyList(), Collections.emptyList(),
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.emptyList(), Collections.emptyList(),
Collections.singleton(new ShardingSphereSequence("foo_seq")));
schema.removeSequence("foo_seq");
assertFalse(schema.containsSequence("foo_seq"));
@@ -142,45 +151,46 @@ class ShardingSphereSchemaTest {
void assertContainsIndex() {
ShardingSphereTable table = new ShardingSphereTable(
"foo_tbl", Collections.emptyList(), Collections.singleton(new
ShardingSphereIndex("col_idx", Collections.emptyList(), false)),
Collections.emptyList());
- assertTrue(new ShardingSphereSchema("foo_db", databaseType,
Collections.singleton(table), Collections.emptyList()).containsIndex("foo_tbl",
"col_idx"));
+ assertTrue(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.singleton(table), Collections.emptyList()).containsIndex("foo_tbl",
"col_idx"));
}
@Test
void assertContainsIndexWithIndexNotExists() {
ShardingSphereTable table = new ShardingSphereTable(
"foo_tbl", Collections.emptyList(), Collections.singleton(new
ShardingSphereIndex("col_idx", Collections.emptyList(), false)),
Collections.emptyList());
- assertFalse(new ShardingSphereSchema("foo_db", databaseType,
Collections.singleton(table), Collections.emptyList()).containsIndex("foo_tbl",
"foo_idx"));
+ assertFalse(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.singleton(table), Collections.emptyList()).containsIndex("foo_tbl",
"foo_idx"));
}
@Test
void assertContainsIndexWithTableNotExists() {
- assertFalse(new ShardingSphereSchema("foo_db",
databaseType).containsIndex("nonexistent_tbl", "nonexistent_idx"));
+ assertFalse(new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType).containsIndex("nonexistent_tbl", "nonexistent_idx"));
}
@Test
void assertGetVisibleColumnNamesWhenTableNotExists() {
- assertTrue(new ShardingSphereSchema("foo_tbl", databaseType,
Collections.emptyList(),
Collections.emptyList()).getVisibleColumnNames("nonexistent_tbl").isEmpty());
+ assertTrue(new ShardingSphereSchema("foo_tbl", postgreSQLDatabaseType,
Collections.emptyList(),
Collections.emptyList()).getVisibleColumnNames("nonexistent_tbl").isEmpty());
}
@Test
void assertGetVisibleColumnNamesWhenContainsKey() {
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singletonList(
new ShardingSphereColumn("foo_col", 0, false, false, false,
true, false, false)), Collections.emptyList(), Collections.emptyList());
- assertThat(new ShardingSphereSchema("foo_db", databaseType,
Collections.singleton(table),
Collections.emptyList()).getVisibleColumnNames("foo_tbl"),
is(Collections.singletonList("foo_col")));
+ assertThat(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.singleton(table),
Collections.emptyList()).getVisibleColumnNames("foo_tbl"),
+ is(Collections.singletonList("foo_col")));
}
@Test
void assertGetVisibleColumnNamesWhenNotContainsKey() {
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singletonList(
new ShardingSphereColumn("foo_col", 0, false, false, false,
false, true, false)), Collections.emptyList(), Collections.emptyList());
- assertTrue(new ShardingSphereSchema("foo_db", databaseType,
Collections.singleton(table),
Collections.emptyList()).getVisibleColumnNames("foo_tbl").isEmpty());
+ assertTrue(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.singleton(table),
Collections.emptyList()).getVisibleColumnNames("foo_tbl").isEmpty());
}
@Test
void assertGetVisibleColumnAndIndexMapWhenContainsTable() {
ShardingSphereColumn column = new ShardingSphereColumn("foo_col", 0,
false, false, false, true, false, false);
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singletonList(column), Collections.emptyList(),
Collections.emptyList());
- ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
databaseType, Collections.singleton(table), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
Map<String, Integer> actual =
schema.getVisibleColumnAndIndexMap("foo_tbl");
assertThat(actual.size(), is(1));
assertTrue(actual.containsKey("foo_col"));
@@ -188,29 +198,166 @@ class ShardingSphereSchemaTest {
@Test
void assertGetVisibleColumnAndIndexMapWhenNotContainsTable() {
- assertTrue(new ShardingSphereSchema("foo_db",
databaseType).getVisibleColumnAndIndexMap("nonexistent_tbl").isEmpty());
+ assertTrue(new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType).getVisibleColumnAndIndexMap("nonexistent_tbl").isEmpty());
}
@Test
void assertIsEmptyWithEmptyTable() {
ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
- assertFalse(new ShardingSphereSchema("foo_db", databaseType,
Collections.singleton(table), Collections.emptyList()).isEmpty());
+ assertFalse(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.singleton(table), Collections.emptyList()).isEmpty());
}
@Test
void assertIsEmptyWithEmptyView() {
ShardingSphereView view = new ShardingSphereView("foo_view", "");
- assertFalse(new ShardingSphereSchema("foo_db", databaseType,
Collections.emptyList(), Collections.singleton(view)).isEmpty());
+ assertFalse(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.emptyList(), Collections.singleton(view)).isEmpty());
}
@Test
void assertIsEmptyWithEmptySequence() {
ShardingSphereSequence sequence = new
ShardingSphereSequence("foo_seq");
- assertFalse(new ShardingSphereSchema("foo_db", databaseType,
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence)).isEmpty());
+ assertFalse(new ShardingSphereSchema("foo_db", postgreSQLDatabaseType,
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(sequence)).isEmpty());
}
@Test
void assertIsEmpty() {
- assertTrue(new ShardingSphereSchema("foo_db", databaseType).isEmpty());
+ assertTrue(new ShardingSphereSchema("foo_db",
postgreSQLDatabaseType).isEmpty());
+ }
+
+ @Test
+ void assertContainsUpperCaseTable() {
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertTrue(schema.containsTable("FOO_TBL"));
+ }
+
+ @Test
+ void assertContainsTableWithOracleRule() {
+ ShardingSphereTable table = new ShardingSphereTable("FOO_TBL",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
oracleDatabaseType, Collections.singleton(table), Collections.emptyList());
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newUpperCasePolicySet()));
+ assertTrue(schema.containsTable("foo_tbl"));
+ }
+
+ @Test
+ void assertGetUpperCaseTable() {
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertThat(schema.getTable("FOO_TBL"), is(table));
+ }
+
+ @Test
+ void assertContainsUpperCaseView() {
+ ShardingSphereView view = new ShardingSphereView("foo_view", "SELECT
1");
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.emptyList(), Collections.singleton(view));
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertTrue(schema.containsView("FOO_VIEW"));
+ }
+
+ @Test
+ void assertContainsViewWithOracleRule() {
+ ShardingSphereView view = new ShardingSphereView("FOO_VIEW", "SELECT
1");
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
oracleDatabaseType, Collections.emptyList(), Collections.singleton(view));
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newUpperCasePolicySet()));
+ assertTrue(schema.containsView("foo_view"));
+ }
+
+ @Test
+ void assertGetUpperCaseView() {
+ ShardingSphereView view = new ShardingSphereView("foo_view", "SELECT
1");
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.emptyList(), Collections.singleton(view));
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertThat(schema.getView("FOO_VIEW"), is(view));
+ }
+
+ @Test
+ void assertAttachIdentifierContext() {
+ ShardingSphereTable table = new ShardingSphereTable("Foo_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ assertTrue(schema.containsTable("FOO_TBL"));
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertFalse(schema.containsTable("FOO_TBL"));
+ }
+
+ @Test
+ void assertAttachIdentifierContextToTable() {
+ ShardingSphereColumn column = new ShardingSphereColumn("Foo_Col",
java.sql.Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertFalse(schema.getTable("foo_tbl").containsColumn("FOO_COL"));
+ }
+
+ @Test
+ void
assertContainsTableByLogicalTableIndexWhenHeterogeneousLookupEnabled() {
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ Map<IdentifierScope, IdentifierCasePolicy> scopedRules = new
EnumMap<>(IdentifierScope.class);
+ scopedRules.put(IdentifierScope.LOGICAL_TABLE,
IdentifierCasePolicyFactory.newLowerCasePolicySet().getPolicy(IdentifierScope.TABLE));
+ DatabaseIdentifierContext context = new DatabaseIdentifierContext(new
IdentifierCasePolicySet(IdentifierCasePolicyFactory.newUpperCasePolicySet()
+ .getPolicy(IdentifierScope.TABLE), scopedRules), true);
+ schema.refreshIdentifierContext(context);
+ assertTrue(schema.containsTable("FOO_TBL"));
+ assertThat(schema.getTable("FOO_TBL"), is(table));
+ }
+
+ @Test
+ void assertGetTablePrioritizesPhysicalTableIndexWhenBothIndexesCanMatch() {
+ ShardingSphereTable lowerCaseTable = new
ShardingSphereTable("foo_tbl", Collections.emptyList(),
Collections.emptyList(), Collections.emptyList());
+ ShardingSphereTable upperCaseTable = new
ShardingSphereTable("FOO_TBL", Collections.emptyList(),
Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Arrays.asList(lowerCaseTable, upperCaseTable),
Collections.emptyList());
+ Map<IdentifierScope, IdentifierCasePolicy> scopedRules = new
EnumMap<>(IdentifierScope.class);
+ scopedRules.put(IdentifierScope.LOGICAL_TABLE,
IdentifierCasePolicyFactory.newLowerCasePolicySet().getPolicy(IdentifierScope.TABLE));
+ DatabaseIdentifierContext context = new DatabaseIdentifierContext(new
IdentifierCasePolicySet(IdentifierCasePolicyFactory.newUpperCasePolicySet()
+ .getPolicy(IdentifierScope.TABLE), scopedRules), true);
+ schema.refreshIdentifierContext(context);
+ assertThat(schema.getTable("FOO_TBL"), is(upperCaseTable));
+ }
+
+ @Test
+ void assertRemoveTableByLogicalTableIndexWhenHeterogeneousLookupEnabled() {
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ Map<IdentifierScope, IdentifierCasePolicy> scopedRules = new
EnumMap<>(IdentifierScope.class);
+ scopedRules.put(IdentifierScope.LOGICAL_TABLE,
IdentifierCasePolicyFactory.newLowerCasePolicySet().getPolicy(IdentifierScope.TABLE));
+ DatabaseIdentifierContext context = new DatabaseIdentifierContext(new
IdentifierCasePolicySet(IdentifierCasePolicyFactory.newUpperCasePolicySet()
+ .getPolicy(IdentifierScope.TABLE), scopedRules), true);
+ schema.refreshIdentifierContext(context);
+ schema.removeTable("FOO_TBL");
+ assertNull(schema.getTable("foo_tbl"));
+ }
+
+ @Test
+ void assertRemoveTableByActualName() {
+ ShardingSphereTable table = new ShardingSphereTable("Foo_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.singleton(table), Collections.emptyList());
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ schema.removeTable("Foo_Tbl");
+ assertTrue(schema.getAllTables().isEmpty());
+ }
+
+ @Test
+ void
assertRemoveTablePrioritizesPhysicalTableIndexWhenBothIndexesCanMatch() {
+ ShardingSphereTable lowerCaseTable = new
ShardingSphereTable("foo_tbl", Collections.emptyList(),
Collections.emptyList(), Collections.emptyList());
+ ShardingSphereTable upperCaseTable = new
ShardingSphereTable("FOO_TBL", Collections.emptyList(),
Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Arrays.asList(lowerCaseTable, upperCaseTable),
Collections.emptyList());
+ Map<IdentifierScope, IdentifierCasePolicy> scopedRules = new
EnumMap<>(IdentifierScope.class);
+ scopedRules.put(IdentifierScope.LOGICAL_TABLE,
IdentifierCasePolicyFactory.newLowerCasePolicySet().getPolicy(IdentifierScope.TABLE));
+ DatabaseIdentifierContext context = new DatabaseIdentifierContext(new
IdentifierCasePolicySet(IdentifierCasePolicyFactory.newUpperCasePolicySet()
+ .getPolicy(IdentifierScope.TABLE), scopedRules), true);
+ schema.refreshIdentifierContext(context);
+ schema.removeTable("FOO_TBL");
+ assertThat(schema.getTable("FOO_TBL"), is(lowerCaseTable));
+ }
+
+ @Test
+ void assertRemoveViewByActualName() {
+ ShardingSphereView view = new ShardingSphereView("Foo_View", "SELECT
1");
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
postgreSQLDatabaseType, Collections.emptyList(), Collections.singleton(view));
+ schema.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ schema.removeView("Foo_View");
+ assertTrue(schema.getAllViews().isEmpty());
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableIdentifierTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableIdentifierTest.java
deleted file mode 100644
index be18f8ad786..00000000000
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableIdentifierTest.java
+++ /dev/null
@@ -1,92 +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.model;
-
-import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyFactory;
-import
org.apache.shardingsphere.infra.metadata.identifier.DatabaseIdentifierContext;
-import org.junit.jupiter.api.Test;
-
-import java.sql.Types;
-import java.util.Arrays;
-import java.util.Collections;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class ShardingSphereTableIdentifierTest {
-
- @Test
- void assertContainsColumn() {
- ShardingSphereColumn column = new ShardingSphereColumn("foo_col",
Types.INTEGER, false, true, false, true, false, false);
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
- table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
- assertTrue(table.containsColumn("FOO_COL"));
- }
-
- @Test
- void assertContainsColumnWithOracleRule() {
- ShardingSphereColumn column = new ShardingSphereColumn("FOO_COL",
Types.INTEGER, false, true, false, true, false, false);
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
- table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newUpperCasePolicySet()));
- assertTrue(table.containsColumn("foo_col"));
- }
-
- @Test
- void assertGetColumn() {
- ShardingSphereColumn column = new ShardingSphereColumn("foo_col",
Types.INTEGER, false, true, false, true, false, false);
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
- table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
- assertThat(table.getColumn("FOO_COL"), is(column));
- }
-
- @Test
- void assertFindColumnNamesIfNotExistedFrom() {
- ShardingSphereColumn column1 = new ShardingSphereColumn("foo_col",
Types.INTEGER, false, true, false, true, false, false);
- ShardingSphereColumn column2 = new ShardingSphereColumn("bar_col",
Types.INTEGER, false, true, false, true, false, false);
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Arrays.asList(column1, column2), Collections.emptyList(),
Collections.emptyList());
- table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
-
assertThat(table.findColumnNamesIfNotExistedFrom(Collections.singleton("FOO_COL")),
is(Collections.singleton("bar_col")));
- }
-
- @Test
- void assertGetIndex() {
- ShardingSphereIndex index = new ShardingSphereIndex("foo_idx",
Collections.emptyList(), false);
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.singleton(index), Collections.emptyList());
- table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
- assertThat(table.getIndex("FOO_IDX"), is(index));
- }
-
- @Test
- void assertContainsConstraint() {
- ShardingSphereConstraint constraint = new
ShardingSphereConstraint("FOO_FK", "ref_tbl");
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(constraint));
- table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newUpperCasePolicySet()));
- assertTrue(table.containsConstraint("foo_fk"));
- }
-
- @Test
- void assertRefreshIdentifierContext() {
- ShardingSphereColumn column = new ShardingSphereColumn("Foo_Col",
Types.INTEGER, false, true, false, true, false, false);
- ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
- assertTrue(table.containsColumn("FOO_COL"));
- table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
- assertFalse(table.containsColumn("FOO_COL"));
- }
-}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
index e776274f19d..75b4252ddfd 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereTableTest.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.infra.metadata.database.schema.model;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyFactory;
+import
org.apache.shardingsphere.infra.metadata.identifier.DatabaseIdentifierContext;
import org.junit.jupiter.api.Test;
import java.sql.Types;
@@ -135,4 +137,62 @@ class ShardingSphereTableTest {
assertThat(table.getAllConstraints().size(), is(1));
assertThat(table.getAllConstraints(), hasItems(constraint));
}
+
+ @Test
+ void assertContainsUpperCaseColumn() {
+ ShardingSphereColumn column = new ShardingSphereColumn("foo_col",
Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
+ table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertTrue(table.containsColumn("FOO_COL"));
+ }
+
+ @Test
+ void assertContainsColumnWithOracleRule() {
+ ShardingSphereColumn column = new ShardingSphereColumn("FOO_COL",
Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
+ table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newUpperCasePolicySet()));
+ assertTrue(table.containsColumn("foo_col"));
+ }
+
+ @Test
+ void assertGetUpperCaseColumn() {
+ ShardingSphereColumn column = new ShardingSphereColumn("foo_col",
Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
+ table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertThat(table.getColumn("FOO_COL"), is(column));
+ }
+
+ @Test
+ void assertFindColumnNamesIfNotExistedFrom() {
+ ShardingSphereColumn column1 = new ShardingSphereColumn("foo_col",
Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereColumn column2 = new ShardingSphereColumn("bar_col",
Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Arrays.asList(column1, column2), Collections.emptyList(),
Collections.emptyList());
+ table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+
assertThat(table.findColumnNamesIfNotExistedFrom(Collections.singleton("FOO_COL")),
is(Collections.singleton("bar_col")));
+ }
+
+ @Test
+ void assertGetIndex() {
+ ShardingSphereIndex index = new ShardingSphereIndex("foo_idx",
Collections.emptyList(), false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.singleton(index), Collections.emptyList());
+ table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertThat(table.getIndex("FOO_IDX"), is(index));
+ }
+
+ @Test
+ void assertContainsConstraint() {
+ ShardingSphereConstraint constraint = new
ShardingSphereConstraint("FOO_FK", "ref_tbl");
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(),
Collections.singleton(constraint));
+ table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newUpperCasePolicySet()));
+ assertTrue(table.containsConstraint("foo_fk"));
+ }
+
+ @Test
+ void assertRefreshIdentifierContext() {
+ ShardingSphereColumn column = new ShardingSphereColumn("Foo_Col",
Types.INTEGER, false, true, false, true, false, false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.singleton(column), Collections.emptyList(),
Collections.emptyList());
+ assertTrue(table.containsColumn("FOO_COL"));
+ table.refreshIdentifierContext(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newLowerCasePolicySet()));
+ assertFalse(table.containsColumn("FOO_COL"));
+ }
}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngineIdentifierTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngineIdentifierTest.java
deleted file mode 100644
index 3a500f71cf6..00000000000
---
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngineIdentifierTest.java
+++ /dev/null
@@ -1,70 +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.mode.metadata.refresher.pushdown;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.DropTableStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.is;
-
-class PushDownMetaDataRefreshEngineIdentifierTest {
-
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
-
- @Test
- void assertRefreshUsesActualSchemaAndTableNames() throws SQLException {
- PushDownMetaDataManagerPersistServiceFixture persistService = new
PushDownMetaDataManagerPersistServiceFixture();
- PushDownMetaDataRefreshEngine engine = new
PushDownMetaDataRefreshEngine(new
CommonSQLStatementContext(createDropTableStatement()));
- engine.refresh(persistService, createDatabase(), new
ConfigurationProperties(new Properties()), Collections.emptyList());
- assertThat(persistService.getDroppedTableSchemaName(),
is("Foo_Schema"));
- assertThat(persistService.getDroppedTableNames(), contains("Foo_Tbl"));
- }
-
- private DropTableStatement createDropTableStatement() {
- TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new
IdentifierValue("foo_tbl"));
- tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- return new DropTableStatement(databaseType,
Collections.singletonList(new SimpleTableSegment(tableNameSegment)), false,
false);
- }
-
- private ShardingSphereDatabase createDatabase() {
- ShardingSphereSchema schema = new ShardingSphereSchema("Foo_Schema",
databaseType,
- Collections.singletonList(new ShardingSphereTable("Foo_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
- Collections.emptyList());
- return new ShardingSphereDatabase("foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()),
- new RuleMetaData(Collections.emptyList()),
Collections.singletonList(schema), new ConfigurationProperties(new
Properties()));
- }
-}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngineTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngineTest.java
index ee6f164adc4..f0508af0193 100644
---
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngineTest.java
+++
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngineTest.java
@@ -19,17 +19,28 @@ package
org.apache.shardingsphere.mode.metadata.refresher.pushdown;
import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyFactory;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import
org.apache.shardingsphere.infra.metadata.identifier.DatabaseIdentifierContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.mode.metadata.refresher.util.SchemaRefreshUtils;
+import
org.apache.shardingsphere.mode.metadata.refresher.pushdown.type.table.DropTablePushDownMetaDataRefresher;
import
org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.DropTableStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.UpdateStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
import org.junit.jupiter.api.Test;
@@ -41,7 +52,12 @@ import java.util.Collections;
import java.util.Optional;
import java.util.Properties;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -112,4 +128,35 @@ class PushDownMetaDataRefreshEngineTest {
new
PushDownMetaDataRefreshEngine(sqlStatementContext).refresh(metaDataManagerPersistService,
database, props, Collections.emptyList());
verify(refresher).refresh(metaDataManagerPersistService, database,
null, "foo_schema", databaseType, sqlStatement, props);
}
+
+ @Test
+ void assertRefreshUsesActualSchemaAndTableNames() throws SQLException {
+ DropTableStatement sqlStatement = createDropTableStatement();
+ SQLStatementContext sqlStatementContext = new
CommonSQLStatementContext(sqlStatement);
+ ShardingSphereDatabase database = createDatabase();
+ when(TypedSPILoader.findService(PushDownMetaDataRefresher.class,
DropTableStatement.class)).thenReturn(Optional.of(new
DropTablePushDownMetaDataRefresher()));
+ when(SchemaRefreshUtils.getActualSchemaName(same(database),
same(sqlStatementContext))).thenReturn("foo_schema");
+ when(SchemaRefreshUtils.getActualSchemaName(same(database),
any(IdentifierValue.class))).thenCallRealMethod();
+ PushDownMetaDataManagerPersistServiceFixture persistService = new
PushDownMetaDataManagerPersistServiceFixture();
+ new
PushDownMetaDataRefreshEngine(sqlStatementContext).refresh(persistService,
database, new ConfigurationProperties(new Properties()),
Collections.emptyList());
+ assertThat(persistService.getDroppedTableSchemaName(),
is("Foo_Schema"));
+ assertThat(persistService.getDroppedTableNames(), contains("Foo_Tbl"));
+ }
+
+ private DropTableStatement createDropTableStatement() {
+ TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new
IdentifierValue("foo_tbl"));
+ tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
+ return new DropTableStatement(databaseType,
Collections.singletonList(new SimpleTableSegment(tableNameSegment)), false,
false);
+ }
+
+ private ShardingSphereDatabase createDatabase() {
+ ShardingSphereSchema schema = new ShardingSphereSchema("Foo_Schema",
databaseType,
+ Collections.singletonList(new ShardingSphereTable("Foo_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
+ Collections.emptyList());
+ ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
+ when(result.getIdentifierContext()).thenReturn(new
DatabaseIdentifierContext(IdentifierCasePolicyFactory.newInsensitivePolicySet()));
+ when(result.getAllSchemas()).thenReturn(Collections.singleton(schema));
+ when(result.getSchema("Foo_Schema")).thenReturn(schema);
+ return result;
+ }
}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsIdentifierTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsIdentifierTest.java
deleted file mode 100644
index 9ab3f99e65b..00000000000
---
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsIdentifierTest.java
+++ /dev/null
@@ -1,110 +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.mode.metadata.refresher.util;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-class TableRefreshUtilsIdentifierTest {
-
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
-
- @Test
- void assertGetActualTableNameUsesExistingTableName() {
- assertThat(TableRefreshUtils.getActualTableName(createDatabase(),
"foo_schema", new IdentifierValue("foo_tbl")), is("Foo_Tbl"));
- }
-
- @Test
- void assertGetActualTableNamesUsesExistingTableNames() {
- assertThat(TableRefreshUtils.getActualTableNames(createDatabase(),
"foo_schema", Arrays.asList(new IdentifierValue("foo_tbl"), new
IdentifierValue("bar_tbl"))),
- is(Arrays.asList("Foo_Tbl", "Bar_Tbl")));
- }
-
- @Test
- void assertGetActualViewNamesUsesExistingViewNames() {
- assertThat(TableRefreshUtils.getActualViewNames(createDatabase(),
"foo_schema", Arrays.asList(new IdentifierValue("foo_view"), new
IdentifierValue("bar_view"))),
- is(Arrays.asList("Foo_View", "Bar_View")));
- }
-
- @Test
- void assertGetActualViewNameUsesExistingViewName() {
- assertThat(TableRefreshUtils.getActualViewName(createDatabase(),
"foo_schema", new IdentifierValue("foo_view")), is("Foo_View"));
- }
-
- @Test
- void assertGetActualIndexNameUsesExistingIndexName() {
- assertThat(TableRefreshUtils.getActualIndexName(createDatabase(),
"foo_schema", "foo_tbl", new IdentifierValue("idx_foo")), is("Idx_Foo"));
- }
-
- @Test
- void assertGetActualColumnNamesUsesExistingColumnNames() {
- assertThat(TableRefreshUtils.getActualColumnNames(createDatabase(),
"foo_schema", "foo_tbl",
- Arrays.asList(new IdentifierValue("order_id"), new
IdentifierValue("user_id"))),
- is(Arrays.asList("Order_ID", "User_ID")));
- }
-
- @Test
- void assertFindActualTableNameByIndexUsesExistingIndexName() {
-
assertThat(TableRefreshUtils.findActualTableNameByIndex(createDatabase(),
"foo_schema", new IdentifierValue("idx_foo")).get(), is("Foo_Tbl"));
- }
-
- @Test
- void assertGetTableLoadCandidateNameUsesNormalizedRule() {
-
assertThat(TableRefreshUtils.getTableLoadCandidateName(createDatabase(), new
IdentifierValue("Foo_Tbl")), is("foo_tbl"));
- }
-
- @Test
- void assertGetViewLoadCandidateNameUsesNormalizedRule() {
-
assertThat(TableRefreshUtils.getViewLoadCandidateName(createDatabase(), new
IdentifierValue("Foo_View")), is("foo_view"));
- }
-
- private ShardingSphereDatabase createDatabase() {
- return createDatabase(databaseType);
- }
-
- private ShardingSphereDatabase createDatabase(final DatabaseType
databaseType) {
- ShardingSphereSchema schema = new ShardingSphereSchema("Foo_Schema",
databaseType,
- Arrays.asList(new ShardingSphereTable("Foo_Tbl",
- Arrays.asList(new ShardingSphereColumn("Order_ID", 0,
false, false, false, true, false, true),
- new ShardingSphereColumn("User_ID", 0, false,
false, false, true, false, true)),
- Collections.singletonList(new
ShardingSphereIndex("Idx_Foo", Collections.singletonList("Order_ID"), false)),
- Collections.emptyList()),
- new ShardingSphereTable("Bar_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
- Arrays.asList(new ShardingSphereView("Foo_View", "SELECT 1"),
new ShardingSphereView("Bar_View", "SELECT 1")));
- return new ShardingSphereDatabase("foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()),
- new RuleMetaData(Collections.emptyList()),
Collections.singletonList(schema), new ConfigurationProperties(new
Properties()));
- }
-}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
index 10a8f82c256..80b16cb2485 100644
---
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
+++
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
@@ -24,6 +24,8 @@ import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView;
@@ -76,6 +78,38 @@ class TableRefreshUtilsTest {
is(Arrays.asList("Foo_View", "Bar_View")));
}
+ @Test
+ void assertGetActualViewNameUsesExistingViewName() {
+ assertThat(TableRefreshUtils.getActualViewName(createDatabase(),
"foo_schema", new IdentifierValue("foo_view")), is("Foo_View"));
+ }
+
+ @Test
+ void assertGetActualIndexNameUsesExistingIndexName() {
+ assertThat(TableRefreshUtils.getActualIndexName(createDatabase(),
"foo_schema", "foo_tbl", new IdentifierValue("idx_foo")), is("Idx_Foo"));
+ }
+
+ @Test
+ void assertGetActualColumnNamesUsesExistingColumnNames() {
+ assertThat(TableRefreshUtils.getActualColumnNames(createDatabase(),
"foo_schema", "foo_tbl",
+ Arrays.asList(new IdentifierValue("order_id"), new
IdentifierValue("user_id"))),
+ is(Arrays.asList("Order_ID", "User_ID")));
+ }
+
+ @Test
+ void assertFindActualTableNameByIndexUsesExistingIndexName() {
+
assertThat(TableRefreshUtils.findActualTableNameByIndex(createDatabase(),
"foo_schema", new IdentifierValue("idx_foo")).get(), is("Foo_Tbl"));
+ }
+
+ @Test
+ void assertGetTableLoadCandidateNameUsesNormalizedRule() {
+
assertThat(TableRefreshUtils.getTableLoadCandidateName(createDatabase(), new
IdentifierValue("Foo_Tbl")), is("foo_tbl"));
+ }
+
+ @Test
+ void assertGetViewLoadCandidateNameUsesNormalizedRule() {
+
assertThat(TableRefreshUtils.getViewLoadCandidateName(createDatabase(), new
IdentifierValue("Foo_View")), is("foo_view"));
+ }
+
@Test
void assertIsSingleTableWhenDistributedTableExists() {
TableMapperRuleAttribute tableMapperRuleAttribute =
mock(TableMapperRuleAttribute.class);
@@ -218,7 +252,11 @@ class TableRefreshUtilsTest {
private ShardingSphereDatabase createDatabase() {
ShardingSphereSchema schema = new ShardingSphereSchema("Foo_Schema",
fixtureDatabaseType,
- Arrays.asList(new ShardingSphereTable("Foo_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList()),
+ Arrays.asList(new ShardingSphereTable("Foo_Tbl",
+ Arrays.asList(new ShardingSphereColumn("Order_ID", 0,
false, false, false, true, false, true),
+ new ShardingSphereColumn("User_ID", 0, false,
false, false, true, false, true)),
+ Collections.singletonList(new
ShardingSphereIndex("Idx_Foo", Collections.singletonList("Order_ID"), false)),
+ Collections.emptyList()),
new ShardingSphereTable("Bar_Tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())),
Arrays.asList(new ShardingSphereView("Foo_View", "SELECT 1"),
new ShardingSphereView("Bar_View", "SELECT 1")));
return new ShardingSphereDatabase("foo_db", fixtureDatabaseType, new
ResourceMetaData(Collections.emptyMap()),