Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace mock(ShardingSphereSchema.class) to new ShardingSphereSchema …
Browse files Browse the repository at this point in the history
…if necessary
terrymanu committed Dec 5, 2024
1 parent dcee76b commit ca0a205
Showing 35 changed files with 170 additions and 324 deletions.
Original file line number Diff line number Diff line change
@@ -27,8 +27,6 @@
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sql.parser.statement.core.enums.OrderDirection;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
@@ -94,14 +92,12 @@ void assertIsCheckWithSubQueryOrderBy() {

@Test
void assertCheckFailed() {
assertThrows(UnsupportedEncryptSQLException.class,
() -> new EncryptOrderByItemSupportedChecker().check(mockEncryptRule(), mock(ShardingSphereDatabase.class), mock(ShardingSphereSchema.class), mockSelectStatementContext("foo_tbl")));
assertThrows(UnsupportedEncryptSQLException.class, () -> new EncryptOrderByItemSupportedChecker().check(mockEncryptRule(), mock(), mock(), mockSelectStatementContext("foo_tbl")));
}

@Test
void assertCheckSuccess() {
assertDoesNotThrow(
() -> new EncryptOrderByItemSupportedChecker().check(mockEncryptRule(), mock(ShardingSphereDatabase.class), mock(ShardingSphereSchema.class), mockSelectStatementContext("bar_tbl")));
assertDoesNotThrow(() -> new EncryptOrderByItemSupportedChecker().check(mockEncryptRule(), mock(), mock(), mockSelectStatementContext("bar_tbl")));
}

private EncryptRule mockEncryptRule() {
Original file line number Diff line number Diff line change
@@ -17,12 +17,9 @@

package org.apache.shardingsphere.encrypt.checker.sql.projection;

import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertSelectContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -55,8 +52,6 @@ void assertIsCheckWithInsertSelect() {

@Test
void assertCheckSuccess() {
assertDoesNotThrow(
() -> new EncryptInsertSelectProjectionSupportedChecker().check(mock(EncryptRule.class), mock(ShardingSphereDatabase.class), mock(ShardingSphereSchema.class),
mock(InsertStatementContext.class, RETURNS_DEEP_STUBS)));
assertDoesNotThrow(() -> new EncryptInsertSelectProjectionSupportedChecker().check(mock(), mock(), mock(), mock(InsertStatementContext.class, RETURNS_DEEP_STUBS)));
}
}
Original file line number Diff line number Diff line change
@@ -70,8 +70,7 @@ void assertCheckWhenIndexNotExistRenameIndexNotExistForPostgreSQL() {
sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new"))));
ShardingSphereTable table = mock(ShardingSphereTable.class);
when(database.getSchema("public").getTable("t_order")).thenReturn(table);
assertThrows(IndexNotExistedException.class, () -> new ShardingAlterIndexSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class),
new AlterIndexStatementContext(sqlStatement, "foo_db")));
assertThrows(IndexNotExistedException.class, () -> new ShardingAlterIndexSupportedChecker().check(shardingRule, database, mock(), new AlterIndexStatementContext(sqlStatement, "foo_db")));
}

@Test
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@

import org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterTableStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -54,7 +53,6 @@ void assertCheckWithRenameTableWithShardingTable() {
sqlStatement.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_new"))));
AlterTableStatementContext sqlStatementContext = new AlterTableStatementContext(sqlStatement, "foo_db");
when(shardingRule.containsShardingTable(Arrays.asList("t_order", "t_order_new"))).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingAlterTableSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingAlterTableSupportedChecker().check(shardingRule, database, mock(), sqlStatementContext));
}
}
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;

import org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterViewStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.metadata.EngagedViewException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -42,7 +40,7 @@
class ShardingAlterViewSupportedCheckerTest {

@Mock
private ShardingRule shardingRule;
private ShardingRule rule;

@Test
void assertPreValidateAlterViewForMySQL() {
@@ -52,9 +50,8 @@ void assertPreValidateAlterViewForMySQL() {
sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view"))));
sqlStatement.setSelect(selectStatement);
AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
when(shardingRule.isShardingTable("t_order")).thenReturn(false);
assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(rule.isShardingTable("t_order")).thenReturn(false);
assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext));
}

@Test
@@ -64,11 +61,9 @@ void assertPreValidateAlterViewWithShardingTableForMySQL() {
MySQLAlterViewStatement sqlStatement = new MySQLAlterViewStatement();
sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view"))));
sqlStatement.setSelect(selectStatement);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db");
when(shardingRule.isShardingTable("t_order")).thenReturn(true);
assertThrows(EngagedViewException.class,
() -> new ShardingAlterViewSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(rule.isShardingTable("t_order")).thenReturn(true);
assertThrows(EngagedViewException.class, () -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext));
}

