You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/08 05:35:12 UTC

[shardingsphere] branch master updated: Add MySQL unsigned int type at Scaling IT test (#17403)

This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new bf902e5989b Add MySQL unsigned int type at Scaling IT test (#17403)
bf902e5989b is described below

commit bf902e5989b2aba55b95a3c692300a77cbe7ac7b
Author: azexcy <10...@users.noreply.github.com>
AuthorDate: Sun May 8 13:35:06 2022 +0800

    Add MySQL unsigned int type at Scaling IT test (#17403)
    
    * Split increment task
    
    * Add MySQL unsigned int type at IT test
    
    * Simple sql statement extracted
    
    * Fix codestyle
    
    * Use random value
---
 .../pipeline/cases/command/CommonSQLCommand.java   |  6 ------
 .../pipeline/cases/command/ExtraSQLCommand.java    |  3 ---
 .../data/pipeline/cases/mysql/BaseMySQLITCase.java |  4 ++--
 .../MySQLIncrementTaskRunnable.java}               | 25 ++++++++++++++++------
 .../pipeline/cases/mysql/MySQLManualScalingIT.java |  6 ------
 .../cases/postgresql/BasePostgreSQLITCase.java     |  4 ++--
 .../PostgreSQLIncrementTaskRunnable.java}          | 22 +++++++++++++------
 .../data/pipeline/util/TableCrudUtil.java          |  2 +-
 .../resources/env/scenario/manual/mysql/sql.xml    | 10 ++++-----
 9 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/CommonSQLCommand.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/CommonSQLCommand.java
index 775f0120e5a..32177b63613 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/CommonSQLCommand.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/CommonSQLCommand.java
@@ -51,12 +51,6 @@ public final class CommonSQLCommand {
     @XmlElement(name = "simple-insert-order")
     private String simpleInsertOrder;
     
-    @XmlElement(name = "update-order")
-    private String updateOrder;
-    
-    @XmlElement(name = "update-order-item")
-    private String updateOrderItem;
-    
     @XmlElement(name = "delete-order")
     private String deleteOrder;
     
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/ExtraSQLCommand.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/ExtraSQLCommand.java
index 8f46c73c7bc..6b718244c9b 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/ExtraSQLCommand.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/ExtraSQLCommand.java
@@ -35,9 +35,6 @@ public final class ExtraSQLCommand {
     @XmlElement(name = "create-table-order-item")
     private String createTableOrderItem;
     
-    @XmlElement(name = "use-database")
-    private String useDatabase;
-    
     @XmlElement(name = "insert-order")
     private String insertOrder;
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/BaseMySQLITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/BaseMySQLITCase.java
index c352b0d5107..62a3e5edd88 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/BaseMySQLITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/BaseMySQLITCase.java
@@ -22,7 +22,6 @@ import org.apache.commons.lang3.tuple.Pair;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import org.apache.shardingsphere.integration.data.pipeline.cases.BaseITCase;
-import org.apache.shardingsphere.integration.data.pipeline.cases.IncrementTaskRunnable;
 import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
 import org.apache.shardingsphere.integration.data.pipeline.cases.postgresql.BasePostgreSQLITCase;
 import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
@@ -57,9 +56,10 @@ public abstract class BaseMySQLITCase extends BaseITCase {
             addResource(connection);
         }
         initShardingRule();
-        setIncreaseTaskThread(new Thread(new IncrementTaskRunnable(getJdbcTemplate(), getCommonSQLCommand())));
+        setIncreaseTaskThread(new Thread(new MySQLIncrementTaskRunnable(getJdbcTemplate(), getCommonSQLCommand())));
         getJdbcTemplate().execute(extraSQLCommand.getCreateTableOrder());
         getJdbcTemplate().execute(extraSQLCommand.getCreateTableOrderItem());
+        getIncreaseTaskThread().start();
         Pair<List<Object[]>, List<Object[]>> dataPair = TableCrudUtil.generateMySQLInsertDataList(3000);
         getJdbcTemplate().batchUpdate(extraSQLCommand.getInsertOrder(), dataPair.getLeft());
         getJdbcTemplate().batchUpdate(getCommonSQLCommand().getInsertOrderItem(), dataPair.getRight());
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/IncrementTaskRunnable.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLIncrementTaskRunnable.java
similarity index 71%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/IncrementTaskRunnable.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLIncrementTaskRunnable.java
index 03030028d34..9fcb90b51ed 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/IncrementTaskRunnable.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLIncrementTaskRunnable.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.integration.data.pipeline.cases;
+package org.apache.shardingsphere.integration.data.pipeline.cases.mysql;
 
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -25,12 +25,21 @@ import org.apache.shardingsphere.integration.data.pipeline.util.TableCrudUtil;
 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 IncrementTaskRunnable implements Runnable {
+public final class MySQLIncrementTaskRunnable implements Runnable {
+    
+    private static final String INSERT_ORDER = "INSERT INTO t_order (id,order_id,user_id) VALUES (?, ?, ?)";
+    
+    private static final String INSERT_ORDER_ITEM = "INSERT INTO t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)";
+    
+    private static final String UPDATE_ORDER_BY_ID = "UPDATE t_order SET t_varchar = ?,t_unsigned_int = ? WHERE id = ?";
+    
+    private static final String UPDATE_ORDER_ITEM_BY_ID = "UPDATE t_order_item SET status = ? WHERE item_id = ?";
     
     private final JdbcTemplate jdbcTemplate;
     
@@ -41,7 +50,7 @@ public final class IncrementTaskRunnable implements Runnable {
         int executeCount = 0;
         List<Long> newPrimaryKeys = new LinkedList<>();
         try {
-            while (!Thread.currentThread().isInterrupted() && executeCount < 20) {
+            while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
                 newPrimaryKeys.add(insertOrderAndOrderItem());
                 if (newPrimaryKeys.size() % 2 == 0) {
                     deleteOrderAndOrderItem(newPrimaryKeys.get(newPrimaryKeys.size() - 1));
@@ -59,14 +68,16 @@ public final class IncrementTaskRunnable implements Runnable {
     
     private long insertOrderAndOrderItem() throws SQLException {
         Pair<Object[], Object[]> dataPair = TableCrudUtil.generateSimpleInsertData();
-        jdbcTemplate.update(commonSQLCommand.getSimpleInsertOrder(), dataPair.getLeft());
-        jdbcTemplate.update(commonSQLCommand.getInsertOrderItem(), dataPair.getRight());
+        jdbcTemplate.update(INSERT_ORDER, dataPair.getLeft());
+        jdbcTemplate.update(INSERT_ORDER_ITEM, dataPair.getRight());
         return Long.parseLong(dataPair.getLeft()[0].toString());
     }
     
     private void updateOrderAndOrderItem(final long primaryKey) throws SQLException {
-        jdbcTemplate.execute(String.format(commonSQLCommand.getUpdateOrder(), primaryKey));
-        jdbcTemplate.execute(String.format(commonSQLCommand.getUpdateOrderItem(), primaryKey));
+        jdbcTemplate.update(UPDATE_ORDER_BY_ID, null, null, primaryKey);
+        long epochSecond = Instant.now().getEpochSecond();
+        jdbcTemplate.update(UPDATE_ORDER_BY_ID, "update" + epochSecond, epochSecond, primaryKey);
+        jdbcTemplate.update(UPDATE_ORDER_ITEM_BY_ID, "changed" + epochSecond, primaryKey);
     }
     
     private void deleteOrderAndOrderItem(final long primaryKey) throws SQLException {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingIT.java
index 222d50ba3d6..21941aa1386 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingIT.java
@@ -22,7 +22,6 @@ import com.google.common.collect.Sets;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.integration.data.pipeline.env.IntegrationTestEnvironment;
 import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -63,11 +62,6 @@ public final class MySQLManualScalingIT extends BaseMySQLITCase {
         return result;
     }
     
-    @Before
-    public void initEnv() {
-        getIncreaseTaskThread().start();
-    }
-    
     @Test
     public void assertManualScalingSuccess() throws InterruptedException {
         List<Map<String, Object>> previewResults = getJdbcTemplate().queryForList("PREVIEW SELECT COUNT(1) FROM t_order");
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/BasePostgreSQLITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/BasePostgreSQLITCase.java
index 0c2eb345837..80f2d7706f7 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/BasePostgreSQLITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/BasePostgreSQLITCase.java
@@ -23,7 +23,6 @@ import org.apache.commons.lang3.tuple.Pair;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
 import org.apache.shardingsphere.integration.data.pipeline.cases.BaseITCase;
-import org.apache.shardingsphere.integration.data.pipeline.cases.IncrementTaskRunnable;
 import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
 import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
 import org.apache.shardingsphere.integration.data.pipeline.util.TableCrudUtil;
@@ -56,9 +55,10 @@ public abstract class BasePostgreSQLITCase extends BaseITCase {
             addResource(connection);
         }
         initShardingRule();
-        setIncreaseTaskThread(new Thread(new IncrementTaskRunnable(getJdbcTemplate(), getCommonSQLCommand())));
+        setIncreaseTaskThread(new Thread(new PostgreSQLIncrementTaskRunnable(getJdbcTemplate(), getCommonSQLCommand())));
         getJdbcTemplate().execute(extraSQLCommand.getCreateTableOrder());
         getJdbcTemplate().execute(extraSQLCommand.getCreateTableOrderItem());
+        getIncreaseTaskThread().start();
         Pair<List<Object[]>, List<Object[]>> dataPair = TableCrudUtil.generatePostgresSQLInsertDataList(3000);
         getJdbcTemplate().batchUpdate(getExtraSQLCommand().getInsertOrder(), dataPair.getLeft());
         getJdbcTemplate().batchUpdate(getCommonSQLCommand().getInsertOrderItem(), dataPair.getRight());
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/IncrementTaskRunnable.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLIncrementTaskRunnable.java
similarity index 74%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/IncrementTaskRunnable.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLIncrementTaskRunnable.java
index 03030028d34..6b72b4e207e 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/IncrementTaskRunnable.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLIncrementTaskRunnable.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.integration.data.pipeline.cases;
+package org.apache.shardingsphere.integration.data.pipeline.cases.postgresql;
 
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -30,7 +30,15 @@ import java.util.List;
 
 @Slf4j
 @AllArgsConstructor
-public final class IncrementTaskRunnable implements Runnable {
+public final class PostgreSQLIncrementTaskRunnable implements Runnable {
+    
+    private static final String UPDATE_ORDER_BY_ID = "UPDATE t_order SET t_varchar = 'update' WHERE id = %s";
+    
+    private static final String UPDATE_ORDER_ITEM_BY_ID = "UPDATE t_order_item SET status = 'changed' WHERE item_id = %s";
+    
+    private static final String INSERT_ORDER = "INSERT INTO t_order ( id, order_id, user_id) VALUES (?, ?, ?)";
+    
+    private static final String INSERT_ORDER_ITEM = "INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES(?,?,?,?)";
     
     private final JdbcTemplate jdbcTemplate;
     
@@ -41,7 +49,7 @@ public final class IncrementTaskRunnable implements Runnable {
         int executeCount = 0;
         List<Long> newPrimaryKeys = new LinkedList<>();
         try {
-            while (!Thread.currentThread().isInterrupted() && executeCount < 20) {
+            while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
                 newPrimaryKeys.add(insertOrderAndOrderItem());
                 if (newPrimaryKeys.size() % 2 == 0) {
                     deleteOrderAndOrderItem(newPrimaryKeys.get(newPrimaryKeys.size() - 1));
@@ -59,14 +67,14 @@ public final class IncrementTaskRunnable implements Runnable {
     
     private long insertOrderAndOrderItem() throws SQLException {
         Pair<Object[], Object[]> dataPair = TableCrudUtil.generateSimpleInsertData();
-        jdbcTemplate.update(commonSQLCommand.getSimpleInsertOrder(), dataPair.getLeft());
-        jdbcTemplate.update(commonSQLCommand.getInsertOrderItem(), dataPair.getRight());
+        jdbcTemplate.update(INSERT_ORDER, dataPair.getLeft());
+        jdbcTemplate.update(INSERT_ORDER_ITEM, dataPair.getRight());
         return Long.parseLong(dataPair.getLeft()[0].toString());
     }
     
     private void updateOrderAndOrderItem(final long primaryKey) throws SQLException {
-        jdbcTemplate.execute(String.format(commonSQLCommand.getUpdateOrder(), primaryKey));
-        jdbcTemplate.execute(String.format(commonSQLCommand.getUpdateOrderItem(), primaryKey));
+        jdbcTemplate.execute(String.format(UPDATE_ORDER_BY_ID, primaryKey));
+        jdbcTemplate.execute(String.format(UPDATE_ORDER_ITEM_BY_ID, primaryKey));
     }
     
     private void deleteOrderAndOrderItem(final long primaryKey) throws SQLException {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/util/TableCrudUtil.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/util/TableCrudUtil.java
index 0099eac29c7..222ab607b77 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/util/TableCrudUtil.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/util/TableCrudUtil.java
@@ -49,7 +49,7 @@ public final class TableCrudUtil {
             int orderId = RANDOM.nextInt(0, 5);
             int userId = RANDOM.nextInt(0, 5);
             orderData.add(new Object[]{SNOWFLAKE_GENERATE.generateKey(), orderId, userId, "varchar" + i, (byte) 1, new Timestamp(System.currentTimeMillis()), new Timestamp(System.currentTimeMillis()),
-                    "hello".getBytes(StandardCharsets.UTF_8), null, new BigDecimal("100.00"), "test", Math.random(), "{}"});
+                    "hello".getBytes(StandardCharsets.UTF_8), null, new BigDecimal("100.00"), "test", Math.random(), "{}", RANDOM.nextInt(0, 10000000)});
             orderItemData.add(new Object[]{SNOWFLAKE_GENERATE.generateKey(), orderId, userId, "SUCCESS"});
         }
         return Pair.of(orderData, orderItemData);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/sql.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/sql.xml
index c73a3989e82..f113c7394df 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/sql.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/sql.xml
@@ -30,6 +30,7 @@
         `t_char` CHAR ( 128 ) NULL,
         `t_double` DOUBLE NULL,
         `t_json` json NULL COMMENT 'json test',
+        `t_unsigned_int` int UNSIGNED NULL,
         PRIMARY KEY ( `id` ),
         INDEX ( `order_id` )
         ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@@ -45,10 +46,6 @@
         ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
     </create-table-order-item>
     
-    <use-database>
-        USE sharding_db
-    </use-database>
-    
     <add-resource>
         ADD RESOURCE %s (URL='jdbc:mysql://%s/%s?serverTimezone=UTC&amp;useSSL=false&amp;rewriteBatchedStatements=true',USER=root,PASSWORD=root)
     </add-resource>
@@ -67,8 +64,9 @@
         t_decimal,
         t_char,
         t_double,
-        t_json
+        t_json,
+        t_unsigned_int
         )
-        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)
+        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
     </insert-order>
 </command>