Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless field on ShardingInsertSupportedCheckerTest #34081

Merged
merged 3 commits into from
Dec 16, 2024
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 @@ -19,10 +19,8 @@

import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.checker.sql.dml.ShardingInsertSupportedChecker;
import org.apache.shardingsphere.sharding.exception.syntax.DMLWithMultipleShardingTablesException;
import org.apache.shardingsphere.sharding.exception.syntax.InsertSelectTableViolationException;
Expand Down Expand Up @@ -62,8 +60,6 @@
@ExtendWith(MockitoExtension.class)
class ShardingInsertSupportedCheckerTest {

private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE");

@Mock
private ShardingRule rule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@ public final class ShardingSphereDatabaseData {

private final Map<String, ShardingSphereSchemaData> schemaData = new CaseInsensitiveMap<>();

/**
* Judge whether to contains schema.
*
* @param schemaName schema name
* @return contains schema or not
*/
public boolean containsSchema(final String schemaName) {
return schemaData.containsKey(schemaName);
}

/**
* Get ShardingSphere schema data.
*
* @param schemaName schema name
* @return ShardingSphere schema data
* @return schema data
*/
public ShardingSphereSchemaData getSchema(final String schemaName) {
return schemaData.get(schemaName);
}

/**
* Put ShardingSphere schema data.
* Put schema data.
*
* @param schemaName schema name
* @param schema ShardingSphere schema data
* @param schema schema data
*/
public void putSchema(final String schemaName, final ShardingSphereSchemaData schema) {
schemaData.put(schemaName, schema);
}

/**
* Remove ShardingSphere schema data.
* Remove schema data.
*
* @param schemaName schema name
*/
public void removeSchema(final String schemaName) {
schemaData.remove(schemaName);
}

/**
* Judge contains ShardingSphere schema from ShardingSphere database or not.
*
* @param schemaName schema name
* @return Contains schema from database or not
*/
public boolean containsSchema(final String schemaName) {
return schemaData.containsKey(schemaName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.statistics;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ShardingSphereDatabaseDataTest {

private final ShardingSphereDatabaseData databaseData = new ShardingSphereDatabaseData();

@BeforeEach
void setUp() {
databaseData.putSchema("foo_schema", new ShardingSphereSchemaData());
}

@Test
void assertContainsSchema() {
assertTrue(databaseData.containsSchema("foo_schema"));
assertFalse(databaseData.containsSchema("bar_schema"));
}

@Test
void assertGetSchema() {
assertTrue(databaseData.getSchema("foo_schema").getTableData().isEmpty());
assertNull(databaseData.getSchema("bar_schema"));
}

@Test
void assertPutSchema() {
databaseData.putSchema("bar_schema", new ShardingSphereSchemaData());
assertTrue(databaseData.containsSchema("bar_schema"));
}

@Test
void assertRemoveSchema() {
databaseData.removeSchema("foo_schema");
assertFalse(databaseData.containsSchema("foo_schema"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Optional<ShardingSphereStatistics> load(final ShardingSphereMetaData meta
private ShardingSphereDatabaseData load(final String databaseName, final ShardingSphereDatabase database) {
ShardingSphereDatabaseData result = new ShardingSphereDatabaseData();
for (String each : repository.getChildrenKeys(ShardingSphereDataNode.getSchemasPath(databaseName)).stream().filter(database::containsSchema).collect(Collectors.toList())) {
result.getSchemaData().put(each, load(databaseName, each, database.getSchema(each)));
result.putSchema(each, load(databaseName, each, database.getSchema(each)));
}
return result;
}
Expand Down
Loading