@Test
@@ -77,7 +72,6 @@ void assertPreValidateAlterRenamedView() {
sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view"))));
sqlStatement.setRenameView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_new"))));
AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext));
}
}
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@
class ShardingCreateFunctionSupportedCheckerTest {

@Mock
private ShardingRule shardingRule;
private ShardingRule rule;

@Test
void assertCheckCreateFunctionForMySQL() {
@@ -68,7 +68,7 @@ void assertCheckCreateFunctionForMySQL() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order_item")).thenReturn(true);
assertDoesNotThrow(() -> new ShardingCreateFunctionSupportedChecker().check(shardingRule, database, schema, sqlStatementContext));
assertDoesNotThrow(() -> new ShardingCreateFunctionSupportedChecker().check(rule, database, schema, sqlStatementContext));
}

@Test
@@ -83,9 +83,8 @@ void assertCheckCreateFunctionWithShardingTableForMySQL() {
sqlStatement.setRoutineBody(routineBody);
CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(shardingRule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingCreateFunctionSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(rule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingCreateFunctionSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

@Test
@@ -100,7 +99,7 @@ void assertCheckCreateFunctionWithNoSuchTableForMySQL() {
sqlStatement.setRoutineBody(routineBody);
CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
assertThrows(NoSuchTableException.class, () -> new ShardingCreateFunctionSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertThrows(NoSuchTableException.class, () -> new ShardingCreateFunctionSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

@Test
@@ -117,6 +116,6 @@ void assertCheckCreateFunctionWithTableExistsForMySQL() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order")).thenReturn(true);
assertThrows(TableExistsException.class, () -> new ShardingCreateFunctionSupportedChecker().check(shardingRule, database, schema, sqlStatementContext));
assertThrows(TableExistsException.class, () -> new ShardingCreateFunctionSupportedChecker().check(rule, database, schema, sqlStatementContext));
}
}
Original file line number Diff line number Diff line change
@@ -67,8 +67,7 @@ void assertCheckWhenTableNotExistIndexNotExistForPostgreSQL() {
sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index"))));
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order")).thenReturn(false);
assertThrows(NoSuchTableException.class,
() -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
}

@Test
@@ -79,8 +78,7 @@ void assertCheckWhenTableExistIndexExistForPostgreSQL() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order")).thenReturn(true);
when(schema.containsIndex("t_order", "t_order_index")).thenReturn(true);
assertThrows(DuplicateIndexException.class,
() -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
}

@Test
@@ -102,8 +100,7 @@ void assertCheckWithoutIndexNameWhenTableNotExistIndexNotExistForPostgreSQL() {
sqlStatement.setGeneratedIndexStartIndex(10);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order")).thenReturn(false);
assertThrows(NoSuchTableException.class,
() -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
}

@Test
@@ -115,7 +112,6 @@ void assertCheckWithoutIndexNameWhenTableExistIndexExistForPostgreSQL() {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order")).thenReturn(true);
when(schema.containsIndex("t_order", "content_idx")).thenReturn(true);
assertThrows(DuplicateIndexException.class,
() -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(shardingRule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db")));
}
}
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@
class ShardingCreateProcedureSupportedCheckerTest {

@Mock
private ShardingRule shardingRule;
private ShardingRule rule;

@Test
void assertCheckForMySQL() {
@@ -67,9 +67,9 @@ void assertCheckForMySQL() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order_item")).thenReturn(true);
when(shardingRule.isShardingTable("t_order_item")).thenReturn(false);
when(rule.isShardingTable("t_order_item")).thenReturn(false);
CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db");
assertDoesNotThrow(() -> new ShardingCreateProcedureSupportedChecker().check(shardingRule, database, schema, sqlStatementContext));
assertDoesNotThrow(() -> new ShardingCreateProcedureSupportedChecker().check(rule, database, schema, sqlStatementContext));
}

@Test
@@ -84,9 +84,8 @@ void assertCheckWithShardingTableForMySQL() {
sqlStatement.setRoutineBody(routineBody);
CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(shardingRule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingCreateProcedureSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(rule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingCreateProcedureSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

@Test
@@ -101,7 +100,7 @@ void assertCheckWithNoSuchTableForMySQL() {
sqlStatement.setRoutineBody(routineBody);
CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
assertThrows(NoSuchTableException.class, () -> new ShardingCreateProcedureSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertThrows(NoSuchTableException.class, () -> new ShardingCreateProcedureSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

@Test
@@ -118,6 +117,6 @@ void assertCheckWithTableExistsForMySQL() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order")).thenReturn(true);
assertThrows(TableExistsException.class, () -> new ShardingCreateProcedureSupportedChecker().check(shardingRule, database, schema, sqlStatementContext));
assertThrows(TableExistsException.class, () -> new ShardingCreateProcedureSupportedChecker().check(rule, database, schema, sqlStatementContext));
}
}
Original file line number Diff line number Diff line change
@@ -107,6 +107,6 @@ void assertCheckIfNotExistsForPostgreSQL() {
private void assertCheckIfNotExists(final CreateTableStatement sqlStatement) {
CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement, "foo_db");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
new ShardingCreateTableSupportedChecker().check(rule, database, mock(ShardingSphereSchema.class), sqlStatementContext);
new ShardingCreateTableSupportedChecker().check(rule, database, mock(), sqlStatementContext);
}
}
Original file line number Diff line number Diff line change
@@ -75,14 +75,13 @@ void setUp() {

@Test
void assertCheck() {
assertDoesNotThrow(() -> new ShardingCreateViewSupportedChecker().check(shardingRule, mock(ShardingSphereDatabase.class), mock(ShardingSphereSchema.class), createViewStatementContext));
assertDoesNotThrow(() -> new ShardingCreateViewSupportedChecker().check(shardingRule, mock(), mock(), createViewStatementContext));
}

@Test
void assertCheckWithException() {
when(shardingRule.isShardingTable(any())).thenReturn(true);
when(shardingRule.isAllBindingTables(any())).thenReturn(false);
assertThrows(EngagedViewException.class,
() -> new ShardingCreateViewSupportedChecker().check(shardingRule, mock(ShardingSphereDatabase.class), mock(ShardingSphereSchema.class), createViewStatementContext));
assertThrows(EngagedViewException.class, () -> new ShardingCreateViewSupportedChecker().check(shardingRule, mock(), mock(), createViewStatementContext));
}
}
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@
class ShardingDropIndexSupportedCheckerTest {

@Mock
private ShardingRule shardingRule;
private ShardingRule rule;

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
@@ -59,7 +59,7 @@ void assertCheckWhenIndexExistForPostgreSQL() {
when(schema.getAllTables()).thenReturn(Collections.singleton(table));
when(table.containsIndex("t_order_index")).thenReturn(true);
when(table.containsIndex("t_order_index_new")).thenReturn(true);
assertDoesNotThrow(() -> new ShardingDropIndexSupportedChecker().check(shardingRule, database, schema, new DropIndexStatementContext(sqlStatement, "foo_db")));
assertDoesNotThrow(() -> new ShardingDropIndexSupportedChecker().check(rule, database, schema, new DropIndexStatementContext(sqlStatement, "foo_db")));
}

@Test
@@ -70,7 +70,6 @@ void assertCheckWhenIndexNotExistForPostgreSQL() {
ShardingSphereTable table = mock(ShardingSphereTable.class);
when(database.getSchema("public").getAllTables()).thenReturn(Collections.singleton(table));
when(database.getSchema("public").getTable("t_order")).thenReturn(table);
assertThrows(IndexNotExistedException.class,
() -> new ShardingDropIndexSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), new DropIndexStatementContext(sqlStatement, "foo_db")));
assertThrows(IndexNotExistedException.class, () -> new ShardingDropIndexSupportedChecker().check(rule, database, mock(), new DropIndexStatementContext(sqlStatement, "foo_db")));
}
}
Original file line number Diff line number Diff line change
@@ -19,13 +19,9 @@

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.config.props.ConfigurationProperties;
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.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.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.checker.sql.dml.ShardingInsertSupportedChecker;
import org.apache.shardingsphere.sharding.exception.syntax.DMLWithMultipleShardingTablesException;
@@ -66,6 +62,8 @@
@ExtendWith(MockitoExtension.class)
class ShardingInsertSupportedCheckerTest {

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

@Mock
private ShardingRule rule;

@@ -76,15 +74,13 @@ class ShardingInsertSupportedCheckerTest {
void assertCheckWhenInsertMultiTables() {
InsertStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertStatement());
Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
when(rule.isAllShardingTables(tableNames)).thenReturn(false);
when(rule.containsShardingTable(tableNames)).thenReturn(true);
assertThrows(DMLWithMultipleShardingTablesException.class, () -> new ShardingInsertSupportedChecker().check(rule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertThrows(DMLWithMultipleShardingTablesException.class, () -> new ShardingInsertSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

private InsertStatementContext createInsertStatementContext(final List<Object> params, final InsertStatement insertStatement) {
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock());
return new InsertStatementContext(metaData, params, insertStatement, "foo_db");
}

@@ -94,8 +90,7 @@ void assertCheckWhenInsertSelectWithoutKeyGenerateColumn() {
when(rule.isGenerateKeyColumn("id", "user")).thenReturn(false);
InsertStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement());
sqlStatementContext.getTablesContext().getTableNames().addAll(createSingleTablesContext().getTableNames());
assertThrows(MissingGenerateKeyColumnWithInsertSelectException.class,
() -> new ShardingInsertSupportedChecker().check(rule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertThrows(MissingGenerateKeyColumnWithInsertSelectException.class, () -> new ShardingInsertSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

@Test
@@ -104,19 +99,18 @@ void assertCheckWhenInsertSelectWithKeyGenerateColumn() {
when(rule.isGenerateKeyColumn("id", "user")).thenReturn(true);
InsertStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement());
sqlStatementContext.getTablesContext().getTableNames().addAll(createSingleTablesContext().getTableNames());
assertDoesNotThrow(() -> new ShardingInsertSupportedChecker().check(rule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertDoesNotThrow(() -> new ShardingInsertSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

@Test
void assertCheckWhenInsertSelectWithoutBindingTables() {
when(rule.findGenerateKeyColumnName("user")).thenReturn(Optional.of("id"));
when(rule.isGenerateKeyColumn("id", "user")).thenReturn(true);
TablesContext multiTablesContext = createMultiTablesContext();
when(rule.isAllBindingTables(multiTablesContext.getTableNames())).thenReturn(false);
when(rule.containsShardingTable(multiTablesContext.getTableNames())).thenReturn(true);
InsertStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement());
sqlStatementContext.getTablesContext().getTableNames().addAll(multiTablesContext.getTableNames());
assertThrows(InsertSelectTableViolationException.class, () -> new ShardingInsertSupportedChecker().check(rule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertThrows(InsertSelectTableViolationException.class, () -> new ShardingInsertSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

@Test
@@ -126,7 +120,7 @@ void assertCheckWhenInsertSelectWithBindingTables() {
TablesContext multiTablesContext = createMultiTablesContext();
InsertStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertSelectStatement());
sqlStatementContext.getTablesContext().getTableNames().addAll(multiTablesContext.getTableNames());
assertDoesNotThrow(() -> new ShardingInsertSupportedChecker().check(rule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertDoesNotThrow(() -> new ShardingInsertSupportedChecker().check(rule, database, mock(), sqlStatementContext));
}

private InsertStatement createInsertStatement() {
@@ -154,13 +148,13 @@ private InsertStatement createInsertSelectStatement() {
private TablesContext createSingleTablesContext() {
List<SimpleTableSegment> result = new LinkedList<>();
result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
return new TablesContext(result, TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), "foo_db");
return new TablesContext(result, databaseType, "foo_db");
}

private TablesContext createMultiTablesContext() {
List<SimpleTableSegment> result = new LinkedList<>();
result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order"))));
return new TablesContext(result, TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), "foo_db");
return new TablesContext(result, databaseType, "foo_db");
}
}
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;

import org.apache.shardingsphere.infra.binder.context.statement.ddl.RenameTableStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.RenameTableDefinitionSegment;
@@ -47,17 +45,14 @@ class ShardingRenameTableSupportedCheckerTest {
@Test
void assertCheckShardingTable() {
RenameTableStatementContext sqlStatementContext = createRenameTableStatementContext("t_order", "t_user_order");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
when(shardingRule.containsShardingTable(argThat(tableNames -> tableNames.contains("t_order") || tableNames.contains("t_user_order")))).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingRenameTableSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingRenameTableSupportedChecker().check(shardingRule, mock(), mock(), sqlStatementContext));
}

@Test
void assertCheckNormalCase() {
RenameTableStatementContext sqlStatementContext = createRenameTableStatementContext("t_not_sharding_table", "t_not_sharding_table_new");
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
assertDoesNotThrow(() -> new ShardingRenameTableSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
assertDoesNotThrow(() -> new ShardingRenameTableSupportedChecker().check(shardingRule, mock(), mock(), sqlStatementContext));
}

private RenameTableStatementContext createRenameTableStatementContext(final String originTableName, final String newTableName) {
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.CopyStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -30,7 +28,6 @@
import org.apache.shardingsphere.sql.parser.statement.postgresql.dml.PostgreSQLCopyStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@@ -43,25 +40,20 @@
class ShardingCopySupportedCheckerTest {

@Mock
private ShardingRule shardingRule;

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
private ShardingRule rule;

@Test
void assertCheckWhenTableSegmentForPostgreSQL() {
PostgreSQLCopyStatement sqlStatement = new PostgreSQLCopyStatement();
sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
assertDoesNotThrow(
() -> new ShardingCopySupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), new CopyStatementContext(sqlStatement, "foo_db")));
assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement, "foo_db")));
}

@Test
void assertCheckWhenTableSegmentForOpenGauss() {
OpenGaussCopyStatement sqlStatement = new OpenGaussCopyStatement();
sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
assertDoesNotThrow(
() -> new ShardingCopySupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), new CopyStatementContext(sqlStatement, "foo_db")));
assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement, "foo_db")));
}

@Test
@@ -78,7 +70,7 @@ private void assertCheckCopyTable(final CopyStatement sqlStatement) {
sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
CopyStatementContext sqlStatementContext = new CopyStatementContext(sqlStatement, "foo_db");
String tableName = "t_order";
when(shardingRule.isShardingTable(tableName)).thenReturn(true);
new ShardingCopySupportedChecker().check(shardingRule, mock(ShardingSphereDatabase.class), mock(ShardingSphereSchema.class), sqlStatementContext);
when(rule.isShardingTable(tableName)).thenReturn(true);
new ShardingCopySupportedChecker().check(rule, mock(), mock(), sqlStatementContext);
}
}
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.syntax.DMLWithMultipleShardingTablesException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.DeleteMultiTableSegment;
@@ -85,8 +83,7 @@ private void assertCheckWhenDeleteMultiTables(final DeleteStatement sqlStatement
Collection<String> tableNames = new HashSet<>(Arrays.asList("user", "order", "order_item"));
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(false);
when(shardingRule.containsShardingTable(tableNames)).thenReturn(true);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
DeleteStatementContext sqlStatementContext = new DeleteStatementContext(sqlStatement, "foo_db");
new ShardingDeleteSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext);
new ShardingDeleteSupportedChecker().check(shardingRule, mock(), mock(), sqlStatementContext);
}
}
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.LoadDataStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -28,7 +26,6 @@
import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLLoadDataStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@@ -41,23 +38,18 @@
class ShardingLoadDataSupportedCheckerTest {

@Mock
private ShardingRule shardingRule;

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
private ShardingRule rule;

@Test
void assertCheckWithSingleTable() {
MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
assertDoesNotThrow(
() -> new ShardingLoadDataSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), new LoadDataStatementContext(sqlStatement, "foo_db")));
assertDoesNotThrow(() -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement, "foo_db")));
}

@Test
void assertCheckWithShardingTable() {
MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
when(shardingRule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingLoadDataSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), new LoadDataStatementContext(sqlStatement, "foo_db")));
when(rule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement, "foo_db")));
}
}
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.LoadXMLStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -28,7 +26,6 @@
import org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLLoadXMLStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@@ -41,23 +38,18 @@
class ShardingLoadXmlSupportedCheckerTest {

@Mock
private ShardingRule shardingRule;

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
private ShardingRule rule;

@Test
void assertCheckWithSingleTable() {
MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
assertDoesNotThrow(
() -> new ShardingLoadXmlSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), new LoadXMLStatementContext(sqlStatement, "foo_db")));
assertDoesNotThrow(() -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement, "foo_db")));
}

@Test
void assertCheckWithShardingTable() {
MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
when(shardingRule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingLoadXmlSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), new LoadXMLStatementContext(sqlStatement, "foo_db")));
when(rule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement, "foo_db")));
}
}
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;

