soulasuna commented on a change in pull request #12159:
URL: https://github.com/apache/shardingsphere/pull/12159#discussion_r702530186
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ProjectionsTokenGeneratorTest.java
##########
@@ -59,27 +59,25 @@
private static final String TEST_DERIVED_PROJECTION_ALIAS =
"TEST_DERIVED_PROJECTION_ALIAS";
- private static final int TEST_STOP_INDEX = 2;
-
private static final String TEST_LOGIC_TABLE_NAME =
"TEST_LOGIC_TABLE_NAME";
- private static final String TEST_ACTUAL_TABLE_NAME =
"TEST_ACTUAL_TABLE_NAME";
-
private static final String TEST_ACTUAL_TABLE_NAME_WRAPPED =
"TEST_ACTUAL_TABLE_NAME_WRAPPED";
private static final String TEST_OTHER_DERIVED_PROJECTION_ALIAS =
"TEST_OTHER_DERIVED_PROJECTION_ALIAS";
private static final String TEST_OTHER_DERIVED_PROJECTION_EXPRESSION =
"TEST_OTHER_DERIVED_PROJECTION_EXPRESSION";
- private RouteUnit routeUnit = mock(RouteUnit.class);
+ private RouteUnit routeUnit;
@Before
public void setup() {
RouteMapper routeMapper = mock(RouteMapper.class);
when(routeMapper.getLogicName()).thenReturn(TEST_LOGIC_TABLE_NAME);
- when(routeMapper.getActualName()).thenReturn(TEST_ACTUAL_TABLE_NAME);
+ final String testActualTableName = "TEST_ACTUAL_TABLE_NAME";
+ when(routeMapper.getActualName()).thenReturn(testActualTableName);
Review comment:
If the variable is only used once, it can be used directly.
Refactored to ‘
when(routeMapper.getActualName()).thenReturn("TEST_ACTUAL_TABLE_NAME")’.
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/RowCountTokenGeneratorTest.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.rewrite.token;
+
+import
org.apache.shardingsphere.infra.binder.segment.select.pagination.PaginationContext;
+import
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
+import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import
org.apache.shardingsphere.sharding.rewrite.token.generator.impl.RowCountTokenGenerator;
+import org.apache.shardingsphere.sharding.rewrite.token.pojo.RowCountToken;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.NumberLiteralPaginationValueSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.NumberLiteralLimitValueSegment;
+import org.junit.Test;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class RowCountTokenGeneratorTest {
+
+ private static final int TEST_OFFSET_SEGMENT_VALUE = 12;
+
+ private static final int TEST_ROW_COUNT_SEGMENT_VALUE = 8;
Review comment:
Minimize the use of variables.
The life cycle of the constant defined in the class is bound to the bytecode
file.
If `TEST_OFFSET_SEGMENT_VALUE `, `TEST_ROW_COUNT_SEGMENT_VALUE ` is only
used in methods, use local variables. The life cycle of the variable is bound
to the method.
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ShardingInsertValuesTokenGeneratorTest.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.rewrite.token;
+
+import
org.apache.shardingsphere.infra.binder.segment.insert.values.InsertValueContext;
+import
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
+import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import
org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.InsertValuesToken;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+import
org.apache.shardingsphere.sharding.rewrite.token.generator.impl.ShardingInsertValuesTokenGenerator;
+import
org.apache.shardingsphere.sharding.rewrite.token.pojo.ShardingInsertValue;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShardingInsertValuesTokenGeneratorTest {
+
+ private static final String TEST_DATASOURCE = "testDatasource";
+
+ private static final String TEST_TABLE = "testTable";
Review comment:
Minimize the use of variables.
The life cycle of the constant defined in the class is bound to the bytecode
file.
If `TEST_DATASOURCE ` , `TEST_TABLE ` is only used in methods, use local
variables. The life cycle of the variable is bound to the method.
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/ConstraintTokenGeneratorTest.java
##########
@@ -72,6 +71,6 @@ public void assertGenerateSQLTokens() {
constraintTokenGenerator.setShardingRule(shardingRule);
Collection<ConstraintToken> result =
constraintTokenGenerator.generateSQLTokens(alterTableStatementContext);
assertThat(result.size(), is(1));
-
assertThat(result.stream().collect(Collectors.toList()).get(0).getStartIndex(),
is(TEST_START_INDEX));
+ assertThat((new LinkedList<>(result)).get(0).getStartIndex(),
is(TEST_START_INDEX));
Review comment:
Minimize the use of variables.
The life cycle of the constant defined in the class is bound to the bytecode
file.
If `TEST_START_INDEX` is only used in methods, use local variables. The life
cycle of the variable is bound to the method.
--
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]