From 95c995fb08ff501ef6b3499822c03f912d8f4734 Mon Sep 17 00:00:00 2001 From: Zhengqiang Duan Date: Sat, 30 Nov 2024 20:54:40 +0800 Subject: [PATCH] Fix sonar issue in ShardingSupportedCheckerTest and ShardingRouteContextTest (#33852) * Fix sonar issue in ShardingSupportedCheckerTest and ShardingRouteContextTest * fix checkstyle --- .../ddl/ShardingCreateFunctionSupportedCheckerTest.java | 5 ++++- .../ddl/ShardingCreateProcedureSupportedCheckerTest.java | 5 ++++- .../checker/dml/ShardingUpdateRouteContextCheckerTest.java | 7 ------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java index b9f37c318a8fe..4e1a0c0938536 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java @@ -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; @@ -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 diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java index 7609bad70a1dc..ed9f383cb553f 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java @@ -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; @@ -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 diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java index 4503322886cf7..75b7c524dc131 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java @@ -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();