import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.exception.syntax.DMLWithMultipleShardingTablesException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment;
@@ -51,20 +49,17 @@
class ShardingUpdateSupportedCheckerTest {

@Mock
private ShardingRule shardingRule;

@Mock
private ShardingSphereDatabase database;
private ShardingRule rule;

@Test
void assertCheckWhenUpdateSingleTable() {
UpdateStatement updateStatement = createUpdateStatement();
updateStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user"))));
UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement, "foo_db");
Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true);
when(shardingRule.containsShardingTable(tableNames)).thenReturn(true);
assertDoesNotThrow(() -> new ShardingUpdateSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(rule.isAllShardingTables(tableNames)).thenReturn(true);
when(rule.containsShardingTable(tableNames)).thenReturn(true);
assertDoesNotThrow(() -> new ShardingUpdateSupportedChecker().check(rule, mock(), mock(), sqlStatementContext));
}

@Test
@@ -76,9 +71,8 @@ void assertCheckWhenUpdateMultipleTables() {
updateStatement.setTable(joinTableSegment);
UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement, "foo_db");
Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(false);
when(shardingRule.containsShardingTable(tableNames)).thenReturn(true);
assertThrows(DMLWithMultipleShardingTablesException.class, () -> new ShardingUpdateSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(rule.containsShardingTable(tableNames)).thenReturn(true);
assertThrows(DMLWithMultipleShardingTablesException.class, () -> new ShardingUpdateSupportedChecker().check(rule, mock(), mock(), sqlStatementContext));
}

