Skip to content

Commit

Permalink
Fix sonar issue in ShardingSupportedCheckerTest and ShardingRouteCont…
Browse files Browse the repository at this point in the history
…extTest (#33852)

* Fix sonar issue in ShardingSupportedCheckerTest and ShardingRouteContextTest

* fix checkstyle
  • Loading branch information
strongduanmu authored Nov 30, 2024
1 parent b023933 commit 95c995f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
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.routine.RoutineBodySegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.routine.ValidStatementSegment;
Expand Down Expand Up @@ -83,7 +84,9 @@ void assertCheckCreateFunctionWithShardingTableForMySQL() {
sqlStatement.setRoutineBody(routineBody);
CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, DefaultDatabase.LOGIC_NAME);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
assertThrows(NoSuchTableException.class, () -> new ShardingCreateFunctionSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(shardingRule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingCreateFunctionSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
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.routine.RoutineBodySegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.routine.ValidStatementSegment;
Expand Down Expand Up @@ -84,7 +85,9 @@ void assertCheckWithShardingTableForMySQL() {
sqlStatement.setRoutineBody(routineBody);
CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, DefaultDatabase.LOGIC_NAME);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
assertThrows(NoSuchTableException.class, () -> new ShardingCreateProcedureSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
when(shardingRule.isShardingTable("t_order")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class,
() -> new ShardingCreateProcedureSupportedChecker().check(shardingRule, database, mock(ShardingSphereSchema.class), sqlStatementContext));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ void assertCheckWhenUpdateShardingColumnWithSameRouteContext() {
assertDoesNotThrow(() -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), createSingleRouteContext()));
}

@Test
void assertCheckWhenTableNameIsBroadcastTable() {
mockShardingRuleForUpdateShardingColumn();
when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement(), DefaultDatabase.LOGIC_NAME));
assertDoesNotThrow(() -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), createSingleRouteContext()));
}

@Test
void assertCheckWhenUpdateShardingColumnWithDifferentRouteContext() {
mockShardingRuleForUpdateShardingColumn();
Expand Down

0 comments on commit 95c995f

Please sign in to comment.