sandynz commented on code in PR #25860:
URL: https://github.com/apache/shardingsphere/pull/25860#discussion_r1202242176


##########
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/UnusedAlgorithmFinderTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.update;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.update.UnusedAlgorithmFinder;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class UnusedAlgorithmFinderTest {
+    
+    private static final String USED_TABLE_SHARDING_ALGORITHM = 
"used_table_sharding_algorithm";
+    
+    private static final String USED_TABLE_SHARDING_DEFAULT_ALGORITHM = 
"used_table_sharding_default_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_ALGORITHM = 
"used_database_sharding_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_DEFAULT_ALGORITHM = 
"used_database_sharding_default_algorithm";
+    
+    private static final String UNUSED_ALGORITHM = "unused_algorithm";
+    
+    @Test
+    void assertFind() {
+        ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+        

Review Comment:
   The empty lines in method could be removed for clean code



##########
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/UnusedAlgorithmFinderTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.update;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.update.UnusedAlgorithmFinder;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;

Review Comment:
   You could import `src/resources/code-style-idea.xml` in IDEA and format 
importing



##########
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/UnusedAlgorithmFinderTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.update;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.update.UnusedAlgorithmFinder;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class UnusedAlgorithmFinderTest {
+    
+    private static final String USED_TABLE_SHARDING_ALGORITHM = 
"used_table_sharding_algorithm";
+    
+    private static final String USED_TABLE_SHARDING_DEFAULT_ALGORITHM = 
"used_table_sharding_default_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_ALGORITHM = 
"used_database_sharding_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_DEFAULT_ALGORITHM = 
"used_database_sharding_default_algorithm";
+    
+    private static final String UNUSED_ALGORITHM = "unused_algorithm";
+    
+    @Test
+    void assertFind() {
+        ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+        
+        ShardingTableRuleConfiguration shardingTableRuleConfiguration = 
getShardingTableRuleConfiguration();

Review Comment:
   `shardingTableRuleConfiguration` name could be `shardingTableRuleConfig` for 
less code



##########
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/UnusedAlgorithmFinderTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.update;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.update.UnusedAlgorithmFinder;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class UnusedAlgorithmFinderTest {
+    
+    private static final String USED_TABLE_SHARDING_ALGORITHM = 
"used_table_sharding_algorithm";
+    
+    private static final String USED_TABLE_SHARDING_DEFAULT_ALGORITHM = 
"used_table_sharding_default_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_ALGORITHM = 
"used_database_sharding_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_DEFAULT_ALGORITHM = 
"used_database_sharding_default_algorithm";
+    
+    private static final String UNUSED_ALGORITHM = "unused_algorithm";
+    
+    @Test
+    void assertFind() {
+        ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+        
+        ShardingTableRuleConfiguration shardingTableRuleConfiguration = 
getShardingTableRuleConfiguration();
+        Map<String, AlgorithmConfiguration> allAlgorithms = getAlgorithms();

Review Comment:
   `allAlgorithms` could be removed and embed `getAlgorithms()` in `putAll`



##########
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/UnusedAlgorithmFinderTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.update;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.update.UnusedAlgorithmFinder;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class UnusedAlgorithmFinderTest {
+    
+    private static final String USED_TABLE_SHARDING_ALGORITHM = 
"used_table_sharding_algorithm";
+    
+    private static final String USED_TABLE_SHARDING_DEFAULT_ALGORITHM = 
"used_table_sharding_default_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_ALGORITHM = 
"used_database_sharding_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_DEFAULT_ALGORITHM = 
"used_database_sharding_default_algorithm";
+    
+    private static final String UNUSED_ALGORITHM = "unused_algorithm";
+    
+    @Test
+    void assertFind() {
+        ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+        
+        ShardingTableRuleConfiguration shardingTableRuleConfiguration = 
getShardingTableRuleConfiguration();
+        Map<String, AlgorithmConfiguration> allAlgorithms = getAlgorithms();
+        
+        ruleConfig.getTables().add(shardingTableRuleConfiguration);
+        ruleConfig.getShardingAlgorithms().putAll(allAlgorithms);
+        ruleConfig.setDefaultDatabaseShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", 
USED_DATABASE_SHARDING_DEFAULT_ALGORITHM));
+        ruleConfig.setDefaultTableShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", 
USED_TABLE_SHARDING_DEFAULT_ALGORITHM));
+        
+        Collection<String> unusedAlgorithmsCollection = 
UnusedAlgorithmFinder.find(ruleConfig);
+        
+        assertNotNull(unusedAlgorithmsCollection);
+        assertThat(unusedAlgorithmsCollection.size(), is(1));
+        assertTrue(unusedAlgorithmsCollection.contains(UNUSED_ALGORITHM));
+    }
+    
+    private ShardingTableRuleConfiguration getShardingTableRuleConfiguration() 
{
+        ShardingTableRuleConfiguration shardingTableRuleConfiguration = new 
ShardingTableRuleConfiguration("t_order", null);
+        shardingTableRuleConfiguration.setTableShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", 
USED_TABLE_SHARDING_ALGORITHM));
+        shardingTableRuleConfiguration.setDatabaseShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", 
USED_DATABASE_SHARDING_ALGORITHM));
+        
+        return shardingTableRuleConfiguration;

Review Comment:
   `shardingTableRuleConfiguration` name could be `result`



##########
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/UnusedAlgorithmFinderTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.distsql.update;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.distsql.handler.update.UnusedAlgorithmFinder;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class UnusedAlgorithmFinderTest {
+    
+    private static final String USED_TABLE_SHARDING_ALGORITHM = 
"used_table_sharding_algorithm";
+    
+    private static final String USED_TABLE_SHARDING_DEFAULT_ALGORITHM = 
"used_table_sharding_default_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_ALGORITHM = 
"used_database_sharding_algorithm";
+    
+    private static final String USED_DATABASE_SHARDING_DEFAULT_ALGORITHM = 
"used_database_sharding_default_algorithm";
+    
+    private static final String UNUSED_ALGORITHM = "unused_algorithm";
+    
+    @Test
+    void assertFind() {
+        ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
+        
+        ShardingTableRuleConfiguration shardingTableRuleConfiguration = 
getShardingTableRuleConfiguration();
+        Map<String, AlgorithmConfiguration> allAlgorithms = getAlgorithms();
+        
+        ruleConfig.getTables().add(shardingTableRuleConfiguration);
+        ruleConfig.getShardingAlgorithms().putAll(allAlgorithms);
+        ruleConfig.setDefaultDatabaseShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", 
USED_DATABASE_SHARDING_DEFAULT_ALGORITHM));
+        ruleConfig.setDefaultTableShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", 
USED_TABLE_SHARDING_DEFAULT_ALGORITHM));
+        
+        Collection<String> unusedAlgorithmsCollection = 
UnusedAlgorithmFinder.find(ruleConfig);

Review Comment:
   `unusedAlgorithmsCollection` name could be `actual`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to