private UpdateStatement createUpdateStatement() {
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.apache.shardingsphere.infra.merge.engine.merger.impl.TransparentResultMerger;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.merge.dal.ShardingDALResultMerger;
import org.apache.shardingsphere.sharding.merge.ddl.ShardingDDLResultMerger;
@@ -89,7 +88,6 @@ void assertNewInstanceWithSelectStatementForSQLServer() {
private void assertNewInstanceWithSelectStatement(final SelectStatement selectStatement) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setProjections(new ProjectionsSegment(0, 0));
SelectStatementContext sqlStatementContext = new SelectStatementContext(new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()),
Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
@@ -118,7 +116,6 @@ void assertNewInstanceWithOtherStatement() {
private InsertStatementContext createInsertStatementContext(final InsertStatement insertStatement) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
return new InsertStatementContext(new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), insertStatement, "foo_db");
}

Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.apache.shardingsphere.infra.merge.result.impl.transparent.TransparentMergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.connection.cursor.CursorConnectionContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -60,25 +59,21 @@ class ShardingDDLResultMergerTest {

@Test
void assertMergeWithIteratorStreamMergedResult() throws SQLException {
assertThat(merger.merge(Collections.singletonList(createQueryResult()), mock(FetchStatementContext.class), mock(ShardingSphereDatabase.class), mock(ConnectionContext.class)),
instanceOf(IteratorStreamMergedResult.class));
assertThat(merger.merge(Collections.singletonList(createQueryResult()), mock(FetchStatementContext.class), mock(), mock()), instanceOf(IteratorStreamMergedResult.class));
}

@Test
void assertMergeWithTransparentMergedResult() throws SQLException {
assertThat(merger.merge(createQueryResults(), mock(SelectStatementContext.class), mock(ShardingSphereDatabase.class), mock(ConnectionContext.class)),
instanceOf(TransparentMergedResult.class));
assertThat(merger.merge(createQueryResults(), mock(SelectStatementContext.class), mock(), mock()), instanceOf(TransparentMergedResult.class));
}

@Test
void assertMergeWithFetchStreamMergedResult() throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
ConnectionContext connectionContext = mock(ConnectionContext.class);
when(connectionContext.getCursorContext()).thenReturn(new CursorConnectionContext());
assertThat(merger.merge(createQueryResults(), createFetchStatementContext(database), mock(ShardingSphereDatabase.class), connectionContext),
instanceOf(FetchStreamMergedResult.class));
assertThat(merger.merge(createQueryResults(), createFetchStatementContext(database), mock(), connectionContext), instanceOf(FetchStreamMergedResult.class));
}

private FetchStatementContext createFetchStatementContext(final ShardingSphereDatabase database) {

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -124,8 +124,8 @@ private SelectStatementContext createSelectStatementContext() {
selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
return new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
}

private SelectStatementContext createSelectStatementContext(final ShardingSphereDatabase database) {
@@ -137,11 +137,8 @@ private SelectStatementContext createSelectStatementContext(final ShardingSphere
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 3, OrderDirection.DESC, NullsOrderType.FIRST))));
selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
selectStatement.setProjections(projectionsSegment);
return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
}

