Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Map<String, Collection<String>>> entry : DATABASE_TYPE_SCHEMA_TABLE_MAP.entrySet()) {
Expand All @@ -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<String, Collection<String>> schemaTableMap = DATABASE_TYPE_SCHEMA_TABLE_MAP.getOrDefault(databaseType, Collections.emptyMap());
Expand All @@ -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<String> tableNames) {
Collection<String> databaseTypeTables = Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(databaseType)).map(schemas -> schemas.get(schema)).orElse(Collections.emptyList());
Expand Down Expand Up @@ -131,7 +131,7 @@ public static Collection<String> getTables(final String databaseType, final Stri
*
* @param databaseType database type
* @param schema schema
* @return inputStream collection
* @return input streams
*/
public static Collection<InputStream> getAllInputStreams(final String databaseType, final String schema) {
Collection<InputStream> result = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<java.io.InputStream> actual = SystemSchemaManager.getAllInputStreams("MySQL", "information_schema");
assertThat(actual.size(), is(95));
for (InputStream each : actual) {
assertNotNull(each);
}
}
}
33 changes: 33 additions & 0 deletions infra/common/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.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.
-->

<configuration>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.apache.shardingsphere" level="warn" additivity="true">
<appender-ref ref="console" />
</logger>
<root>
<level value="info" />
<appender-ref ref="console" />
</root>
</configuration>