You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/05/13 15:35:35 UTC

[GitHub] [shardingsphere] azexcy commented on a diff in pull request #17637: Refactor Scaling IT code, prepare support multiple scenarios

azexcy commented on code in PR #17637:
URL: https://github.com/apache/shardingsphere/pull/17637#discussion_r872527904


##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLIncrementTaskRunnable.java:
##########
@@ -17,63 +17,49 @@
 
 package org.apache.shardingsphere.integration.data.pipeline.cases.mysql;
 
-import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseTaskRunnable;
 import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
-import org.apache.shardingsphere.integration.data.pipeline.util.TableCrudUtil;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
 import org.springframework.jdbc.core.JdbcTemplate;
 
-import java.sql.SQLException;
-import java.time.Instant;
 import java.util.LinkedList;
 import java.util.List;
 
 @Slf4j
-@AllArgsConstructor
-public final class MySQLIncrementTaskRunnable implements Runnable {
+public final class MySQLIncrementTaskRunnable extends BaseTaskRunnable {
     
-    private final JdbcTemplate jdbcTemplate;
-    
-    private final ExtraSQLCommand extraSQLCommand;
+    public MySQLIncrementTaskRunnable(final JdbcTemplate jdbcTemplate, final ExtraSQLCommand extraSQLCommand, final KeyGenerateAlgorithm keyGenerateAlgorithm) {
+        super(jdbcTemplate, extraSQLCommand, keyGenerateAlgorithm);
+    }
     
     @Override
     public void run() {
         int executeCount = 0;
-        List<Long> newPrimaryKeys = new LinkedList<>();
-        try {
-            while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
-                newPrimaryKeys.add(insertOrderAndOrderItem());
-                if (newPrimaryKeys.size() % 2 == 0) {
-                    deleteOrderAndOrderItem(newPrimaryKeys.get(newPrimaryKeys.size() - 1));
-                } else {
-                    updateOrderAndOrderItem(newPrimaryKeys.get(newPrimaryKeys.size() - 1));
-                }
-                executeCount++;
-                log.info("Increment task runnable execute successfully.");
+        List<Object> newOrderPrimaryKeys = new LinkedList<>();
+        List<Object> newOrderItemPrimaryKeys = new LinkedList<>();
+        while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
+            newOrderPrimaryKeys.add(insertOrder());
+            newOrderItemPrimaryKeys.add(insertOrderItem());
+            if (newOrderPrimaryKeys.size() % 2 == 0) {
+                deleteOrderByPrimaryKey(newOrderPrimaryKeys.get(newOrderPrimaryKeys.size() - 1));
+                deleteOrderItemByPrimaryKey(newOrderItemPrimaryKeys.get(newOrderItemPrimaryKeys.size() - 1));
+            } else {
+                updateOrderByPrimaryKey(newOrderPrimaryKeys.get(newOrderPrimaryKeys.size() - 1));
+                updateOrderItemByPrimaryKey(newOrderItemPrimaryKeys.get(newOrderItemPrimaryKeys.size() - 1));
             }
-        } catch (final SQLException ex) {
-            log.error("IncrementTaskThread error", ex);
-            throw new RuntimeException(ex);

Review Comment:
   If exception thrown, the increment task will stop, seem need not to catch the exception. 



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org