private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
return new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock());
return new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
}

@Test
@@ -248,8 +245,8 @@ private SelectStatementContext createSelectStatementContextForCountGroupBy() {
selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
return new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
}

private SelectStatementContext createSelectStatementContextForCountGroupByDifferentOrderBy() {
@@ -261,7 +258,7 @@ private SelectStatementContext createSelectStatementContextForCountGroupByDiffer
selectStatement.setProjections(projectionsSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
return new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
return new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
import org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.sql.parser.statement.core.enums.OrderDirection;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.GroupBySegment;
@@ -83,7 +82,6 @@ void assertCompareToForAscWithOrderByItemsForSQLServer() throws SQLException {
private void assertCompareToForAscWithOrderByItems(final SelectStatement selectStatement) throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderType.FIRST),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderType.FIRST))));
@@ -127,7 +125,6 @@ void assertCompareToForDescWithOrderByItemsForSQLServer() throws SQLException {
private void assertCompareToForDescWithOrderByItems(final SelectStatement selectStatement) throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderType.FIRST),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderType.FIRST))));
@@ -171,7 +168,6 @@ void assertCompareToForEqualWithOrderByItemsForSQLServer() throws SQLException {
private void assertCompareToForEqualWithOrderByItems(final SelectStatement selectStatement) throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderType.FIRST),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderType.FIRST))));
@@ -215,7 +211,6 @@ void assertCompareToForAscWithGroupByItemsForSQLServer() throws SQLException {
private void assertCompareToForAscWithGroupByItems(final SelectStatement selectStatement) throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderType.FIRST),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, NullsOrderType.FIRST))));
@@ -257,7 +252,6 @@ void assertCompareToForDecsWithGroupByItemsForSQLServer() throws SQLException {
private void assertCompareToForDescWithGroupByItems(final SelectStatement selectStatement) throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderType.FIRST),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderType.FIRST))));
@@ -303,7 +297,6 @@ void assertCompareToForEqualWithGroupByItemsForSQLServer() throws SQLException {
private void assertCompareToForEqualWithGroupByItems(final SelectStatement selectStatement) throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
selectStatement.setGroupBy(new GroupBySegment(0, 0, Arrays.asList(
new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderType.FIRST),
new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, NullsOrderType.FIRST))));
Original file line number Diff line number Diff line change
@@ -168,7 +168,6 @@ private SelectStatementContext createSelectStatementContext() {
selectStatement.setFrom(tableSegment);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.COUNT, "COUNT(*)"));
projectionsSegment.getProjections().add(new AggregationProjectionSegment(0, 0, AggregationType.AVG, "AVG(num)"));
Original file line number Diff line number Diff line change
@@ -18,15 +18,11 @@
package org.apache.shardingsphere.sharding.merge.dql.pagination;

