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/08/26 07:15:42 UTC
[shardingsphere] branch master updated: Add encrypt rule at migration IT case (#20550)
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 062dda00b0a Add encrypt rule at migration IT case (#20550)
062dda00b0a is described below
commit 062dda00b0a16c1fd44a47c0e20ab1ec27130472
Author: Xinze Guo <10...@users.noreply.github.com>
AuthorDate: Fri Aug 26 15:15:34 2022 +0800
Add encrypt rule at migration IT case (#20550)
---
.../integration/data/pipeline/cases/base/BaseITCase.java | 11 ++++++++---
.../data/pipeline/cases/command/MigrationDistSQLCommand.java | 3 +++
.../data/pipeline/cases/general/MySQLMigrationGeneralIT.java | 1 +
.../data/pipeline/cases/task/MySQLIncrementTask.java | 10 +++++-----
.../data/pipeline/framework/helper/ScalingCaseHelper.java | 6 +++---
.../src/test/resources/env/common/command.xml | 6 ++++++
6 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseITCase.java
index 7092d4bc933..43018a2beb8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseITCase.java
@@ -218,11 +218,15 @@ public abstract class BaseITCase {
}
protected void createTargetOrderTableRule() throws SQLException {
- proxyExecuteWithLog(migrationDistSQLCommand.getCreateTargetOrderTableRule(), 3);
+ proxyExecuteWithLog(migrationDistSQLCommand.getCreateTargetOrderTableRule(), 2);
+ }
+
+ protected void createTargetOrderTableEncryptRule() throws SQLException {
+ proxyExecuteWithLog(migrationDistSQLCommand.getCreateTargetOrderTableEncryptRule(), 2);
}
protected void createTargetOrderItemTableRule() throws SQLException {
- proxyExecuteWithLog(migrationDistSQLCommand.getCreateTargetOrderItemTableRule(), 3);
+ proxyExecuteWithLog(migrationDistSQLCommand.getCreateTargetOrderItemTableRule(), 2);
}
protected void startMigrationOrder(final boolean withSchema) throws SQLException {
@@ -245,8 +249,9 @@ public abstract class BaseITCase {
try {
proxyExecuteWithLog(migrationDistSQLCommand.getAddMigrationProcessConfig(), 0);
} catch (final SQLException ex) {
- if ("58000".equals(ex.getSQLState())) {
+ if ("58000".equals(ex.getSQLState()) || "42000".equals(ex.getSQLState())) {
log.warn(ex.getMessage());
+ return;
}
throw ex;
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/MigrationDistSQLCommand.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/MigrationDistSQLCommand.java
index 260b660e41c..bc873e505e0 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/MigrationDistSQLCommand.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/command/MigrationDistSQLCommand.java
@@ -32,6 +32,9 @@ public final class MigrationDistSQLCommand {
@XmlElement(name = "add-migration-process-config")
private String addMigrationProcessConfig;
+ @XmlElement(name = "create-target-order-table-encrypt-rule")
+ private String createTargetOrderTableEncryptRule;
+
@XmlElement(name = "create-target-order-table-rule")
private String createTargetOrderTableRule;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/MySQLMigrationGeneralIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/MySQLMigrationGeneralIT.java
index d54f9b67e49..813973da71d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/MySQLMigrationGeneralIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/MySQLMigrationGeneralIT.java
@@ -78,6 +78,7 @@ public final class MySQLMigrationGeneralIT extends BaseExtraSQLITCase {
addSourceResource();
addTargetResource();
createTargetOrderTableRule();
+ createTargetOrderTableEncryptRule();
createTargetOrderItemTableRule();
SnowflakeKeyGenerateAlgorithm keyGenerateAlgorithm = new SnowflakeKeyGenerateAlgorithm();
JdbcTemplate jdbcTemplate = new JdbcTemplate(getSourceDataSource());
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/task/MySQLIncrementTask.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/task/MySQLIncrementTask.java
index 14bebdc5c5f..a0a049bc846 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/task/MySQLIncrementTask.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/task/MySQLIncrementTask.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.integration.data.pipeline.cases.task;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.RandomStringUtils;
import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseIncrementTask;
import org.apache.shardingsphere.integration.data.pipeline.framework.helper.ScalingCaseHelper;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
@@ -61,9 +62,8 @@ public final class MySQLIncrementTask extends BaseIncrementTask {
private Object insertOrder() {
ThreadLocalRandom random = ThreadLocalRandom.current();
- String status = random.nextInt() % 2 == 0 ? null : "NOT-NULL";
Object[] orderInsertDate = new Object[]{primaryKeyGenerateAlgorithm.generateKey(), ScalingCaseHelper.generateSnowflakeKey(), random.nextInt(0, 6),
- random.nextInt(1, 99), status};
+ random.nextInt(1, 99), RandomStringUtils.randomAlphabetic(10)};
jdbcTemplate.update("INSERT INTO t_order (id,order_id,user_id,t_unsigned_int,status) VALUES (?, ?, ?, ?, ?)", orderInsertDate);
return orderInsertDate[0];
}
@@ -78,11 +78,11 @@ public final class MySQLIncrementTask extends BaseIncrementTask {
private void updateOrderByPrimaryKey(final Object primaryKey) {
Object[] updateData = {"updated" + Instant.now().getEpochSecond(), ThreadLocalRandom.current().nextInt(0, 100), primaryKey};
- jdbcTemplate.update("UPDATE t_order SET status = ?,t_unsigned_int = ? WHERE id = ?", updateData);
- jdbcTemplate.update("UPDATE t_order SET status = null,t_unsigned_int = 299,t_datetime='0000-00-00 00:00:00' WHERE id = ?", primaryKey);
+ jdbcTemplate.update("UPDATE t_order SET t_char = ?,t_unsigned_int = ? WHERE id = ?", updateData);
+ jdbcTemplate.update("UPDATE t_order SET t_char = null,t_unsigned_int = 299,t_datetime='0000-00-00 00:00:00' WHERE id = ?", primaryKey);
}
private void setNullToOrderFields(final Object primaryKey) {
- jdbcTemplate.update("UPDATE t_order SET status = null, t_unsigned_int = null WHERE id = ?", primaryKey);
+ jdbcTemplate.update("UPDATE t_order SET t_char = null, t_unsigned_int = null WHERE id = ?", primaryKey);
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingCaseHelper.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingCaseHelper.java
index 6a658b291ea..b0531fb2503 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingCaseHelper.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingCaseHelper.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
+import java.time.Year;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
@@ -70,9 +71,8 @@ public final class ScalingCaseHelper {
if (databaseType instanceof MySQLDatabaseType) {
Object[] addObjs = {keyGenerateAlgorithm.generateKey(), orderId, userId, generateString(6), randomInt, randomInt, randomInt,
randomUnsignedInt, randomUnsignedInt, randomUnsignedInt, randomUnsignedInt, generateFloat(), generateDouble(-1000, 100000),
- // TODO year should not be always null
- BigDecimal.valueOf(generateDouble(1, 100)), now, now, now.toLocalDate(), now.toLocalTime(), null, "1", "t", "e", "s", "t", generateString(2), generateString(1),
- generateString(1), "1", "2", generateJsonString(1024)};
+ BigDecimal.valueOf(generateDouble(1, 100)), now, now, now.toLocalDate(), now.toLocalTime(), Year.now().getValue(), "1", "t", "e", "s", "t", generateString(2),
+ generateString(1), generateString(1), "1", "2", generateJsonString(1024)};
orderData.add(addObjs);
} else {
orderData.add(new Object[]{keyGenerateAlgorithm.generateKey(), orderId, userId, generateString(6), randomInt,
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml
index 6b54bf4614b..fea5de0e5c4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml
@@ -57,6 +57,12 @@
)
</add-migration-target-resource-template>
+ <create-target-order-table-encrypt-rule>
+ CREATE ENCRYPT RULE t_order (
+ COLUMNS((NAME=status, CIPHER=status,TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
+ QUERY_WITH_CIPHER_COLUMN=true)
+ </create-target-order-table-encrypt-rule>
+
<create-target-order-table-rule>
CREATE SHARDING TABLE RULE t_order(
RESOURCES(ds_2,ds_3,ds_4),