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/31 08:09:00 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #18091: Scaling IT add thread sleep, make sure metadata refreshed

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


##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/ThreadUtil.java:
##########
@@ -37,4 +39,17 @@ public static void sleep(final long millis) {
         } catch (final InterruptedException ignored) {
         }
     }
+    
+    /**
+     * Sleep ignored InterruptedException.
+     *
+     * @param timeUnit time unit.
+     * @param number sleep time.

Review Comment:
   The end `.` could be removed.



##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseITCase.java:
##########
@@ -188,43 +190,57 @@ private String getActualJdbcUrlTemplate(final String databaseName) {
         }
     }
     
-    protected void initShardingAlgorithm() throws InterruptedException {
-        executeWithLog(getCommonSQLCommand().getCreateDatabaseShardingAlgorithm());
-        TimeUnit.SECONDS.sleep(2);
-        executeWithLog(getCommonSQLCommand().getCreateOrderShardingAlgorithm());
-        TimeUnit.SECONDS.sleep(2);
-        executeWithLog(getCommonSQLCommand().getCreateOrderItemShardingAlgorithm());
+    protected void initShardingAlgorithm() {
+        executeWithLogAndWait(getCommonSQLCommand().getCreateDatabaseShardingAlgorithm());
+        executeWithLogAndWait(getCommonSQLCommand().getCreateOrderShardingAlgorithm());
+        executeWithLogAndWait(getCommonSQLCommand().getCreateOrderItemShardingAlgorithm());
     }
     
     protected void getCreateOrderWithItemSharingTableRule() {
-        executeWithLog(commonSQLCommand.getCreateOrderWithItemSharingTableRule());
+        executeWithLogAndWait(commonSQLCommand.getCreateOrderWithItemSharingTableRule());
         assertBeforeApplyScalingMetadataCorrectly();
     }
     
     protected void createOrderSharingTableRule() {
-        executeWithLog(commonSQLCommand.getCreateOrderShardingTableRule());
+        executeWithLogAndWait(commonSQLCommand.getCreateOrderShardingTableRule());
     }
     
     protected void bindingShardingRule() {
-        executeWithLog("CREATE SHARDING BINDING TABLE RULES (t_order,t_order_item)");
+        executeWithLogAndWait("CREATE SHARDING BINDING TABLE RULES (t_order,t_order_item)");
     }
     
     protected void createScalingRule() {
-        executeWithLog("CREATE SHARDING SCALING RULE scaling_manual (INPUT(SHARDING_SIZE=1000), DATA_CONSISTENCY_CHECKER(TYPE(NAME=DATA_MATCH)))");
+        executeWithLogAndWait("CREATE SHARDING SCALING RULE scaling_manual (INPUT(SHARDING_SIZE=1000), DATA_CONSISTENCY_CHECKER(TYPE(NAME=DATA_MATCH)))");
     }
     
     protected void createSchema(final String schemaName) {
-        executeWithLog(String.format("CREATE SCHEMA %s", schemaName));
+        executeWithLogAndWait(String.format("CREATE SCHEMA %s", schemaName));
+    }
+    
+    protected void executeWithLogAndWait(final Connection connection, final String sql) throws SQLException {
+        log.info("connection execute:{}", sql);
+        connection.createStatement().execute(sql);
+        ThreadUtil.sleep(TimeUnit.SECONDS, 1);
     }
     
-    protected void executeWithLog(final String sql) {
+    protected void executeWithLogAndWait(final String sql) {
         log.info("jdbcTemplate execute:{}", sql);
         jdbcTemplate.execute(sql);
+        ThreadUtil.sleep(TimeUnit.SECONDS, 2);
     }

Review Comment:
   `executeWithLogAndWait` could be simplified, since wait might be needed temporarily.



##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/ThreadUtil.java:
##########
@@ -37,4 +39,17 @@ public static void sleep(final long millis) {
         } catch (final InterruptedException ignored) {
         }
     }
+    
+    /**
+     * Sleep ignored InterruptedException.
+     *
+     * @param timeUnit time unit.
+     * @param number sleep time.
+     */
+    public static void sleep(final TimeUnit timeUnit, final int number) {

Review Comment:
   `int number` could be `int timeout`, and it could be put before `TimeUnit timeUnit`.
   
   `ThreadUtil.sleep(TimeUnit.SECONDS, 2)` vs `ThreadUtil.sleep(2, TimeUnit.SECONDS)`.
   



-- 
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