import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
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.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger;
@@ -35,7 +31,6 @@
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.limit.NumberLiteralLimitValueSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment;
import org.apache.shardingsphere.sql.parser.statement.sqlserver.dml.SQLServerSelectStatement;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.sql.SQLException;
@@ -50,26 +45,18 @@

class TopAndRowNumberDecoratorMergedResultTest {

private ShardingSphereSchema schema;

@BeforeEach
void setUp() {
schema = mock(ShardingSphereSchema.class);
}

@Test
void assertNextForSkipAll() throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, Long.MAX_VALUE, true), null));
SelectStatementContext selectStatementContext =
new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
SelectStatementContext selectStatementContext = new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "SQLServer"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
MergedResult actual = resultMerger.merge(
Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
assertFalse(actual.next());
}

@@ -78,14 +65,13 @@ void assertNextWithoutOffsetWithRowCount() throws SQLException {
final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, null, new NumberLiteralLimitValueSegment(0, 0, 5L)));
SelectStatementContext selectStatementContext =
new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
SelectStatementContext selectStatementContext = new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
MergedResult actual = resultMerger.merge(
Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
for (int i = 0; i < 5; i++) {
assertTrue(actual.next());
}
@@ -96,15 +82,14 @@ void assertNextWithoutOffsetWithRowCount() throws SQLException {
void assertNextWithOffsetWithoutRowCount() throws SQLException {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2L, true), null));
SelectStatementContext selectStatementContext =
new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
SelectStatementContext selectStatementContext = new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "SQLServer"));
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
MergedResult actual = resultMerger.merge(
Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
for (int i = 0; i < 7; i++) {
assertTrue(actual.next());
}
@@ -116,14 +101,13 @@ void assertNextWithOffsetBoundOpenedFalse() throws SQLException {
final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "SQLServer"));
final ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2L, false), new NumberLiteralLimitValueSegment(0, 0, 4L)));
SelectStatementContext selectStatementContext =
new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
SelectStatementContext selectStatementContext = new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
MergedResult actual = resultMerger.merge(
Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
assertTrue(actual.next());
assertTrue(actual.next());
assertFalse(actual.next());
@@ -134,24 +118,19 @@ void assertNextWithOffsetBoundOpenedTrue() throws SQLException {
final ShardingDQLResultMerger resultMerger = new ShardingDQLResultMerger(TypedSPILoader.getService(DatabaseType.class, "SQLServer"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(schema);
SQLServerSelectStatement sqlStatement = new SQLServerSelectStatement();
sqlStatement.setProjections(new ProjectionsSegment(0, 0));
sqlStatement.setLimit(new LimitSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2L, true), new NumberLiteralLimitValueSegment(0, 0, 4L)));
SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database),
Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
MergedResult actual = resultMerger.merge(Arrays.asList(mockQueryResult(), mockQueryResult(),
mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
SelectStatementContext selectStatementContext = new SelectStatementContext(
new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock()), Collections.emptyList(), sqlStatement, "foo_db", Collections.emptyList());
MergedResult actual = resultMerger.merge(
Arrays.asList(mockQueryResult(), mockQueryResult(), mockQueryResult(), mockQueryResult()), selectStatementContext, mockDatabase(), mock(ConnectionContext.class));
assertTrue(actual.next());
assertTrue(actual.next());
assertTrue(actual.next());
assertFalse(actual.next());
}

private ShardingSphereMetaData createShardingSphereMetaData(final ShardingSphereDatabase database) {
return new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
}

private QueryResult mockQueryResult() throws SQLException {
QueryResult result = mock(QueryResult.class, RETURNS_DEEP_STUBS);
when(result.next()).thenReturn(true, true, false);
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
@@ -93,7 +92,6 @@ void assertCheckWhenInsertWithSingleRouting() {

private InsertStatementContext createInsertStatementContext(final List<Object> params, final InsertStatement insertStatement) {
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), mock());
return new InsertStatementContext(metaData, params, insertStatement, "foo_db");
}
@@ -118,7 +116,6 @@ void assertCheckWhenInsertWithRoutingToSingleDataNode() {
@Test
void assertCheckWhenInsertWithRoutingToMultipleDataNodes() {
SQLStatementContext sqlStatementContext = createInsertStatementContext(Collections.singletonList(1), createInsertStatement());
when(routeContext.isSingleRouting()).thenReturn(false);
when(routeContext.getOriginalDataNodes()).thenReturn(getMultipleRouteDataNodes());
when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
assertThrows(DuplicateInsertDataRecordException.class, () -> new ShardingInsertRouteContextChecker(shardingConditions).check(shardingRule, queryContext, database, mock(), routeContext));
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
@@ -105,7 +104,6 @@ class ShardingRouteEngineFactoryTest {
@BeforeEach
void setUp() {
when(((TableAvailable) sqlStatementContext).getTablesContext()).thenReturn(tablesContext);
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
tableNames = new ArrayList<>();
when(tablesContext.getTableNames()).thenReturn(tableNames);
}
@@ -131,8 +129,7 @@ void assertNewInstanceForDALWithTables() {
DALStatement dalStatement = mock(DALStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
assertThat(actual, instanceOf(ShardingUnicastRouteEngine.class));
}

@@ -165,8 +162,7 @@ private void assertNewInstanceForDCLForSingleTable(final GrantStatement grantSta
grantStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))));
GrantStatementContext sqlStatementContext = new GrantStatementContext(grantStatement, "foo_db");
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.singletonList("tbl"), props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.singletonList("tbl"), props);
assertThat(actual, instanceOf(ShardingTableBroadcastRouteEngine.class));
}

