diff --git a/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutorTest.java b/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutorTest.java index 18654d8f91780..3cc97457272be 100644 --- a/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutorTest.java +++ b/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutorTest.java @@ -62,7 +62,7 @@ void assertUpdateCurrentRuleConfiguration() { when(rule.getConfiguration()).thenReturn(config); executor.setRule(rule); DropBroadcastTableRuleStatement sqlStatement = new DropBroadcastTableRuleStatement(false, Collections.singleton("t_address")); - BroadcastRuleConfiguration toBeDroppedConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); - assertTrue(toBeDroppedConfig.getTables().isEmpty()); + BroadcastRuleConfiguration toBeAlteredConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); + assertTrue(toBeAlteredConfig.getTables().isEmpty()); } } diff --git a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java index ced48cfdcd018..ce82286d137bd 100644 --- a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java +++ b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java @@ -82,6 +82,9 @@ void assertUpdateCurrentRuleConfigurationWithInUsedEncryptor() { when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); EncryptRuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(createSQLStatement("MD5")); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + assertThat(toBeAlteredRuleConfig.getTables().iterator().next().getName(), is("t_encrypt")); + assertThat(toBeAlteredRuleConfig.getTables().iterator().next().getColumns().iterator().next().getName(), is("user_id")); assertThat(toBeAlteredRuleConfig.getEncryptors().size(), is(3)); } diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java index 07f1dfe0082a0..fdf00affbeb93 100644 --- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java +++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutorTest.java @@ -90,6 +90,9 @@ void assertUpdate() { when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); MaskRuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + assertThat(toBeAlteredRuleConfig.getTables().iterator().next().getName(), is("t_order")); + assertThat(toBeAlteredRuleConfig.getTables().iterator().next().getColumns().iterator().next().getLogicColumn(), is("order_id")); assertThat(toBeAlteredRuleConfig.getMaskAlgorithms().size(), is(1)); assertTrue(toBeAlteredRuleConfig.getMaskAlgorithms().containsKey("t_order_order_id_md5")); } diff --git a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java index 7c62e04a4a319..ee8d001d73a4a 100644 --- a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java +++ b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutorTest.java @@ -63,8 +63,8 @@ void assertUpdateCurrentRuleConfiguration() { when(rule.getConfiguration()).thenReturn(ruleConfig); executor.setRule(rule); MaskRuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(createSQLStatement(false, "t_mask")); - assertTrue(toBeDroppedRuleConfig.getMaskAlgorithms().isEmpty()); assertThat(toBeDroppedRuleConfig.getTables().size(), is(1)); + assertTrue(toBeDroppedRuleConfig.getMaskAlgorithms().isEmpty()); } @Test diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java index 2c0413c2826a1..5d25783d1178a 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java @@ -157,6 +157,7 @@ void assertUpdateSuccess() { executor.setRule(mock(ReadwriteSplittingRule.class)); ReadwriteSplittingRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(sqlStatement); assertThat(toBeCreatedRuleConfig.getDataSources().size(), is(1)); + assertThat(toBeCreatedRuleConfig.getLoadBalancers().size(), is(1)); } private CreateReadwriteSplittingRuleStatement createSQLStatement(final String loadBalancerName) { diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java index 7d31dc632255a..3952df05d474e 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java @@ -19,9 +19,9 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.exception.kernel.metadata.rule.RuleDefinitionException; -import org.apache.shardingsphere.infra.exception.kernel.metadata.rule.MissingRequiredRuleException; import org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InUsedRuleException; +import org.apache.shardingsphere.infra.exception.kernel.metadata.rule.MissingRequiredRuleException; +import org.apache.shardingsphere.infra.exception.kernel.metadata.rule.RuleDefinitionException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; @@ -98,6 +98,7 @@ void assertBuildToBeDroppedRuleConfiguration() { when(rule.getConfiguration()).thenReturn(ruleConfig); executor.setRule(rule); ReadwriteSplittingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement()); + assertThat(actual.getDataSources().size(), is(1)); assertThat(actual.getLoadBalancers().size(), is(1)); } @@ -108,6 +109,7 @@ void assertBuildToBeDroppedRuleConfigurationWithInUsedLoadBalancer() { when(rule.getConfiguration()).thenReturn(ruleConfig); executor.setRule(rule); ReadwriteSplittingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement()); + assertThat(actual.getDataSources().size(), is(1)); assertThat(actual.getLoadBalancers().size(), is(0)); } @@ -118,6 +120,7 @@ void assertBuildToBeDroppedRuleConfigurationWithoutLoadBalancerName() { when(rule.getConfiguration()).thenReturn(ruleConfig); executor.setRule(rule); ReadwriteSplittingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement()); + assertThat(actual.getDataSources().size(), is(1)); assertThat(actual.getLoadBalancers().size(), is(1)); } diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java index a17326b5d45ef..29303e4eb8843 100644 --- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java +++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/DropDefaultShadowAlgorithmExecutorTest.java @@ -32,7 +32,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -77,7 +76,7 @@ void assertUpdate() { DropDefaultShadowAlgorithmStatement sqlStatement = new DropDefaultShadowAlgorithmStatement(false); assertTrue(executor.hasAnyOneToBeDropped(sqlStatement)); ShadowRuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(sqlStatement); - assertFalse(toBeDroppedRuleConfig.getDefaultShadowAlgorithmName().isEmpty()); + assertThat(toBeDroppedRuleConfig.getDefaultShadowAlgorithmName(), is("default")); assertThat(toBeDroppedRuleConfig.getShadowAlgorithms().size(), is(1)); } } diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java index 4d325b0407074..b8edac4b60d88 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableReferenceRuleExecutorTest.java @@ -65,10 +65,10 @@ void assertCheckWithNotExistedTables() { @Test void assertBuildToBeAlteredRuleConfiguration() { - ShardingRuleConfiguration actual = executor.buildToBeAlteredRuleConfiguration(createSQLStatement("reference_0", "t_3,t_4")); - assertThat(actual.getBindingTableGroups().size(), is(1)); - assertThat(actual.getBindingTableGroups().iterator().next().getName(), is("reference_0")); - assertThat(actual.getBindingTableGroups().iterator().next().getReference(), is("t_3,t_4")); + ShardingRuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(createSQLStatement("reference_0", "t_3,t_4")); + assertThat(toBeAlteredRuleConfig.getBindingTableGroups().size(), is(1)); + assertThat(toBeAlteredRuleConfig.getBindingTableGroups().iterator().next().getName(), is("reference_0")); + assertThat(toBeAlteredRuleConfig.getBindingTableGroups().iterator().next().getReference(), is("t_3,t_4")); } private AlterShardingTableReferenceRuleStatement createSQLStatement(final String name, final String reference) { diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleExecutorTest.java index 95cacc949d0a9..47714e66b55fc 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleExecutorTest.java @@ -78,9 +78,9 @@ void assertUpdate() { when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); executor.checkBeforeUpdate(sqlStatement); - ShardingRuleConfiguration actual = executor.buildToBeAlteredRuleConfiguration(sqlStatement); - assertThat(actual.getTables().size(), is(1)); - ShardingTableRuleConfiguration tableRule = actual.getTables().iterator().next(); + ShardingRuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + ShardingTableRuleConfiguration tableRule = toBeAlteredRuleConfig.getTables().iterator().next(); assertThat(tableRule.getLogicTable(), is("t_order")); assertThat(tableRule.getActualDataNodes(), is("ds_${0..1}.t_order${0..1}")); assertThat(tableRule.getTableShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class)); @@ -88,8 +88,8 @@ void assertUpdate() { assertThat(tableRule.getTableShardingStrategy().getShardingAlgorithmName(), is("t_order_table_core.standard.fixture")); assertThat(tableRule.getDatabaseShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class)); assertThat(tableRule.getDatabaseShardingStrategy().getShardingAlgorithmName(), is("t_order_database_inline")); - assertThat(actual.getTables().size(), is(1)); - ShardingAutoTableRuleConfiguration autoTableRule = actual.getAutoTables().iterator().next(); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + ShardingAutoTableRuleConfiguration autoTableRule = toBeAlteredRuleConfig.getAutoTables().iterator().next(); assertThat(autoTableRule.getLogicTable(), is("t_order_item")); assertThat(autoTableRule.getActualDataSources(), is("ds_0,ds_1")); assertThat(autoTableRule.getShardingStrategy().getShardingAlgorithmName(), is("t_order_item_foo.distsql.fixture")); @@ -105,9 +105,9 @@ void assertUpdateWithDifferentCase() { when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); executor.checkBeforeUpdate(sqlStatement); - ShardingRuleConfiguration actual = executor.buildToBeAlteredRuleConfiguration(sqlStatement); - assertThat(actual.getTables().size(), is(1)); - ShardingTableRuleConfiguration tableRule = actual.getTables().iterator().next(); + ShardingRuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + ShardingTableRuleConfiguration tableRule = toBeAlteredRuleConfig.getTables().iterator().next(); assertThat(tableRule.getLogicTable(), is("T_ORDER")); assertThat(tableRule.getActualDataNodes(), is("ds_${0..1}.t_order${0..1}")); assertThat(tableRule.getTableShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class)); @@ -115,8 +115,8 @@ void assertUpdateWithDifferentCase() { assertThat(tableRule.getTableShardingStrategy().getShardingAlgorithmName(), is("t_order_table_core.standard.fixture")); assertThat(tableRule.getDatabaseShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class)); assertThat(tableRule.getDatabaseShardingStrategy().getShardingAlgorithmName(), is("t_order_database_inline")); - assertThat(actual.getTables().size(), is(1)); - ShardingAutoTableRuleConfiguration autoTableRule = actual.getAutoTables().iterator().next(); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + ShardingAutoTableRuleConfiguration autoTableRule = toBeAlteredRuleConfig.getAutoTables().iterator().next(); assertThat(autoTableRule.getLogicTable(), is("T_ORDER_ITEM")); assertThat(autoTableRule.getActualDataSources(), is("ds_0,ds_1")); assertThat(autoTableRule.getShardingStrategy().getShardingAlgorithmName(), is("t_order_item_foo.distsql.fixture")); @@ -132,9 +132,9 @@ void assertUpdateTableType() { when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); executor.checkBeforeUpdate(sqlStatement); - ShardingRuleConfiguration actual = executor.buildToBeAlteredRuleConfiguration(sqlStatement); - assertThat(actual.getTables().size(), is(1)); - ShardingTableRuleConfiguration tableRule = actual.getTables().iterator().next(); + ShardingRuleConfiguration toBeAlteredRuleConfig = executor.buildToBeAlteredRuleConfiguration(sqlStatement); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + ShardingTableRuleConfiguration tableRule = toBeAlteredRuleConfig.getTables().iterator().next(); assertThat(tableRule.getLogicTable(), is("t_order_item")); assertThat(tableRule.getActualDataNodes(), is("ds_${0..1}.t_order${0..1}")); assertThat(tableRule.getTableShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class)); @@ -142,8 +142,8 @@ void assertUpdateTableType() { assertThat(tableRule.getTableShardingStrategy().getShardingAlgorithmName(), is("t_order_item_table_core.standard.fixture")); assertThat(tableRule.getDatabaseShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class)); assertThat(tableRule.getDatabaseShardingStrategy().getShardingAlgorithmName(), is("t_order_item_database_inline")); - assertThat(actual.getTables().size(), is(1)); - ShardingAutoTableRuleConfiguration autoTableRule = actual.getAutoTables().iterator().next(); + assertThat(toBeAlteredRuleConfig.getTables().size(), is(1)); + ShardingAutoTableRuleConfiguration autoTableRule = toBeAlteredRuleConfig.getAutoTables().iterator().next(); assertThat(autoTableRule.getLogicTable(), is("t_order")); assertThat(autoTableRule.getActualDataSources(), is("ds_0,ds_1")); assertThat(autoTableRule.getShardingStrategy().getShardingAlgorithmName(), is("t_order_foo.distsql.fixture")); diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyExecutorTest.java index be20d49a0e5e7..0d00c973a37a5 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateDefaultShardingStrategyExecutorTest.java @@ -104,8 +104,8 @@ void assertCreateDefaultTableShardingStrategy() { AlgorithmSegment algorithm = new AlgorithmSegment("order_id_algorithm", new Properties()); CreateDefaultShardingStrategyStatement sqlStatement = new CreateDefaultShardingStrategyStatement(false, "TABLE", "standard", "order_id", algorithm); executor.checkBeforeUpdate(sqlStatement); - ShardingRuleConfiguration actual = executor.buildToBeCreatedRuleConfiguration(sqlStatement); - StandardShardingStrategyConfiguration defaultTableShardingStrategy = (StandardShardingStrategyConfiguration) actual.getDefaultTableShardingStrategy(); + ShardingRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(sqlStatement); + StandardShardingStrategyConfiguration defaultTableShardingStrategy = (StandardShardingStrategyConfiguration) toBeCreatedRuleConfig.getDefaultTableShardingStrategy(); assertThat(defaultTableShardingStrategy.getShardingAlgorithmName(), is("default_table_order_id_algorithm")); assertThat(defaultTableShardingStrategy.getShardingColumn(), is("order_id")); } @@ -119,8 +119,8 @@ void assertCreateDefaultDatabaseShardingStrategy() { when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); executor.checkBeforeUpdate(statement); - ShardingRuleConfiguration actual = executor.buildToBeCreatedRuleConfiguration(statement); - StandardShardingStrategyConfiguration defaultDatabaseShardingStrategy = (StandardShardingStrategyConfiguration) actual.getDefaultDatabaseShardingStrategy(); + ShardingRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(statement); + StandardShardingStrategyConfiguration defaultDatabaseShardingStrategy = (StandardShardingStrategyConfiguration) toBeCreatedRuleConfig.getDefaultDatabaseShardingStrategy(); assertThat(defaultDatabaseShardingStrategy.getShardingAlgorithmName(), is("default_database_inline")); assertThat(defaultDatabaseShardingStrategy.getShardingColumn(), is("user_id")); } @@ -139,8 +139,8 @@ void assertCreateDefaultTableShardingStrategyWithIfNotExists() { algorithm = new AlgorithmSegment("user_id_algorithm", new Properties()); CreateDefaultShardingStrategyStatement statementWithIfNotExists = new CreateDefaultShardingStrategyStatement(true, "TABLE", "standard", "order_id", algorithm); executor.checkBeforeUpdate(statementWithIfNotExists); - ShardingRuleConfiguration actual = executor.buildToBeCreatedRuleConfiguration(statementWithIfNotExists); - StandardShardingStrategyConfiguration defaultTableShardingStrategy = (StandardShardingStrategyConfiguration) actual.getDefaultTableShardingStrategy(); + ShardingRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(statementWithIfNotExists); + StandardShardingStrategyConfiguration defaultTableShardingStrategy = (StandardShardingStrategyConfiguration) toBeCreatedRuleConfig.getDefaultTableShardingStrategy(); assertThat(defaultTableShardingStrategy.getShardingAlgorithmName(), is("default_table_user_id_algorithm")); assertThat(defaultTableShardingStrategy.getShardingColumn(), is("order_id")); } @@ -155,8 +155,8 @@ void assertCreateDefaultTableShardingStrategyWithNoneShardingStrategyType() { executor.setRule(rule); CreateDefaultShardingStrategyStatement sqlStatement = new CreateDefaultShardingStrategyStatement(false, "TABLE", "none", null, null); executor.checkBeforeUpdate(sqlStatement); - ShardingRuleConfiguration actual = executor.buildToBeCreatedRuleConfiguration(sqlStatement); - NoneShardingStrategyConfiguration defaultTableShardingStrategy = (NoneShardingStrategyConfiguration) actual.getDefaultTableShardingStrategy(); + ShardingRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(sqlStatement); + NoneShardingStrategyConfiguration defaultTableShardingStrategy = (NoneShardingStrategyConfiguration) toBeCreatedRuleConfig.getDefaultTableShardingStrategy(); assertThat(defaultTableShardingStrategy.getType(), is("")); assertThat(defaultTableShardingStrategy.getShardingAlgorithmName(), is("")); } @@ -169,8 +169,8 @@ void assertCreateDefaultDatabaseShardingStrategyWithNoneShardingStrategyType() { when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); executor.checkBeforeUpdate(sqlStatement); - ShardingRuleConfiguration actual = executor.buildToBeCreatedRuleConfiguration(sqlStatement); - NoneShardingStrategyConfiguration defaultDatabaseShardingStrategy = (NoneShardingStrategyConfiguration) actual.getDefaultDatabaseShardingStrategy(); + ShardingRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(sqlStatement); + NoneShardingStrategyConfiguration defaultDatabaseShardingStrategy = (NoneShardingStrategyConfiguration) toBeCreatedRuleConfig.getDefaultDatabaseShardingStrategy(); assertThat(defaultDatabaseShardingStrategy.getType(), is("")); assertThat(defaultDatabaseShardingStrategy.getShardingAlgorithmName(), is("")); } diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableReferenceRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableReferenceRuleExecutorTest.java index f242db604eb21..f547a87685f73 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableReferenceRuleExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableReferenceRuleExecutorTest.java @@ -79,8 +79,8 @@ void assertUpdateWithIfNotExists() { when(rule.getConfiguration()).thenReturn(currentRuleConfig); executor.setRule(rule); executor.checkBeforeUpdate(sqlStatement); - ShardingRuleConfiguration actual = executor.buildToBeCreatedRuleConfiguration(sqlStatement); - Collection referenceRuleConfigs = actual.getBindingTableGroups(); + ShardingRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(sqlStatement); + Collection referenceRuleConfigs = toBeCreatedRuleConfig.getBindingTableGroups(); assertThat(referenceRuleConfigs.size(), is(0)); } diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyExecutorTest.java index 6df548ef087ca..627de111c10ef 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropDefaultShardingStrategyExecutorTest.java @@ -83,9 +83,9 @@ void assertBuildToBeDroppedRuleConfigurationWithInUsedAlgorithm() { ShardingRule rule = mock(ShardingRule.class); when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); - ShardingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("Table")); - assertNull(actual.getDefaultTableShardingStrategy()); - assertThat(actual.getShardingAlgorithms().size(), is(0)); + ShardingRuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("Table")); + assertNull(toBeDroppedRuleConfig.getDefaultTableShardingStrategy()); + assertThat(toBeDroppedRuleConfig.getShardingAlgorithms().size(), is(0)); } @Test @@ -93,10 +93,10 @@ void assertUpdateMultipleStrategies() { ShardingRule rule = mock(ShardingRule.class); when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); - ShardingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("Database")); - assertNull(actual.getDefaultTableShardingStrategy()); - actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("Table")); - assertThat(actual.getShardingAlgorithms().size(), is(1)); + ShardingRuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("Database")); + assertNull(toBeDroppedRuleConfig.getDefaultTableShardingStrategy()); + toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("Table")); + assertThat(toBeDroppedRuleConfig.getShardingAlgorithms().size(), is(1)); } private DropDefaultShardingStrategyStatement createSQLStatement(final String defaultType) { diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java index a87f83680b0ce..2eea655c71b30 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/DropShardingTableRuleExecutorTest.java @@ -91,9 +91,12 @@ void assertUpdate() { ShardingRule rule = mock(ShardingRule.class); when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); - ShardingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("t_order")); - assertTrue(getShardingTables(actual).contains("t_order")); - assertFalse(getBindingTables(actual).contains("t_order_item")); + ShardingRuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("t_order")); + assertTrue(getShardingTables(toBeDroppedRuleConfig).contains("t_order")); + assertFalse(getBindingTables(toBeDroppedRuleConfig).contains("t_order_item")); + assertThat(toBeDroppedRuleConfig.getShardingAlgorithms().size(), is(2)); + assertThat(toBeDroppedRuleConfig.getKeyGenerators().size(), is(1)); + assertThat(toBeDroppedRuleConfig.getAuditors().size(), is(1)); } @Test @@ -101,9 +104,12 @@ void assertUpdateWithDifferentCase() { ShardingRule rule = mock(ShardingRule.class); when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); - ShardingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("T_ORDER")); - assertTrue(getShardingTables(actual).contains("t_order")); - assertFalse(getBindingTables(actual).contains("t_order_item")); + ShardingRuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(createSQLStatement("T_ORDER")); + assertTrue(getShardingTables(toBeDroppedRuleConfig).contains("t_order")); + assertFalse(getBindingTables(toBeDroppedRuleConfig).contains("t_order_item")); + assertThat(toBeDroppedRuleConfig.getShardingAlgorithms().size(), is(2)); + assertThat(toBeDroppedRuleConfig.getKeyGenerators().size(), is(1)); + assertThat(toBeDroppedRuleConfig.getAuditors().size(), is(1)); } @Test @@ -112,12 +118,12 @@ void assertDropRuleAndUnusedAlgorithm() { when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); executor.setRule(rule); DropShardingTableRuleStatement sqlStatement = createSQLStatement("t_order"); - ShardingRuleConfiguration actual = executor.buildToBeDroppedRuleConfiguration(sqlStatement); - assertTrue(getShardingTables(actual).contains("t_order")); - assertFalse(getBindingTables(actual).contains("t_order_item")); - assertThat(actual.getShardingAlgorithms().size(), is(2)); - assertThat(actual.getKeyGenerators().size(), is(1)); - assertThat(actual.getAuditors().size(), is(1)); + ShardingRuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(sqlStatement); + assertTrue(getShardingTables(toBeDroppedRuleConfig).contains("t_order")); + assertFalse(getBindingTables(toBeDroppedRuleConfig).contains("t_order_item")); + assertThat(toBeDroppedRuleConfig.getShardingAlgorithms().size(), is(2)); + assertThat(toBeDroppedRuleConfig.getKeyGenerators().size(), is(1)); + assertThat(toBeDroppedRuleConfig.getAuditors().size(), is(1)); } private DropShardingTableRuleStatement createSQLStatement(final String tableName) { diff --git a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutorTest.java b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutorTest.java index 40ff1f7be11ca..74f4bbdd7410b 100644 --- a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutorTest.java +++ b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutorTest.java @@ -56,13 +56,24 @@ void assertBuild() { assertThat(toBeCreatedRuleConfig.getDefaultDataSource().get(), is("foo_ds")); } + @Test + void assertUpdate() { + SingleRuleConfiguration currentConfig = new SingleRuleConfiguration(); + SingleRule rule = mock(SingleRule.class); + when(rule.getConfiguration()).thenReturn(currentConfig); + executor.setRule(rule); + SingleRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(new SetDefaultSingleTableStorageUnitStatement("foo_ds")); + assertTrue(toBeCreatedRuleConfig.getDefaultDataSource().isPresent()); + assertThat(toBeCreatedRuleConfig.getDefaultDataSource().get(), is("foo_ds")); + } + @Test void assertRandom() { SingleRuleConfiguration currentConfig = new SingleRuleConfiguration(); SingleRule rule = mock(SingleRule.class); when(rule.getConfiguration()).thenReturn(currentConfig); executor.setRule(rule); - executor.buildToBeCreatedRuleConfiguration(new SetDefaultSingleTableStorageUnitStatement(null)); - assertFalse(currentConfig.getDefaultDataSource().isPresent()); + SingleRuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(new SetDefaultSingleTableStorageUnitStatement(null)); + assertFalse(toBeCreatedRuleConfig.getDefaultDataSource().isPresent()); } }