diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java index 9dcb830da82c2..c8ea76be5be17 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java @@ -61,11 +61,11 @@ public final class SystemSchemaManager { } /** - * Judge whether current table is system table or not. + * Judge whether the current table is system table. * * @param schema schema * @param tableName table name - * @return whether current table is system table or not + * @return is system table or not */ public static boolean isSystemTable(final String schema, final String tableName) { for (Entry>> entry : DATABASE_TYPE_SCHEMA_TABLE_MAP.entrySet()) { @@ -77,12 +77,12 @@ public static boolean isSystemTable(final String schema, final String tableName) } /** - * Judge whether current table is system table or not. + * Judge whether the current table is system table. * * @param databaseType database type * @param schema schema * @param tableName table name - * @return whether current table is system table or not + * @return is system table or not */ public static boolean isSystemTable(final String databaseType, final String schema, final String tableName) { Map> schemaTableMap = DATABASE_TYPE_SCHEMA_TABLE_MAP.getOrDefault(databaseType, Collections.emptyMap()); @@ -94,12 +94,12 @@ public static boolean isSystemTable(final String databaseType, final String sche } /** - * Judge whether current table is system table or not. + * Judge whether the current table is system table. * * @param databaseType database type * @param schema schema * @param tableNames table names - * @return whether current table is system table or not + * @return is system table or not */ public static boolean isSystemTable(final String databaseType, final String schema, final Collection tableNames) { Collection databaseTypeTables = Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(databaseType)).map(schemas -> schemas.get(schema)).orElse(Collections.emptyList()); @@ -131,7 +131,7 @@ public static Collection getTables(final String databaseType, final Stri * * @param databaseType database type * @param schema schema - * @return inputStream collection + * @return input streams */ public static Collection getAllInputStreams(final String databaseType, final String schema) { Collection result = new LinkedList<>(); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java index a88453a05a59c..5566ff2779d17 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java @@ -19,11 +19,15 @@ import org.junit.jupiter.api.Test; +import java.io.InputStream; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; class SystemSchemaManagerTest { @@ -83,4 +87,38 @@ void assertIsisSystemTable() { assertTrue(SystemSchemaManager.isSystemTable("shardingsphere", "cluster_information")); assertFalse(SystemSchemaManager.isSystemTable("shardingsphere", "nonexistent")); } + + @Test + void assertIsSystemTableWithDatabaseTypeAndNullSchema() { + assertTrue(SystemSchemaManager.isSystemTable("MySQL", null, "columns")); + assertTrue(SystemSchemaManager.isSystemTable("PostgreSQL", null, "pg_database")); + assertFalse(SystemSchemaManager.isSystemTable("MySQL", null, "nonexistent_table")); + } + + @Test + void assertIsSystemTableWithDatabaseTypeAndSchema() { + assertTrue(SystemSchemaManager.isSystemTable("MySQL", "information_schema", "columns")); + assertTrue(SystemSchemaManager.isSystemTable("PostgreSQL", "pg_catalog", "pg_database")); + assertTrue(SystemSchemaManager.isSystemTable("MySQL", "shardingsphere", "cluster_information")); + assertFalse(SystemSchemaManager.isSystemTable("MySQL", "information_schema", "nonexistent_table")); + assertFalse(SystemSchemaManager.isSystemTable("NonExistentDB", "test_schema", "test_table")); + } + + @Test + void assertIsSystemTableWithTableNamesCollection() { + assertTrue(SystemSchemaManager.isSystemTable("MySQL", "information_schema", Arrays.asList("columns", "tables", "schemata"))); + assertFalse(SystemSchemaManager.isSystemTable("MySQL", "information_schema", Arrays.asList("columns", "nonexistent_table"))); + assertTrue(SystemSchemaManager.isSystemTable("PostgreSQL", "pg_catalog", Arrays.asList("pg_database", "pg_tables"))); + assertFalse(SystemSchemaManager.isSystemTable("NonExistentDB", "test_schema", Collections.singleton("test_table"))); + assertTrue(SystemSchemaManager.isSystemTable("MySQL", "nonexistent_schema", Collections.emptyList())); + } + + @Test + void assertGetAllInputStreams() { + java.util.Collection actual = SystemSchemaManager.getAllInputStreams("MySQL", "information_schema"); + assertThat(actual.size(), is(95)); + for (InputStream each : actual) { + assertNotNull(each); + } + } } diff --git a/infra/common/src/test/resources/logback-test.xml b/infra/common/src/test/resources/logback-test.xml new file mode 100644 index 0000000000000..b420ff1121035 --- /dev/null +++ b/infra/common/src/test/resources/logback-test.xml @@ -0,0 +1,33 @@ + + + + + + + + [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n + + + + + + + + + +