@@ -175,8 +171,7 @@ void assertNewInstanceForDCLForNoSingleTable() {
DCLStatement dclStatement = mock(DCLStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(dclStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
assertThat(actual, instanceOf(ShardingInstanceBroadcastRouteEngine.class));
}

@@ -195,8 +190,7 @@ void assertNewInstanceForSelectBroadcastTable() {
SQLStatement sqlStatement = mock(MySQLSelectStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
assertThat(actual, instanceOf(ShardingUnicastRouteEngine.class));
}

@@ -205,8 +199,7 @@ void assertNewInstanceForAlwaysFalse() {
SQLStatement sqlStatement = mock(SQLStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
assertThat(actual, instanceOf(ShardingUnicastRouteEngine.class));
}

@@ -218,8 +211,7 @@ void assertNewInstanceForStandard() {
when(shardingRule.getShardingLogicTableNames(((TableAvailable) sqlStatementContext).getTablesContext().getTableNames())).thenReturn(tableNames);
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
assertThat(actual, instanceOf(ShardingStandardRouteEngine.class));
}

@@ -231,8 +223,7 @@ void assertNewInstanceForComplex() {
tableNames.add("2");
when(shardingRule.getShardingLogicTableNames(tableNames)).thenReturn(tableNames);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
assertThat(actual, instanceOf(ShardingComplexRouteEngine.class));
}

@@ -243,8 +234,7 @@ void assertNewInstanceForShowCreateTableWithTableRule() {
tableNames.add("table_1");
when(shardingRule.getShardingLogicTableNames(tableNames)).thenReturn(tableNames);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
assertThat(actual, instanceOf(ShardingUnicastRouteEngine.class));
}

@@ -255,8 +245,7 @@ void assertNewInstanceForShowColumnsWithTableRule() {
tableNames.add("table_1");
when(shardingRule.getShardingLogicTableNames(tableNames)).thenReturn(tableNames);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
assertThat(actual, instanceOf(ShardingUnicastRouteEngine.class));
}

@@ -282,8 +271,7 @@ void assertNewInstanceForOptimizeTableWithShardingTable() {
tableNames.add("table_1");
when(shardingRule.getShardingLogicTableNames(tableNames)).thenReturn(tableNames);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
assertThat(actual, instanceOf(ShardingTableBroadcastRouteEngine.class));
}

@@ -300,8 +288,7 @@ void assertNewInstanceForCursorStatementWithShardingTable() {
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true);
when(shardingRule.getShardingLogicTableNames(tableNames)).thenReturn(tableNames);
QueryContext queryContext = new QueryContext(cursorStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
assertThat(actual, instanceOf(ShardingStandardRouteEngine.class));
}

@@ -314,8 +301,7 @@ void assertNewInstanceForCursorStatementWithSingleTable() {
when(cursorStatementContext.getTablesContext().getSimpleTables()).thenReturn(tableSegments);
when(cursorStatementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
QueryContext queryContext = new QueryContext(cursorStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, Collections.emptyList(), props);
assertThat(actual, instanceOf(ShardingIgnoreRouteEngine.class));
}

Original file line number Diff line number Diff line change
@@ -80,8 +80,7 @@ void assertInstanceCreatedWhenNoExceptionThrown() {
void assertFindTableNameWhenSingleTable() {
SimpleTableSegment tableSegment = createTableSegment("table_1", "tbl_1");
ColumnSegment columnSegment = createColumnSegment(null, "col");
Map<String, String> actual = new TablesContext(Collections.singletonList(tableSegment), databaseType, "foo_db")
.findTableNames(Collections.singletonList(columnSegment), mock(ShardingSphereSchema.class));
Map<String, String> actual = new TablesContext(Collections.singletonList(tableSegment), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock());
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
}
@@ -91,8 +90,7 @@ void assertFindTableNameWhenColumnSegmentOwnerPresent() {
SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
ColumnSegment columnSegment = createColumnSegment("table_1", "col");
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db")
.findTableNames(Collections.singletonList(columnSegment), mock(ShardingSphereSchema.class));
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock());
assertFalse(actual.isEmpty());
assertThat(actual.get("table_1.col"), is("table_1"));
}
@@ -102,8 +100,7 @@ void assertFindTableNameWhenColumnSegmentOwnerAbsent() {
SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
ColumnSegment columnSegment = createColumnSegment(null, "col");
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db")
.findTableNames(Collections.singletonList(columnSegment), mock(ShardingSphereSchema.class));
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock());
assertTrue(actual.isEmpty());
}

@@ -114,8 +111,7 @@ void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsCol
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.getAllColumnNames("table_1")).thenReturn(Collections.singletonList("col"));
ColumnSegment columnSegment = createColumnSegment(null, "col");
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2),
databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema);
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
}
@@ -128,8 +124,7 @@ void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsCol
Collections.singletonList(new ShardingSphereColumn("COL", 0, false, false, true, true, false, false)), Collections.emptyList(), Collections.emptyList());
ShardingSphereSchema schema = new ShardingSphereSchema("foo_db", Collections.singleton(table), Collections.emptyList());
ColumnSegment columnSegment = createColumnSegment(null, "COL");
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2),
databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema);
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("TABLE_1"));
}
@@ -177,8 +172,7 @@ void assertGetSchemaNameWithDifferentSchemaAndSameTable() {
tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1");
tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2")));
assertThrows(IllegalStateException.class,
() -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName());
assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName());
}

@Test
@@ -187,8 +181,7 @@ void assertGetSchemaNameWithDifferentSchemaAndDifferentTable() {
tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2")));
assertThrows(IllegalStateException.class,
() -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName());
assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName());
}

@Test
Original file line number Diff line number Diff line change
@@ -23,8 +23,6 @@
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.DataSourceBroadcastRouteEngine;
import org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.InstanceBroadcastRouteEngine;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
@@ -43,14 +41,12 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

@@ -64,9 +60,6 @@
@MockitoSettings(strictness = Strictness.LENIENT)
class TablelessRouteEngineFactoryTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;

@Mock(extraInterfaces = TableAvailable.class)
private SQLStatementContext sqlStatementContext;

@@ -76,9 +69,7 @@ class TablelessRouteEngineFactoryTest {
@BeforeEach
void setUp() {
when(((TableAvailable) sqlStatementContext).getTablesContext()).thenReturn(tablesContext);
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
Collection<String> tableNames = new ArrayList<>();
when(tablesContext.getTableNames()).thenReturn(tableNames);
when(tablesContext.getTableNames()).thenReturn(new ArrayList<>());
}

private ConnectionContext mockConnectionContext() {
Original file line number Diff line number Diff line change
@@ -30,6 +30,10 @@
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDropSchemaStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;

@@ -38,33 +42,33 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class SingleDropSchemaSupportedCheckerTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private SingleRule rule;

@Test
void assertCheckWithoutCascadeSchema() {
assertThrows(DropNotEmptySchemaException.class,
() -> new SingleDropSchemaSupportedChecker().check(mock(SingleRule.class, RETURNS_DEEP_STUBS), mockDatabase(), mock(ShardingSphereSchema.class),
createSQLStatementContext("foo_schema", false)));
assertThrows(DropNotEmptySchemaException.class, () -> new SingleDropSchemaSupportedChecker().check(rule, mockDatabase(), mock(), createSQLStatementContext("foo_schema", false)));
}

@Test
void assertCheckWithNotExistedSchema() {
ShardingSphereDatabase database = mockDatabase();
when(database.getSchema("not_existed_schema")).thenReturn(null);
assertThrows(SchemaNotFoundException.class,
() -> new SingleDropSchemaSupportedChecker().check(mock(SingleRule.class, RETURNS_DEEP_STUBS), database, mock(ShardingSphereSchema.class),
createSQLStatementContext("not_existed_schema", true)));
assertThrows(SchemaNotFoundException.class, () -> new SingleDropSchemaSupportedChecker().check(rule, database, mock(), createSQLStatementContext("not_existed_schema", true)));
}

@Test
void assertCheck() {
new SingleDropSchemaSupportedChecker().check(mock(SingleRule.class, RETURNS_DEEP_STUBS), mockDatabase(), mock(ShardingSphereSchema.class), createSQLStatementContext("foo_schema", true));
new SingleDropSchemaSupportedChecker().check(rule, mockDatabase(), mock(), createSQLStatementContext("foo_schema", true));
}

private ShardingSphereDatabase mockDatabase() {
ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema");
schema.putTable(new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE));
ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
Collections.singleton(new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE)), Collections.emptyList());
when(result.getAllSchemas()).thenReturn(Collections.singleton(schema));
return result;
}
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@
import org.apache.shardingsphere.single.rule.SingleRule;
import org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLDropTableStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;

@@ -35,24 +39,26 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class SingleDropTableSupportedCheckerTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private SingleRule rule;

@Test
void assertCheckWithCascade() {
assertThrows(UnsupportedDropCascadeTableException.class,
() -> new SingleDropTableSupportedChecker().check(mock(SingleRule.class, RETURNS_DEEP_STUBS), mockDatabase(), mock(ShardingSphereSchema.class),
createSQLStatementContext(true)));
assertThrows(UnsupportedDropCascadeTableException.class, () -> new SingleDropTableSupportedChecker().check(rule, mockDatabase(), mock(), createSQLStatementContext(true)));
}

@Test
void assertCheckWithoutCascade() {
new SingleDropTableSupportedChecker().check(mock(SingleRule.class, RETURNS_DEEP_STUBS), mockDatabase(), mock(ShardingSphereSchema.class), createSQLStatementContext(false));
new SingleDropTableSupportedChecker().check(rule, mockDatabase(), mock(), createSQLStatementContext(false));
}

private ShardingSphereDatabase mockDatabase() {
ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema");
schema.putTable(new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE));
ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
Collections.singleton(new ShardingSphereTable("foo_tbl", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TableType.TABLE)), Collections.emptyList());
when(result.getAllSchemas()).thenReturn(Collections.singleton(schema));
return result;
}
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -118,7 +117,6 @@ private SelectStatementContext createStatementContext() {
private ShardingSphereDatabase createDatabase() {
ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(result.getName()).thenReturn("foo_db");
when(result.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -118,10 +118,8 @@ void assertAlterSchemaWithEmptyAlteredSchema() {
void assertAlterSchemaWithNotEmptyAlteredSchema() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.isEmpty()).thenReturn(true);
when(database.getSchema("foo_schema")).thenReturn(schema);
when(database.getSchema("bar_schema")).thenReturn(schema);
when(database.getSchema("foo_schema")).thenReturn(new ShardingSphereSchema("foo_schema"));
when(database.getSchema("bar_schema")).thenReturn(new ShardingSphereSchema("bar_schema"));
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(), mock(), new ConfigurationProperties(new Properties()));
when(metaDataContextManager.getMetaDataContexts().get().getMetaData()).thenReturn(metaData);
DatabaseMetaDataPersistFacade databaseMetaDataFacade = mock(DatabaseMetaDataPersistFacade.class, RETURNS_DEEP_STUBS);
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@
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.route.context.RouteContext;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
@@ -271,7 +270,6 @@ private InsertStatementContext createMySQLInsertStatementContext() {
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
return new InsertStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, "foo_db");
}

@@ -286,7 +284,6 @@ private InsertStatementContext createPostgreSQLInsertStatementContext() {
sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order"))));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getName()).thenReturn("foo_db");
when(database.getSchema("public")).thenReturn(mock(ShardingSphereSchema.class));
return new InsertStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), sqlStatement, "foo_db");
}
}
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@
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.rule.attribute.datasource.DataSourceMapperRuleAttribute;
import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -143,8 +142,6 @@ private ContextManager mockContextManager(final String databaseName) {
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class);
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(database.getSchema("foo_db")).thenReturn(schema);
StorageUnit storageUnit = mock(StorageUnit.class);
DataSource dataSource = new MockedDataSource();
when(storageUnit.getDataSource()).thenReturn(dataSource);

0 comments on commit ca0a205

Please sign in to comment.