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/17 13:29:57 UTC
[shardingsphere] branch master updated: Improve text primary key case, and some adjustments (#17730)
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 1fe78ffaa85 Improve text primary key case, and some adjustments (#17730)
1fe78ffaa85 is described below
commit 1fe78ffaa85aba20d6988fc47f282ed592f70a20
Author: azexcy <10...@users.noreply.github.com>
AuthorDate: Tue May 17 21:29:51 2022 +0800
Improve text primary key case, and some adjustments (#17730)
* Extract the same code from xml, optimize by scenario
* Add text primary key case
* move ddlgenerator.xml
* Update it-scaling.yml,remove repository limit
* Code optimization
* Remove insert no_use statement, may need wait
* Code optimization
* Fix codestyle
---
.github/workflows/it-scaling.yml | 2 +-
.../pipeline/cases/base/BaseExtraSQLITCase.java | 48 ++++++++
.../data/pipeline/cases/base/BaseITCase.java | 77 +++++++++----
.../BaseIncrementTask.java} | 21 +---
.../data/pipeline/cases/base/BaseMySQLITCase.java | 82 --------------
.../pipeline/cases/base/BaseOpenGaussITCase.java | 74 -------------
.../pipeline/cases/base/BasePostgreSQLITCase.java | 72 ------------
.../data/pipeline/cases/base/BaseTaskRunnable.java | 103 -----------------
.../pipeline/cases/command/CommonSQLCommand.java | 7 +-
.../pipeline/cases/command/ExtraSQLCommand.java | 19 +---
.../cases/common/MySQLIncrementTaskRunnable.java | 73 ------------
.../common/PostgreSQLIncrementTaskRunnable.java | 68 ------------
.../MySQLGeneralScalingIT.java} | 62 +++++------
.../PostgreSQLGeneralScalingIT.java} | 64 +++++------
.../cases/postgresql/PostgreSQLDDLGeneratorIT.java | 2 +-
.../postgresql/PostgreSQLManualScalingIT.java | 84 --------------
.../cases/primarykey/TextPrimaryKeyScalingIT.java | 90 +++++++++++++++
.../pipeline/cases/task/MySQLIncrementTask.java | 80 ++++++++++++++
.../cases/task/PostgreSQLIncrementTask.java | 86 ++++++++++++++
.../pipeline/env/IntegrationTestEnvironment.java | 10 +-
.../data/pipeline/framework/ITWatcher.java | 55 ---------
.../framework/helper/ScalingCaseHelper.java | 123 +++++++++++++++++++++
.../framework/helper/ScalingTableSQLHelper.java | 75 -------------
.../framework/param/ScalingParameterized.java | 2 +
.../data/pipeline/util/TableCrudUtil.java | 19 ++--
.../src/test/resources/env/common/command.xml | 13 ++-
.../postgresql}/ddlgenerator.xml | 0
.../sql.xml => general/mysql.xml} | 42 +------
.../sql.xml => general/postgresql.xml} | 24 +---
.../text_primary_key/mysql.xml} | 29 +----
.../text_primary_key/postgresql.xml} | 11 +-
31 files changed, 594 insertions(+), 923 deletions(-)
diff --git a/.github/workflows/it-scaling.yml b/.github/workflows/it-scaling.yml
index 95748c2c17a..4763e8b7ce9 100644
--- a/.github/workflows/it-scaling.yml
+++ b/.github/workflows/it-scaling.yml
@@ -62,7 +62,7 @@ env:
jobs:
scaling-it-test:
- if: (github.event_name != 'schedule' && github.repository == 'apache/shardingsphere')
+ if: (github.event_name != 'schedule')
name: scaling-it-test
runs-on: ubuntu-latest
env:
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseExtraSQLITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseExtraSQLITCase.java
new file mode 100644
index 00000000000..8ea64397799
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseExtraSQLITCase.java
@@ -0,0 +1,48 @@
+/*
+ * 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.integration.data.pipeline.cases.base;
+
+import lombok.Getter;
+import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
+import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
+
+import javax.xml.bind.JAXB;
+
+public abstract class BaseExtraSQLITCase extends BaseITCase {
+
+ @Getter
+ private final ExtraSQLCommand extraSQLCommand;
+
+ public BaseExtraSQLITCase(final ScalingParameterized parameterized) {
+ super(parameterized);
+ extraSQLCommand = JAXB.unmarshal(BaseExtraSQLITCase.class.getClassLoader().getResource(parameterized.getScenario()), ExtraSQLCommand.class);
+ }
+
+ protected void createNoUseTable() {
+ getJdbcTemplate().execute("CREATE SHARDING TABLE RULE no_use (RESOURCES(ds_0, ds_1), SHARDING_COLUMN=sharding_id, TYPE(NAME=MOD,PROPERTIES('sharding-count'=4)))");
+ getJdbcTemplate().execute("CREATE TABLE no_use(id int(11) NOT NULL,sharding_id int(11) NOT NULL, PRIMARY KEY (id))");
+ }
+
+ protected void createOrderTable() {
+ getJdbcTemplate().execute(extraSQLCommand.getCreateTableOrder());
+ }
+
+ protected void createOrderItemTable() {
+ getJdbcTemplate().execute(extraSQLCommand.getCreateTableOrderItem());
+ }
+}
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 63c7dde3fc7..ea77fa946a4 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
@@ -25,22 +25,21 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.api.job.JobStatus;
-import org.apache.shardingsphere.data.pipeline.core.util.ThreadUtil;
import org.apache.shardingsphere.infra.database.metadata.url.JdbcUrlAppender;
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.command.CommonSQLCommand;
import org.apache.shardingsphere.integration.data.pipeline.env.IntegrationTestEnvironment;
import org.apache.shardingsphere.integration.data.pipeline.env.enums.ITEnvTypeEnum;
-import org.apache.shardingsphere.integration.data.pipeline.framework.ITWatcher;
import org.apache.shardingsphere.integration.data.pipeline.framework.container.compose.BaseComposedContainer;
import org.apache.shardingsphere.integration.data.pipeline.framework.container.compose.DockerComposedContainer;
import org.apache.shardingsphere.integration.data.pipeline.framework.container.compose.NativeComposedContainer;
import org.apache.shardingsphere.integration.data.pipeline.framework.container.database.DockerDatabaseContainer;
+import org.apache.shardingsphere.integration.data.pipeline.framework.helper.ScalingCaseHelper;
import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
import org.apache.shardingsphere.integration.data.pipeline.util.DatabaseTypeUtil;
import org.apache.shardingsphere.test.integration.env.DataSourceEnvironment;
import org.junit.After;
-import org.junit.Rule;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;
@@ -72,20 +71,19 @@ public abstract class BaseITCase {
private static final IntegrationTestEnvironment ENV = IntegrationTestEnvironment.getInstance();
- @Rule
- @Getter(AccessLevel.NONE)
- public ITWatcher watcher = new ITWatcher();
-
private final BaseComposedContainer composedContainer;
private final CommonSQLCommand commonSQLCommand;
+ private final DatabaseType databaseType;
+
private JdbcTemplate jdbcTemplate;
@Setter
private Thread increaseTaskThread;
public BaseITCase(final ScalingParameterized parameterized) {
+ databaseType = parameterized.getDatabaseType();
if (ENV.getItEnvType() == ITEnvTypeEnum.DOCKER) {
composedContainer = new DockerComposedContainer(parameterized.getDatabaseType(), parameterized.getDockerImageName());
} else {
@@ -99,7 +97,7 @@ public abstract class BaseITCase {
@SneakyThrows
protected void createProxyDatabase(final DatabaseType databaseType) {
JdbcUrlAppender jdbcUrlAppender = new JdbcUrlAppender();
- Properties queryProps = createQueryProperties();
+ Properties queryProps = ScalingCaseHelper.getQueryPropertiesByDatabaseType(databaseType);
String defaultDatabaseName = DatabaseTypeUtil.isPostgreSQL(databaseType) ? "postgres" : "";
try (Connection connection = DriverManager.getConnection(jdbcUrlAppender.appendQueryProperties(composedContainer.getProxyJdbcUrl(defaultDatabaseName), queryProps), "root", "root")) {
connection.createStatement().execute("CREATE DATABASE sharding_db");
@@ -107,8 +105,6 @@ public abstract class BaseITCase {
jdbcTemplate = new JdbcTemplate(getProxyDataSource("sharding_db"));
}
- protected abstract Properties createQueryProperties();
-
private DataSource getProxyDataSource(final String databaseName) {
HikariDataSource result = new HikariDataSource();
result.setDriverClassName(DataSourceEnvironment.getDriverClassName(composedContainer.getDatabaseContainer().getDatabaseType()));
@@ -120,17 +116,51 @@ public abstract class BaseITCase {
return result;
}
- protected void addSourceResource(final Connection connection, final String username, final String password) throws SQLException {
- Properties queryProps = createQueryProperties();
- String addSourceResource = commonSQLCommand.getSourceAddResourceTemplate().replace("${user}", username).replace("${password}", password)
+ protected boolean waitShardingAlgorithmEffect(final int maxWaitTimes) throws InterruptedException {
+ long startTime = System.currentTimeMillis();
+ int waitTimes = 0;
+ do {
+ List<Map<String, Object>> result = jdbcTemplate.queryForList("SHOW SHARDING ALGORITHMS");
+ if (result.size() >= 3) {
+ log.info("waitShardingAlgorithmEffect time consume: {}", System.currentTimeMillis() - startTime);
+ return true;
+ }
+ TimeUnit.SECONDS.sleep(2);
+ waitTimes++;
+ } while (waitTimes <= maxWaitTimes);
+ return false;
+ }
+
+ @SneakyThrows
+ protected void addSourceResource() {
+ Properties queryProps = ScalingCaseHelper.getQueryPropertiesByDatabaseType(databaseType);
+ // TODO if mysql can append database firstly, they can be combined
+ if (databaseType instanceof MySQLDatabaseType) {
+ try (Connection connection = DriverManager.getConnection(JDBC_URL_APPENDER.appendQueryProperties(getComposedContainer().getProxyJdbcUrl(""), queryProps), "root", "root")) {
+ connection.createStatement().execute("USE sharding_db");
+ addSourceResource0(connection);
+ }
+ } else {
+ try (Connection connection = DriverManager.getConnection(JDBC_URL_APPENDER.appendQueryProperties(getComposedContainer().getProxyJdbcUrl("sharding_db"), queryProps), "root", "root")) {
+ addSourceResource0(connection);
+ }
+ }
+ }
+
+ private void addSourceResource0(final Connection connection) throws SQLException {
+ Properties queryProps = ScalingCaseHelper.getQueryPropertiesByDatabaseType(databaseType);
+ String addSourceResource = commonSQLCommand.getSourceAddResourceTemplate().replace("${user}", ScalingCaseHelper.getUsername(databaseType))
+ .replace("${password}", ScalingCaseHelper.getPassword(databaseType))
.replace("${ds0}", JDBC_URL_APPENDER.appendQueryProperties(getActualJdbcUrlTemplate("ds_0"), queryProps))
.replace("${ds1}", JDBC_URL_APPENDER.appendQueryProperties(getActualJdbcUrlTemplate("ds_1"), queryProps));
connection.createStatement().execute(addSourceResource);
}
- protected void addTargetSourceResource(final String username, final String password) {
- Properties queryProps = createQueryProperties();
- String addTargetResource = commonSQLCommand.getTargetAddResourceTemplate().replace("${user}", username).replace("${password}", password)
+ @SneakyThrows
+ protected void addTargetResource() {
+ Properties queryProps = ScalingCaseHelper.getQueryPropertiesByDatabaseType(databaseType);
+ String addTargetResource = commonSQLCommand.getTargetAddResourceTemplate().replace("${user}", ScalingCaseHelper.getUsername(databaseType))
+ .replace("${password}", ScalingCaseHelper.getPassword(databaseType))
.replace("${ds2}", JDBC_URL_APPENDER.appendQueryProperties(getActualJdbcUrlTemplate("ds_2"), queryProps))
.replace("${ds3}", JDBC_URL_APPENDER.appendQueryProperties(getActualJdbcUrlTemplate("ds_3"), queryProps))
.replace("${ds4}", JDBC_URL_APPENDER.appendQueryProperties(getActualJdbcUrlTemplate("ds_4"), queryProps));
@@ -174,6 +204,11 @@ public abstract class BaseITCase {
jdbcTemplate.execute(String.format("CREATE SCHEMA %s", schemaName));
}
+ protected void startIncrementTask(final BaseIncrementTask baseIncrementTask) {
+ setIncreaseTaskThread(new Thread(baseIncrementTask));
+ getIncreaseTaskThread().start();
+ }
+
protected void assertOriginalSourceSuccess() {
List<Map<String, Object>> previewResults = getJdbcTemplate().queryForList("PREVIEW SELECT COUNT(1) FROM t_order");
Set<Object> originalSources = previewResults.stream().map(each -> each.get("data_source_name")).collect(Collectors.toSet());
@@ -183,11 +218,13 @@ public abstract class BaseITCase {
/**
* Check data match consistency.
*
- * @param jdbcTemplate jdbc template
- * @param jobId job id
* @throws InterruptedException interrupted exception
*/
- protected void assertCheckMatchConsistencySuccess(final JdbcTemplate jdbcTemplate, final String jobId) throws InterruptedException {
+ protected void assertCheckMatchConsistencySuccess() throws InterruptedException {
+ if (null != increaseTaskThread) {
+ increaseTaskThread.join(60 * 1000L);
+ }
+ String jobId = String.valueOf(getJdbcTemplate().queryForMap("SHOW SCALING LIST").get("id"));
Map<String, String> actualStatusMap = new HashMap<>(2, 1);
for (int i = 0; i < 100; i++) {
List<Map<String, Object>> showScalingStatusResMap = jdbcTemplate.queryForList(String.format("SHOW SCALING STATUS %s", jobId));
@@ -218,7 +255,7 @@ public abstract class BaseITCase {
}
jdbcTemplate.execute(String.format("APPLY SCALING %s", jobId));
// TODO make sure the scaling job was applied
- ThreadUtil.sleep(2000);
+ TimeUnit.SECONDS.sleep(2);
List<Map<String, Object>> previewResults = jdbcTemplate.queryForList("PREVIEW SELECT COUNT(1) FROM t_order");
Set<Object> originalSources = previewResults.stream().map(each -> each.get("data_source_name")).collect(Collectors.toSet());
assertThat(originalSources, is(new HashSet<>(Arrays.asList("ds_2", "ds_3", "ds_4"))));
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/scenario/ScalingScenario.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseIncrementTask.java
similarity index 65%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/scenario/ScalingScenario.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseIncrementTask.java
index fbacfe4b689..c1d85b5e40f 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/scenario/ScalingScenario.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseIncrementTask.java
@@ -15,25 +15,8 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.integration.data.pipeline.cases.scenario;
+package org.apache.shardingsphere.integration.data.pipeline.cases.base;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-
-/**
- * Manual scaling scenario.
- */
-public final class ScalingScenario {
-
- public static final String SCENARIO_SUFFIX = "sql.xml";
+public abstract class BaseIncrementTask implements Runnable {
- /**
- * Manual scenario list.
- *
- * @return scenario list
- */
- public static Collection<String> listScenario() {
- return new HashSet<>(Collections.singleton("integer_primary_key"));
- }
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseMySQLITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseMySQLITCase.java
deleted file mode 100644
index 3f0aee29fef..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseMySQLITCase.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.integration.data.pipeline.cases.base;
-
-import lombok.Getter;
-import lombok.SneakyThrows;
-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.command.ExtraSQLCommand;
-import org.apache.shardingsphere.integration.data.pipeline.cases.common.MySQLIncrementTaskRunnable;
-import org.apache.shardingsphere.integration.data.pipeline.framework.helper.ScalingTableSQLHelper;
-import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-
-import javax.xml.bind.JAXB;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-
-public abstract class BaseMySQLITCase extends BaseITCase {
-
- protected static final DatabaseType DATABASE_TYPE = new MySQLDatabaseType();
-
- private final ExtraSQLCommand extraSQLCommand;
-
- @Getter
- private final ScalingTableSQLHelper sqlHelper;
-
- public BaseMySQLITCase(final ScalingParameterized parameterized) {
- super(parameterized);
- extraSQLCommand = JAXB.unmarshal(BaseMySQLITCase.class.getClassLoader().getResource(parameterized.getScenario()), ExtraSQLCommand.class);
- sqlHelper = new ScalingTableSQLHelper(DATABASE_TYPE, extraSQLCommand, getJdbcTemplate());
- }
-
- @SneakyThrows(SQLException.class)
- protected void addSourceResource() {
- Properties queryProps = createQueryProperties();
- // TODO if use jdbcurl like "jdbc:mysql:localhost:3307/sharding_db", will throw exception show "Datasource or ShardingSphere rule does not exist"
- try (Connection connection = DriverManager.getConnection(JDBC_URL_APPENDER.appendQueryProperties(getComposedContainer().getProxyJdbcUrl(""), queryProps), "root", "root")) {
- connection.createStatement().execute("USE sharding_db");
- addSourceResource(connection, "root", "root");
- }
- }
-
- protected void startIncrementTask(final KeyGenerateAlgorithm keyGenerateAlgorithm) {
- setIncreaseTaskThread(new Thread(new MySQLIncrementTaskRunnable(getJdbcTemplate(), extraSQLCommand, keyGenerateAlgorithm)));
- getIncreaseTaskThread().start();
- }
-
- /**
- * Add no use table, to test part of the table.
- */
- protected void createNoUseTable() {
- getJdbcTemplate().execute("CREATE SHARDING TABLE RULE no_use (RESOURCES(ds_0, ds_1), SHARDING_COLUMN=sharding_id, TYPE(NAME=MOD,PROPERTIES('sharding-count'=4)))");
- getJdbcTemplate().execute("CREATE TABLE no_use(id int(11) NOT NULL,sharding_id int(11) NOT NULL, PRIMARY KEY (id))");
- }
-
- @Override
- protected Properties createQueryProperties() {
- Properties result = new Properties();
- result.put("useSSL", Boolean.FALSE.toString());
- result.put("rewriteBatchedStatements", Boolean.TRUE.toString());
- result.put("serverTimezone", "UTC");
- return result;
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseOpenGaussITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseOpenGaussITCase.java
deleted file mode 100644
index e0d017563e6..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseOpenGaussITCase.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.integration.data.pipeline.cases.base;
-
-import lombok.Getter;
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
-import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
-import org.apache.shardingsphere.integration.data.pipeline.cases.common.PostgreSQLIncrementTaskRunnable;
-import org.apache.shardingsphere.integration.data.pipeline.framework.helper.ScalingTableSQLHelper;
-import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-
-import javax.xml.bind.JAXB;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-
-public abstract class BaseOpenGaussITCase extends BaseITCase {
-
- protected static final DatabaseType DATABASE_TYPE = new OpenGaussDatabaseType();
-
- @Getter
- private final ExtraSQLCommand extraSQLCommand;
-
- @Getter
- private final ScalingTableSQLHelper sqlHelper;
-
- public BaseOpenGaussITCase(final ScalingParameterized parameterized) {
- super(parameterized);
- extraSQLCommand = JAXB.unmarshal(BaseOpenGaussITCase.class.getClassLoader().getResource(parameterized.getScenario()), ExtraSQLCommand.class);
- sqlHelper = new ScalingTableSQLHelper(DATABASE_TYPE, extraSQLCommand, getJdbcTemplate());
- }
-
- // TODO add source resource should be common,after all problem be solved.
- @SneakyThrows(SQLException.class)
- protected void addSourceResource() {
- Properties queryProps = createQueryProperties();
- try (Connection connection = DriverManager.getConnection(JDBC_URL_APPENDER.appendQueryProperties(getComposedContainer().getProxyJdbcUrl("sharding_db"), queryProps), "root", "root")) {
- addSourceResource(connection, "gaussdb", "Root@123");
- }
- }
-
- protected void startIncrementTask(final KeyGenerateAlgorithm keyGenerateAlgorithm) {
- setIncreaseTaskThread(new Thread(new PostgreSQLIncrementTaskRunnable(getJdbcTemplate(), extraSQLCommand, keyGenerateAlgorithm)));
- getIncreaseTaskThread().start();
- }
-
- @Override
- protected Properties createQueryProperties() {
- Properties result = new Properties();
- result.put("useSSL", Boolean.FALSE.toString());
- result.put("serverTimezone", "UTC");
- result.put("preferQueryMode", "extendedForPrepared");
- return result;
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BasePostgreSQLITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BasePostgreSQLITCase.java
deleted file mode 100644
index f16535d0cad..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BasePostgreSQLITCase.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.integration.data.pipeline.cases.base;
-
-import lombok.Getter;
-import lombok.SneakyThrows;
-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.command.ExtraSQLCommand;
-import org.apache.shardingsphere.integration.data.pipeline.cases.common.PostgreSQLIncrementTaskRunnable;
-import org.apache.shardingsphere.integration.data.pipeline.framework.helper.ScalingTableSQLHelper;
-import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-
-import javax.xml.bind.JAXB;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-
-public abstract class BasePostgreSQLITCase extends BaseITCase {
-
- protected static final DatabaseType DATABASE_TYPE = new PostgreSQLDatabaseType();
-
- private final ExtraSQLCommand extraSQLCommand;
-
- @Getter
- private final ScalingTableSQLHelper sqlHelper;
-
- public BasePostgreSQLITCase(final ScalingParameterized parameterized) {
- super(parameterized);
- extraSQLCommand = JAXB.unmarshal(BasePostgreSQLITCase.class.getClassLoader().getResource(parameterized.getScenario()), ExtraSQLCommand.class);
- sqlHelper = new ScalingTableSQLHelper(DATABASE_TYPE, extraSQLCommand, getJdbcTemplate());
- }
-
- @SneakyThrows(SQLException.class)
- protected void addSourceResource() {
- Properties queryProps = createQueryProperties();
- try (Connection connection = DriverManager.getConnection(JDBC_URL_APPENDER.appendQueryProperties(getComposedContainer().getProxyJdbcUrl("sharding_db"), queryProps), "root", "root")) {
- addSourceResource(connection, "root", "root");
- }
- }
-
- protected void startIncrementTask(final KeyGenerateAlgorithm keyGenerateAlgorithm) {
- setIncreaseTaskThread(new Thread(new PostgreSQLIncrementTaskRunnable(getJdbcTemplate(), extraSQLCommand, keyGenerateAlgorithm)));
- getIncreaseTaskThread().start();
- }
-
- @Override
- protected Properties createQueryProperties() {
- Properties result = new Properties();
- result.put("useSSL", Boolean.FALSE.toString());
- result.put("serverTimezone", "UTC");
- result.put("preferQueryMode", "extendedForPrepared");
- return result;
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseTaskRunnable.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseTaskRunnable.java
deleted file mode 100644
index d363d791a09..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/base/BaseTaskRunnable.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.integration.data.pipeline.cases.base;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import java.time.Instant;
-
-@Getter
-@RequiredArgsConstructor
-@Slf4j
-public abstract class BaseTaskRunnable implements Runnable {
-
- private final JdbcTemplate jdbcTemplate;
-
- private final ExtraSQLCommand extraSQLCommand;
-
- private final KeyGenerateAlgorithm keyGenerateAlgorithm;
-
- protected abstract Object[] getOrderInsertData();
-
- protected abstract Object[] getOrderInsertItemData();
-
- protected abstract Object[] getOrderUpdateData(Object primaryKey);
-
- /**
- * Insert order.
- *
- * @return primary key of insert data
- */
- public Object insertOrder() {
- Object[] orderInsertDate = getOrderInsertData();
- jdbcTemplate.update(extraSQLCommand.getInsertOrder(), orderInsertDate);
- return orderInsertDate[0];
- }
-
- /**
- * Insert order item.
- *
- * @return primary key of insert data
- */
- public Object insertOrderItem() {
- Object[] orderInsertItemDate = getOrderInsertItemData();
- jdbcTemplate.update(extraSQLCommand.getInsertOrderItem(), orderInsertItemDate);
- return orderInsertItemDate[0];
- }
-
- /**
- * Update order by primary key.
- *
- * @param primaryKey primary key
- */
- public void updateOrderByPrimaryKey(final Object primaryKey) {
- jdbcTemplate.update(extraSQLCommand.getUpdateOrderById(), getOrderUpdateData(primaryKey));
- }
-
- /**
- * Update order item by primary key.
- *
- * @param primaryKey primary key
- */
- public void updateOrderItemByPrimaryKey(final Object primaryKey) {
- jdbcTemplate.update(extraSQLCommand.getUpdateOrderItemById(), "updated" + Instant.now().getEpochSecond(), primaryKey);
- }
-
- /**
- * Delete order by primary key.
- *
- * @param primaryKey primary key
- */
- public void deleteOrderByPrimaryKey(final Object primaryKey) {
- jdbcTemplate.update(extraSQLCommand.getDeleteOrderById(), primaryKey);
- }
-
- /**
- * Delete order by primary key.
- *
- * @param primaryKey primary key
- */
- public void deleteOrderItemByPrimaryKey(final Object primaryKey) {
- jdbcTemplate.update(extraSQLCommand.getDeleteOrderItemById(), primaryKey);
- }
-}
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 d89c3af1fd2..4b2a9bf78cf 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
@@ -50,8 +50,11 @@ public final class CommonSQLCommand {
@XmlElement(name = "alter-sharding-table-rule")
private String alterShardingTableRule;
- @XmlElement(name = "auto-alter-table-rule")
- private String autoAlterTableRule;
+ @XmlElement(name = "auto-alter-all-sharding-table-rule")
+ private String autoAlterAllShardingTableRule;
+
+ @XmlElement(name = "auto-alter-order-sharding-table-rule")
+ private String autoAlterOrderShardingTableRule;
@XmlElement(name = "source-add-resource-template")
private String sourceAddResourceTemplate;
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 4ccff9a6406..1b3788ca445 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
@@ -38,21 +38,6 @@ public final class ExtraSQLCommand {
@XmlElement(name = "full-insert-order")
private String fullInsertOrder;
- @XmlElement(name = "insert-order")
- private String insertOrder;
-
- @XmlElement(name = "insert-order-item")
- private String insertOrderItem;
-
- @XmlElement(name = "update-order-by-id")
- private String updateOrderById;
-
- @XmlElement(name = "update-order-item-by-id")
- private String updateOrderItemById;
-
- @XmlElement(name = "delete-order-by-id")
- private String deleteOrderById;
-
- @XmlElement(name = "delete-order-item-by-id")
- private String deleteOrderItemById;
+ @XmlElement(name = "full-insert-order-item")
+ private String fullInsertOrderItem;
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/common/MySQLIncrementTaskRunnable.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/common/MySQLIncrementTaskRunnable.java
deleted file mode 100644
index 529687a30d0..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/common/MySQLIncrementTaskRunnable.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.integration.data.pipeline.cases.common;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseTaskRunnable;
-import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import java.time.Instant;
-import java.util.concurrent.ThreadLocalRandom;
-
-@Slf4j
-public final class MySQLIncrementTaskRunnable extends BaseTaskRunnable {
-
- public MySQLIncrementTaskRunnable(final JdbcTemplate jdbcTemplate, final ExtraSQLCommand extraSQLCommand, final KeyGenerateAlgorithm keyGenerateAlgorithm) {
- super(jdbcTemplate, extraSQLCommand, keyGenerateAlgorithm);
- }
-
- @Override
- public void run() {
- int executeCount = 0;
- while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
- Object orderPrimaryKey = insertOrder();
- Object orderItemPrimaryKey = insertOrderItem();
- if (executeCount % 2 == 0) {
- deleteOrderByPrimaryKey(orderPrimaryKey);
- deleteOrderItemByPrimaryKey(orderItemPrimaryKey);
- } else {
- updateOrderByPrimaryKey(orderPrimaryKey);
- setFieldsToNull(orderPrimaryKey);
- updateOrderItemByPrimaryKey(orderItemPrimaryKey);
- }
- executeCount++;
- }
- log.info("MySQL increment task runnable execute successfully.");
- }
-
- private void setFieldsToNull(final Object primaryKey) {
- getJdbcTemplate().update(" UPDATE t_order SET t_unsigned_int = null WHERE id = ?", primaryKey);
- }
-
- @Override
- protected Object[] getOrderInsertData() {
- return new Object[]{getKeyGenerateAlgorithm().generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6)};
- }
-
- @Override
- protected Object[] getOrderInsertItemData() {
- return new Object[]{getKeyGenerateAlgorithm().generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6), "OK"};
- }
-
- @Override
- protected Object[] getOrderUpdateData(final Object primaryKey) {
- return new Object[]{"updated" + Instant.now().getEpochSecond(), ThreadLocalRandom.current().nextInt(0, 100), primaryKey};
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/common/PostgreSQLIncrementTaskRunnable.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/common/PostgreSQLIncrementTaskRunnable.java
deleted file mode 100644
index f457c88e64e..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/common/PostgreSQLIncrementTaskRunnable.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.integration.data.pipeline.cases.common;
-
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseTaskRunnable;
-import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
-import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import java.time.Instant;
-import java.util.concurrent.ThreadLocalRandom;
-
-@Slf4j
-public final class PostgreSQLIncrementTaskRunnable extends BaseTaskRunnable {
-
- public PostgreSQLIncrementTaskRunnable(final JdbcTemplate jdbcTemplate, final ExtraSQLCommand extraSQLCommand, final KeyGenerateAlgorithm keyGenerateAlgorithm) {
- super(jdbcTemplate, extraSQLCommand, keyGenerateAlgorithm);
- }
-
- @Override
- public void run() {
- int executeCount = 0;
- while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
- Object orderPrimaryKey = insertOrder();
- Object orderItemPrimaryKey = insertOrderItem();
- if (executeCount % 2 == 0) {
- deleteOrderByPrimaryKey(orderPrimaryKey);
- deleteOrderItemByPrimaryKey(orderItemPrimaryKey);
- } else {
- updateOrderByPrimaryKey(orderPrimaryKey);
- updateOrderItemByPrimaryKey(orderItemPrimaryKey);
- }
- executeCount++;
- }
- log.info("PostgreSQL increment task runnable execute successfully.");
- }
-
- @Override
- protected Object[] getOrderInsertData() {
- return new Object[]{getKeyGenerateAlgorithm().generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6)};
- }
-
- @Override
- protected Object[] getOrderInsertItemData() {
- return new Object[]{getKeyGenerateAlgorithm().generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6), "OK"};
- }
-
- @Override
- protected Object[] getOrderUpdateData(final Object primaryKey) {
- return new Object[]{"updated" + Instant.now().getEpochSecond(), primaryKey};
- }
-}
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/general/MySQLGeneralScalingIT.java
similarity index 59%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLManualScalingIT.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/MySQLGeneralScalingIT.java
index 1c45e88b36b..4d5573aa0d1 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/general/MySQLGeneralScalingIT.java
@@ -15,16 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.integration.data.pipeline.cases.mysql;
+package org.apache.shardingsphere.integration.data.pipeline.cases.general;
-import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseMySQLITCase;
-import org.apache.shardingsphere.integration.data.pipeline.cases.scenario.ScalingScenario;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseExtraSQLITCase;
+import org.apache.shardingsphere.integration.data.pipeline.cases.task.MySQLIncrementTask;
import org.apache.shardingsphere.integration.data.pipeline.env.IntegrationTestEnvironment;
+import org.apache.shardingsphere.integration.data.pipeline.framework.helper.ScalingCaseHelper;
import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -32,58 +33,55 @@ import org.junit.runners.Parameterized.Parameters;
import java.util.Collection;
import java.util.LinkedList;
-import java.util.concurrent.TimeUnit;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
/**
- * MySQL manual scaling test case.
+ * General scaling test case, includes multiple cases.
*/
@Slf4j
@RunWith(Parameterized.class)
-public final class MySQLManualScalingIT extends BaseMySQLITCase {
+public final class MySQLGeneralScalingIT extends BaseExtraSQLITCase {
private static final IntegrationTestEnvironment ENV = IntegrationTestEnvironment.getInstance();
- public MySQLManualScalingIT(final ScalingParameterized parameterized) {
+ private final ScalingParameterized parameterized;
+
+ public MySQLGeneralScalingIT(final ScalingParameterized parameterized) {
super(parameterized);
+ this.parameterized = parameterized;
+ log.info("parameterized:{}", parameterized);
}
@Parameters(name = "{0}")
public static Collection<ScalingParameterized> getParameters() {
Collection<ScalingParameterized> result = new LinkedList<>();
for (String version : ENV.getMysqlVersions()) {
- if (Strings.isNullOrEmpty(version)) {
- continue;
- }
- for (String scenario : ScalingScenario.listScenario()) {
- result.add(new ScalingParameterized(DATABASE_TYPE, version, String.join("/", "env/scenario/manual/mysql", scenario, ScalingScenario.SCENARIO_SUFFIX)));
- }
+ result.add(new ScalingParameterized(new MySQLDatabaseType(), version, "env/scenario/general/mysql.xml"));
}
return result;
}
- @Before
- public void setUp() throws InterruptedException {
+ @Test
+ public void assertManualScalingSuccess() throws InterruptedException {
addSourceResource();
initShardingAlgorithm();
- // TODO wait for algorithm init
- TimeUnit.SECONDS.sleep(3);
+ assertTrue(waitShardingAlgorithmEffect(15));
createScalingRule();
- }
-
- @Test
- public void assertManualScalingSuccess() throws InterruptedException {
createAllSharingTableRule();
bindingShardingRule();
createNoUseTable();
- getSqlHelper().createOrderTable();
- getSqlHelper().createOrderItemTable();
- getSqlHelper().initTableData(true);
- startIncrementTask(new SnowflakeKeyGenerateAlgorithm());
+ createOrderTable();
+ createOrderItemTable();
+ SnowflakeKeyGenerateAlgorithm keyGenerateAlgorithm = new SnowflakeKeyGenerateAlgorithm();
+ Pair<List<Object[]>, List<Object[]>> dataPair = ScalingCaseHelper.generateFullInsertData(keyGenerateAlgorithm, parameterized.getDatabaseType(), 3000);
+ getJdbcTemplate().batchUpdate(getExtraSQLCommand().getFullInsertOrder(), dataPair.getLeft());
+ getJdbcTemplate().batchUpdate(getExtraSQLCommand().getFullInsertOrderItem(), dataPair.getRight());
+ startIncrementTask(new MySQLIncrementTask(getJdbcTemplate(), keyGenerateAlgorithm, true));
assertOriginalSourceSuccess();
- addTargetSourceResource("root", "root");
- getJdbcTemplate().execute(getCommonSQLCommand().getAutoAlterTableRule());
- String jobId = String.valueOf(getJdbcTemplate().queryForMap("SHOW SCALING LIST").get("id"));
- getIncreaseTaskThread().join(60 * 1000L);
- assertCheckMatchConsistencySuccess(getJdbcTemplate(), jobId);
+ addTargetResource();
+ getJdbcTemplate().execute(getCommonSQLCommand().getAutoAlterAllShardingTableRule());
+ assertCheckMatchConsistencySuccess();
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/openguass/OpenGaussManualScalingIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/PostgreSQLGeneralScalingIT.java
similarity index 63%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/openguass/OpenGaussManualScalingIT.java
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/PostgreSQLGeneralScalingIT.java
index 5c65147cdb1..254f0505bb9 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/openguass/OpenGaussManualScalingIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/general/PostgreSQLGeneralScalingIT.java
@@ -15,17 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.integration.data.pipeline.cases.openguass;
+package org.apache.shardingsphere.integration.data.pipeline.cases.general;
-import com.google.common.base.Strings;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
-import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseOpenGaussITCase;
-import org.apache.shardingsphere.integration.data.pipeline.cases.scenario.ScalingScenario;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseExtraSQLITCase;
+import org.apache.shardingsphere.integration.data.pipeline.cases.task.PostgreSQLIncrementTask;
import org.apache.shardingsphere.integration.data.pipeline.env.IntegrationTestEnvironment;
import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
import org.apache.shardingsphere.integration.data.pipeline.util.TableCrudUtil;
import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -34,57 +35,56 @@ import org.junit.runners.Parameterized.Parameters;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import java.util.concurrent.TimeUnit;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * PostgreSQL general scaling test case. include openGauss type, same process.
+ */
+@Slf4j
@RunWith(Parameterized.class)
-public final class OpenGaussManualScalingIT extends BaseOpenGaussITCase {
+public final class PostgreSQLGeneralScalingIT extends BaseExtraSQLITCase {
private static final IntegrationTestEnvironment ENV = IntegrationTestEnvironment.getInstance();
- public OpenGaussManualScalingIT(final ScalingParameterized parameterized) {
+ private final ScalingParameterized parameterized;
+
+ public PostgreSQLGeneralScalingIT(final ScalingParameterized parameterized) {
super(parameterized);
+ this.parameterized = parameterized;
+ log.info("parameterized:{}", parameterized);
}
@Parameters(name = "{0}")
public static Collection<ScalingParameterized> getParameters() {
Collection<ScalingParameterized> result = new LinkedList<>();
+ for (String dockerImageName : ENV.getPostgresVersions()) {
+ result.add(new ScalingParameterized(new PostgreSQLDatabaseType(), dockerImageName, "env/scenario/general/postgresql.xml"));
+ }
for (String dockerImageName : ENV.getOpenGaussVersions()) {
- if (Strings.isNullOrEmpty(dockerImageName)) {
- continue;
- }
- for (String scenario : ScalingScenario.listScenario()) {
- result.add(new ScalingParameterized(DATABASE_TYPE, dockerImageName, String.join("/", "env/scenario/manual/postgresql", scenario, ScalingScenario.SCENARIO_SUFFIX)));
- }
+ result.add(new ScalingParameterized(new OpenGaussDatabaseType(), dockerImageName, "env/scenario/general/postgresql.xml"));
}
return result;
}
- @Before
- public void setUp() throws InterruptedException {
+ @Test
+ public void assertManualScalingSuccess() throws InterruptedException {
addSourceResource();
initShardingAlgorithm();
- // TODO wait for algorithm init
- TimeUnit.SECONDS.sleep(2);
+ assertTrue(waitShardingAlgorithmEffect(15));
createScalingRule();
createSchema("test");
- }
-
- @Test
- public void assertManualScalingSuccess() throws InterruptedException {
createAllSharingTableRule();
bindingShardingRule();
- getSqlHelper().createOrderTable();
- getSqlHelper().createOrderItemTable();
- getSqlHelper().initTableData(true);
+ createOrderTable();
+ createOrderItemTable();
Pair<List<Object[]>, List<Object[]>> dataPair = TableCrudUtil.generatePostgresSQLInsertDataList(3000);
getJdbcTemplate().batchUpdate(getExtraSQLCommand().getFullInsertOrder(), dataPair.getLeft());
- getJdbcTemplate().batchUpdate(getExtraSQLCommand().getInsertOrderItem(), dataPair.getRight());
- startIncrementTask(new SnowflakeKeyGenerateAlgorithm());
+ getJdbcTemplate().batchUpdate(getExtraSQLCommand().getFullInsertOrderItem(), dataPair.getRight());
+ startIncrementTask(new PostgreSQLIncrementTask(getJdbcTemplate(), new SnowflakeKeyGenerateAlgorithm(), "test", true));
assertOriginalSourceSuccess();
- addTargetSourceResource("gaussdb", "Root@123");
- getJdbcTemplate().execute(getCommonSQLCommand().getAutoAlterTableRule());
- String jobId = String.valueOf(getJdbcTemplate().queryForMap("SHOW SCALING LIST").get("id"));
- getIncreaseTaskThread().join(60 * 1000L);
- assertCheckMatchConsistencySuccess(getJdbcTemplate(), jobId);
+ addTargetResource();
+ getJdbcTemplate().execute(getCommonSQLCommand().getAutoAlterAllShardingTableRule());
+ assertCheckMatchConsistencySuccess();
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLDDLGeneratorIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLDDLGeneratorIT.java
index b05d4387288..2ca6de44bb4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLDDLGeneratorIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLDDLGeneratorIT.java
@@ -54,7 +54,7 @@ public final class PostgreSQLDDLGeneratorIT {
private static final String CASE_FILE_PATH = "ddlgenerator.xml";
- private static final String PARENT_PATH = "env/scenario/manual/postgresql/ddlgenerator";
+ private static final String PARENT_PATH = "env/scenario/ddlgenerator/postgresql";
private static final String DEFAULT_SCHEMA = "public";
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLManualScalingIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLManualScalingIT.java
deleted file mode 100644
index 169bbd43702..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLManualScalingIT.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.integration.data.pipeline.cases.postgresql;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.integration.data.pipeline.cases.base.BasePostgreSQLITCase;
-import org.apache.shardingsphere.integration.data.pipeline.cases.scenario.ScalingScenario;
-import org.apache.shardingsphere.integration.data.pipeline.env.IntegrationTestEnvironment;
-import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
-import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.concurrent.TimeUnit;
-
-@RunWith(Parameterized.class)
-public final class PostgreSQLManualScalingIT extends BasePostgreSQLITCase {
-
- private static final IntegrationTestEnvironment ENV = IntegrationTestEnvironment.getInstance();
-
- public PostgreSQLManualScalingIT(final ScalingParameterized parameterized) {
- super(parameterized);
- }
-
- @Parameters(name = "{0}")
- public static Collection<ScalingParameterized> getParameters() {
- Collection<ScalingParameterized> result = new LinkedList<>();
- for (String dockerImageName : ENV.getPostgresVersions()) {
- if (Strings.isNullOrEmpty(dockerImageName)) {
- continue;
- }
- for (String scenario : ScalingScenario.listScenario()) {
- result.add(new ScalingParameterized(DATABASE_TYPE, dockerImageName, String.join("/", "env/scenario/manual/postgresql", scenario, ScalingScenario.SCENARIO_SUFFIX)));
- }
- }
- return result;
- }
-
- @Before
- public void setUp() throws InterruptedException {
- addSourceResource();
- initShardingAlgorithm();
- // TODO wait for algorithm init
- TimeUnit.SECONDS.sleep(3);
- createScalingRule();
- createSchema("test");
- }
-
- @Test
- public void assertManualScalingSuccess() throws InterruptedException {
- createAllSharingTableRule();
- bindingShardingRule();
- getSqlHelper().createOrderTable();
- getSqlHelper().createOrderItemTable();
- getSqlHelper().initTableData(true);
- startIncrementTask(new SnowflakeKeyGenerateAlgorithm());
- assertOriginalSourceSuccess();
- addTargetSourceResource("root", "root");
- getJdbcTemplate().execute(getCommonSQLCommand().getAutoAlterTableRule());
- String jobId = String.valueOf(getJdbcTemplate().queryForMap("SHOW SCALING LIST").get("id"));
- getIncreaseTaskThread().join(60 * 1000L);
- assertCheckMatchConsistencySuccess(getJdbcTemplate(), jobId);
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/primarykey/TextPrimaryKeyScalingIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/primarykey/TextPrimaryKeyScalingIT.java
new file mode 100644
index 00000000000..4e5a6c25a26
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/primarykey/TextPrimaryKeyScalingIT.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.integration.data.pipeline.cases.primarykey;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseExtraSQLITCase;
+import org.apache.shardingsphere.integration.data.pipeline.env.IntegrationTestEnvironment;
+import org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
+import org.apache.shardingsphere.sharding.algorithm.keygen.UUIDKeyGenerateAlgorithm;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+
+import static org.junit.Assert.assertTrue;
+
+@Slf4j
+@RunWith(Parameterized.class)
+public class TextPrimaryKeyScalingIT extends BaseExtraSQLITCase {
+
+ private static final IntegrationTestEnvironment ENV = IntegrationTestEnvironment.getInstance();
+
+ public TextPrimaryKeyScalingIT(final ScalingParameterized parameterized) {
+ super(parameterized);
+ log.info("parameterized:{}", parameterized);
+ }
+
+ @Parameters(name = "{0}")
+ public static Collection<ScalingParameterized> getParameters() {
+ Collection<ScalingParameterized> result = new LinkedList<>();
+ for (String version : ENV.getMysqlVersions()) {
+ result.add(new ScalingParameterized(new MySQLDatabaseType(), version, "env/scenario/primarykey/text_primary_key/mysql.xml"));
+ }
+ for (String version : ENV.getPostgresVersions()) {
+ result.add(new ScalingParameterized(new PostgreSQLDatabaseType(), version, "env/scenario/primarykey/text_primary_key/postgresql.xml"));
+ }
+ for (String version : ENV.getOpenGaussVersions()) {
+ result.add(new ScalingParameterized(new OpenGaussDatabaseType(), version, "env/scenario/primarykey/text_primary_key/postgresql.xml"));
+ }
+ return result;
+ }
+
+ @Test
+ public void assertTextPrimaryKeyScalingSuccess() throws InterruptedException {
+ addSourceResource();
+ initShardingAlgorithm();
+ assertTrue(waitShardingAlgorithmEffect(15));
+ createScalingRule();
+ createOrderSharingTableRule();
+ createOrderTable();
+ batchInsertOrder();
+ assertOriginalSourceSuccess();
+ addTargetResource();
+ getJdbcTemplate().execute(getCommonSQLCommand().getAutoAlterOrderShardingTableRule());
+ assertCheckMatchConsistencySuccess();
+ }
+
+ private void batchInsertOrder() {
+ UUIDKeyGenerateAlgorithm keyGenerateAlgorithm = new UUIDKeyGenerateAlgorithm();
+ List<Object[]> orderData = new ArrayList<>(3000);
+ for (int i = 1; i <= 3000; i++) {
+ orderData.add(new Object[]{keyGenerateAlgorithm.generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6), "OK"});
+ }
+ getJdbcTemplate().batchUpdate("INSERT INTO t_order (id,order_id,user_id,status) VALUES (?,?,?,?)", orderData);
+ }
+}
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
new file mode 100644
index 00000000000..9cc83326244
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/task/MySQLIncrementTask.java
@@ -0,0 +1,80 @@
+/*
+ * 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.integration.data.pipeline.cases.task;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseIncrementTask;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.time.Instant;
+import java.util.concurrent.ThreadLocalRandom;
+
+@Slf4j
+@RequiredArgsConstructor
+public final class MySQLIncrementTask extends BaseIncrementTask {
+
+ private final JdbcTemplate jdbcTemplate;
+
+ private final KeyGenerateAlgorithm keyGenerateAlgorithm;
+
+ private final Boolean incrementOrderItemTogether;
+
+ @Override
+ public void run() {
+ int executeCount = 0;
+ while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
+ Object orderPrimaryKey = insertOrder();
+ if (executeCount % 2 == 0) {
+ jdbcTemplate.update("DELETE FROM t_order WHERE id = ?", orderPrimaryKey);
+ } else {
+ setNullToOrderFields(orderPrimaryKey);
+ updateOrderByPrimaryKey(orderPrimaryKey);
+ }
+ if (incrementOrderItemTogether) {
+ Object orderItemPrimaryKey = insertOrderItem();
+ jdbcTemplate.update("UPDATE t_order_item SET status = ? WHERE item_id = ?", "updated" + Instant.now().getEpochSecond(), orderItemPrimaryKey);
+ }
+ executeCount++;
+ }
+ log.info("MySQL increment task runnable execute successfully.");
+ }
+
+ private Object insertOrder() {
+ ThreadLocalRandom random = ThreadLocalRandom.current();
+ Object[] orderInsertDate = new Object[]{keyGenerateAlgorithm.generateKey(), random.nextInt(0, 6), random.nextInt(0, 6), random.nextInt(1, 99)};
+ jdbcTemplate.update("INSERT INTO t_order (id,order_id,user_id,t_unsigned_int) VALUES (?, ?, ?, ?)", orderInsertDate);
+ return orderInsertDate[0];
+ }
+
+ private Object insertOrderItem() {
+ Object[] orderInsertItemDate = new Object[]{keyGenerateAlgorithm.generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6), "OK"};
+ jdbcTemplate.update("INSERT INTO t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)", orderInsertItemDate);
+ return orderInsertItemDate[0];
+ }
+
+ 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);
+ }
+
+ private void setNullToOrderFields(final Object primaryKey) {
+ jdbcTemplate.update("UPDATE t_order SET status = 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/cases/task/PostgreSQLIncrementTask.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/task/PostgreSQLIncrementTask.java
new file mode 100644
index 00000000000..828f56f256a
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/task/PostgreSQLIncrementTask.java
@@ -0,0 +1,86 @@
+/*
+ * 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.integration.data.pipeline.cases.task;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.integration.data.pipeline.cases.base.BaseIncrementTask;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.time.Instant;
+import java.util.concurrent.ThreadLocalRandom;
+
+@Slf4j
+@RequiredArgsConstructor
+public final class PostgreSQLIncrementTask extends BaseIncrementTask {
+
+ private final JdbcTemplate jdbcTemplate;
+
+ private final KeyGenerateAlgorithm keyGenerateAlgorithm;
+
+ private final String schema;
+
+ private final boolean incrementOrderItemTogether;
+
+ @Override
+ public void run() {
+ int executeCount = 0;
+ while (executeCount < 20 && !Thread.currentThread().isInterrupted()) {
+ Object orderPrimaryKey = insertOrder();
+ if (executeCount % 2 == 0) {
+ jdbcTemplate.update(prefixSchema("DELETE FROM ${schema}t_order WHERE id = ?", schema), orderPrimaryKey);
+ } else {
+ updateOrderByPrimaryKey(orderPrimaryKey);
+ }
+ if (incrementOrderItemTogether) {
+ Object orderItemPrimaryKey = insertOrderItem();
+ jdbcTemplate.update(prefixSchema("UPDATE ${schema}t_order_item SET status = ? WHERE item_id = ?", schema), "updated" + Instant.now().getEpochSecond(), orderItemPrimaryKey);
+ jdbcTemplate.update(prefixSchema("DELETE FROM ${schema}t_order_item WHERE item_id = ?", schema), orderItemPrimaryKey);
+ }
+ executeCount++;
+ }
+ log.info("PostgreSQL increment task runnable execute successfully.");
+ }
+
+ private Object insertOrder() {
+ Object[] orderInsertDate = new Object[]{keyGenerateAlgorithm.generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6)};
+ jdbcTemplate.update(prefixSchema("INSERT INTO ${schema}t_order (id,order_id,user_id) VALUES (?, ?, ?)", schema), orderInsertDate);
+ return orderInsertDate[0];
+ }
+
+ private Object insertOrderItem() {
+ Object[] orderInsertItemDate = new Object[]{keyGenerateAlgorithm.generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6), "OK"};
+ jdbcTemplate.update(prefixSchema("INSERT INTO ${schema}t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)", schema), orderInsertItemDate);
+ return orderInsertItemDate[0];
+ }
+
+ private void updateOrderByPrimaryKey(final Object primaryKey) {
+ Object[] updateData = {"updated" + Instant.now().getEpochSecond(), primaryKey};
+ jdbcTemplate.update(prefixSchema("UPDATE ${schema}t_order SET status = ? WHERE id = ?", schema), updateData);
+ }
+
+ private String prefixSchema(final String sql, final String schema) {
+ if (StringUtils.isNotBlank(schema)) {
+ return sql.replace("${schema}", schema + ".");
+ } else {
+ return sql.replace("${schema}", "");
+ }
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java
index 82399d46dc3..4e33512c060 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/env/IntegrationTestEnvironment.java
@@ -17,15 +17,17 @@
package org.apache.shardingsphere.integration.data.pipeline.env;
-import com.google.common.base.Splitter;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.integration.data.pipeline.env.enums.ITEnvTypeEnum;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Arrays;
import java.util.List;
import java.util.Properties;
+import java.util.stream.Collectors;
@Getter
@Slf4j
@@ -46,9 +48,9 @@ public final class IntegrationTestEnvironment {
private IntegrationTestEnvironment() {
props = loadProperties();
itEnvType = ITEnvTypeEnum.valueOf(props.getProperty("it.cluster.env.type", ITEnvTypeEnum.DOCKER.name()).toUpperCase());
- mysqlVersions = Splitter.on(",").trimResults().splitToList(props.getOrDefault("it.env.mysql.version", "").toString());
- postgresVersions = Splitter.on(",").trimResults().splitToList(props.getOrDefault("it.env.postgresql.version", "").toString());
- openGaussVersions = Splitter.on(",").trimResults().splitToList(props.getOrDefault("it.env.opengauss.version", "").toString());
+ mysqlVersions = Arrays.stream(props.getOrDefault("it.env.mysql.version", "").toString().split(",")).filter(StringUtils::isNotBlank).collect(Collectors.toList());
+ postgresVersions = Arrays.stream(props.getOrDefault("it.env.postgresql.version", "").toString().split(",")).filter(StringUtils::isNotBlank).collect(Collectors.toList());
+ openGaussVersions = Arrays.stream(props.getOrDefault("it.env.opengauss.version", "").toString().split(",")).filter(StringUtils::isNotBlank).collect(Collectors.toList());
}
private Properties loadProperties() {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/ITWatcher.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/ITWatcher.java
deleted file mode 100644
index 4af93ba231e..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/ITWatcher.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.integration.data.pipeline.framework;
-
-import lombok.extern.slf4j.Slf4j;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-/**
- * Integration test watcher.
- */
-@Slf4j
-public final class ITWatcher extends TestWatcher {
-
- @Override
- protected void failed(final Throwable cause, final Description description) {
- log.error("Error case: {}, message: {}", description.getMethodName(), getStackTrace(cause));
- super.failed(cause, description);
- }
-
- private String getStackTrace(final Throwable cause) {
- if (null == cause) {
- return "";
- }
- try (
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(out)) {
- cause.printStackTrace(printStream);
- printStream.flush();
- return out.toString();
- // CHECKSTYLE:OFF
- } catch (final Exception ignored) {
- // CHECKSTYLE:ON
- return "";
- }
- }
-}
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
new file mode 100644
index 00000000000..532ca623a4a
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingCaseHelper.java
@@ -0,0 +1,123 @@
+/*
+ * 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.integration.data.pipeline.framework.helper;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shardingsphere.infra.database.metadata.url.JdbcUrlAppender;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
+
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Scaling case helper, some config is different between different database.
+ */
+public final class ScalingCaseHelper {
+
+ private static final JdbcUrlAppender JDBC_URL_APPENDER = new JdbcUrlAppender();
+
+ private static final String CUSTOM_SCHEMA = "test";
+
+ /**
+ * Get query properties by database type.
+ *
+ * @param databaseType database type
+ * @return query properties
+ */
+ public static Properties getQueryPropertiesByDatabaseType(final DatabaseType databaseType) {
+ Properties result = new Properties();
+ if (databaseType instanceof MySQLDatabaseType) {
+ result.put("useSSL", Boolean.FALSE.toString());
+ result.put("rewriteBatchedStatements", Boolean.TRUE.toString());
+ result.put("serverTimezone", "UTC");
+ return result;
+ }
+ if (databaseType instanceof PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType) {
+ result.put("useSSL", Boolean.FALSE.toString());
+ result.put("serverTimezone", "UTC");
+ result.put("preferQueryMode", "extendedForPrepared");
+ return result;
+ }
+ return result;
+ }
+
+ /**
+ * Generate MySQL insert data, contains full fields.
+ *
+ * @param keyGenerateAlgorithm key generate algorithm
+ * @param databaseType database type
+ * @param insertRows insert rows
+ * @return insert data list
+ */
+ public static Pair<List<Object[]>, List<Object[]>> generateFullInsertData(final KeyGenerateAlgorithm keyGenerateAlgorithm, final DatabaseType databaseType, final int insertRows) {
+ if (insertRows < 0) {
+ return Pair.of(null, null);
+ }
+ List<Object[]> orderData = new ArrayList<>(insertRows);
+ List<Object[]> orderItemData = new ArrayList<>(insertRows);
+ ThreadLocalRandom current = ThreadLocalRandom.current();
+ for (int i = 0; i <= insertRows; i++) {
+ int orderId = current.nextInt(0, 6);
+ int userId = current.nextInt(0, 6);
+ if (databaseType instanceof MySQLDatabaseType) {
+ orderData.add(new Object[]{keyGenerateAlgorithm.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(), "{}",
+ current.nextInt(0, 10000000)});
+ } else {
+ orderData.add(new Object[]{keyGenerateAlgorithm.generateKey(), ThreadLocalRandom.current().nextInt(0, 6), ThreadLocalRandom.current().nextInt(0, 6), "OK"});
+ }
+ orderItemData.add(new Object[]{keyGenerateAlgorithm.generateKey(), orderId, userId, "SUCCESS"});
+ }
+ return Pair.of(orderData, orderItemData);
+ }
+
+ /**
+ * Get username by database type.
+ *
+ * @param databaseType database type
+ * @return username
+ */
+ public static String getUsername(final DatabaseType databaseType) {
+ if (databaseType instanceof OpenGaussDatabaseType) {
+ return "gaussdb";
+ }
+ return "root";
+ }
+
+ /**
+ * Get password by database type.
+ *
+ * @param databaseType database type
+ * @return username
+ */
+ public static String getPassword(final DatabaseType databaseType) {
+ if (databaseType instanceof OpenGaussDatabaseType) {
+ return "Root@123";
+ }
+ return "root";
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingTableSQLHelper.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingTableSQLHelper.java
deleted file mode 100644
index 0bfce120ec2..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/helper/ScalingTableSQLHelper.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.integration.data.pipeline.framework.helper;
-
-import lombok.AllArgsConstructor;
-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.infra.database.type.dialect.OpenGaussDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.integration.data.pipeline.cases.command.ExtraSQLCommand;
-import org.apache.shardingsphere.integration.data.pipeline.util.TableCrudUtil;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import java.util.List;
-
-/**
- * SQL helper.
- */
-@AllArgsConstructor
-public final class ScalingTableSQLHelper {
-
- private final DatabaseType databaseType;
-
- private final ExtraSQLCommand extraSQLCommand;
-
- private final JdbcTemplate jdbcTemplate;
-
- /**
- * Create order table.
- */
- public void createOrderTable() {
- jdbcTemplate.execute(extraSQLCommand.getCreateTableOrder());
- }
-
- /**
- * Create order item table.
- */
- public void createOrderItemTable() {
- jdbcTemplate.execute(extraSQLCommand.getCreateTableOrderItem());
- }
-
- /**
- * Init table data.
- *
- * @param initOrderItemTogether whether init order item table together
- */
- public void initTableData(final boolean initOrderItemTogether) {
- Pair<List<Object[]>, List<Object[]>> dataPair = Pair.of(null, null);
- if (databaseType instanceof MySQLDatabaseType) {
- dataPair = TableCrudUtil.generateMySQLInsertDataList(3000);
- } else if (databaseType instanceof PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType) {
- dataPair = TableCrudUtil.generatePostgresSQLInsertDataList(3000);
- }
- jdbcTemplate.batchUpdate(extraSQLCommand.getFullInsertOrder(), dataPair.getLeft());
- if (initOrderItemTogether) {
- jdbcTemplate.batchUpdate(extraSQLCommand.getInsertOrderItem(), dataPair.getRight());
- }
- }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/param/ScalingParameterized.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/param/ScalingParameterized.java
index e3c5c0f185c..f4ebe6c4962 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/param/ScalingParameterized.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/param/ScalingParameterized.java
@@ -19,10 +19,12 @@ package org.apache.shardingsphere.integration.data.pipeline.framework.param;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import lombok.ToString;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
@Getter
@RequiredArgsConstructor
+@ToString
public final class ScalingParameterized {
private final DatabaseType databaseType;
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 f4af6301a93..293e40d380a 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
@@ -31,10 +31,8 @@ public final class TableCrudUtil {
private static final SnowflakeKeyGenerateAlgorithm SNOWFLAKE_GENERATE = new SnowflakeKeyGenerateAlgorithm();
- private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();
-
/**
- * Generate MySQL insert data.
+ * Generate MySQL insert data, contains full fields.
*
* @param insertRows insert rows
* @return insert data list
@@ -45,18 +43,19 @@ public final class TableCrudUtil {
}
List<Object[]> orderData = new ArrayList<>(insertRows);
List<Object[]> orderItemData = new ArrayList<>(insertRows);
- for (int i = 1; i <= insertRows; i++) {
- int orderId = RANDOM.nextInt(0, 5);
- int userId = RANDOM.nextInt(0, 5);
+ ThreadLocalRandom current = ThreadLocalRandom.current();
+ for (int i = 0; i <= insertRows; i++) {
+ int orderId = current.nextInt(0, 6);
+ int userId = current.nextInt(0, 6);
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(), "{}", RANDOM.nextInt(0, 10000000)});
+ "hello".getBytes(StandardCharsets.UTF_8), null, new BigDecimal("100.00"), "test", Math.random(), "{}", current.nextInt(0, 10000000)});
orderItemData.add(new Object[]{SNOWFLAKE_GENERATE.generateKey(), orderId, userId, "SUCCESS"});
}
return Pair.of(orderData, orderItemData);
}
/**
- * Generate PostgreSQL simple insert data.
+ * Generate PostgreSQL insert data, contains full fields.
*
* @param insertRows insert rows
* @return insert data
@@ -65,8 +64,8 @@ public final class TableCrudUtil {
List<Object[]> orderData = new ArrayList<>(insertRows);
List<Object[]> orderItemData = new ArrayList<>(insertRows);
for (int i = 1; i <= insertRows; i++) {
- int orderId = RANDOM.nextInt(0, 5);
- int userId = RANDOM.nextInt(0, 5);
+ int orderId = ThreadLocalRandom.current().nextInt(0, 6);
+ int userId = ThreadLocalRandom.current().nextInt(0, 6);
orderData.add(new Object[]{SNOWFLAKE_GENERATE.generateKey(), orderId, userId, "OK"});
orderItemData.add(new Object[]{SNOWFLAKE_GENERATE.generateKey(), orderId, userId, "SUCCESS"});
}
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 39cf89cd8a8..c142b08a428 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
@@ -72,7 +72,7 @@
KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=snowflake)))
</alter-sharding-table-rule>
- <auto-alter-table-rule>
+ <auto-alter-all-sharding-table-rule>
ALTER SHARDING TABLE RULE t_order(
RESOURCES(ds_2, ds_3, ds_4),
SHARDING_COLUMN=order_id,
@@ -84,7 +84,16 @@
TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=6)),
KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=snowflake))
)
- </auto-alter-table-rule>
+ </auto-alter-all-sharding-table-rule>
+
+ <auto-alter-order-sharding-table-rule>
+ ALTER SHARDING TABLE RULE t_order(
+ RESOURCES(ds_2, ds_3, ds_4),
+ SHARDING_COLUMN=order_id,
+ TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=6)),
+ KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=snowflake))
+ )
+ </auto-alter-order-sharding-table-rule>
<source-add-resource-template>
ADD RESOURCE ds_0 (
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/ddlgenerator/ddlgenerator.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/ddlgenerator/postgresql/ddlgenerator.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/ddlgenerator/ddlgenerator.xml
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/ddlgenerator/postgresql/ddlgenerator.xml
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/integer_primary_key/sql.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/general/mysql.xml
similarity index 68%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/integer_primary_key/sql.xml
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/general/mysql.xml
index d497c549081..4d10f42f791 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/integer_primary_key/sql.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/general/mysql.xml
@@ -47,46 +47,10 @@
</create-table-order-item>
<full-insert-order>
- INSERT INTO t_order (
- id,
- order_id,
- user_id,
- status,
- t_tinyint,
- t_timestamp,
- t_datetime,
- t_binary,
- t_blob,
- t_decimal,
- t_char,
- t_double,
- t_json,
- t_unsigned_int
- )
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
+ INSERT INTO t_order ( id, order_id, user_id, status, t_tinyint, t_timestamp, t_datetime, t_binary, t_blob, t_decimal, t_char, t_double, t_json, t_unsigned_int ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
</full-insert-order>
- <insert-order>
- INSERT INTO t_order (id,order_id,user_id) VALUES (?, ?, ?)
- </insert-order>
-
- <insert-order-item>
+ <full-insert-order-item>
INSERT INTO t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)
- </insert-order-item>
-
- <update-order-by-id>
- UPDATE t_order SET status = ?,t_unsigned_int = ? WHERE id = ?
- </update-order-by-id>
-
- <update-order-item-by-id>
- UPDATE t_order_item SET status = ? WHERE item_id = ?
- </update-order-item-by-id>
-
- <delete-order-by-id>
- DELETE FROM t_order WHERE id = ?
- </delete-order-by-id>
-
- <delete-order-item-by-id>
- DELETE FROM t_order_item WHERE item_id = ?
- </delete-order-item-by-id>
+ </full-insert-order-item>
</command>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/integer_primary_key/sql.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/general/postgresql.xml
similarity index 71%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/integer_primary_key/sql.xml
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/general/postgresql.xml
index 67e70819739..82ba676360b 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/integer_primary_key/sql.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/general/postgresql.xml
@@ -39,27 +39,7 @@
INSERT INTO test.t_order(id, order_id, user_id, status) VALUES (?,?,?,?)
</full-insert-order>
- <insert-order>
- INSERT INTO test.t_order ( id, order_id, user_id) VALUES (?, ?, ?)
- </insert-order>
-
- <insert-order-item>
+ <full-insert-order-item>
INSERT INTO test.t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)
- </insert-order-item>
-
- <update-order-by-id>
- UPDATE test.t_order SET status = ? WHERE id = ?
- </update-order-by-id>
-
- <update-order-item-by-id>
- UPDATE test.t_order_item SET status = ? WHERE item_id = ?
- </update-order-item-by-id>
-
- <delete-order-by-id>
- DELETE FROM test.t_order WHERE id = ?
- </delete-order-by-id>
-
- <delete-order-item-by-id>
- DELETE FROM test.t_order_item WHERE item_id = ?
- </delete-order-item-by-id>
+ </full-insert-order-item>
</command>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/text_primary_key/sql.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/primarykey/text_primary_key/mysql.xml
similarity index 58%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/text_primary_key/sql.xml
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/primarykey/text_primary_key/mysql.xml
index 972c049c6ec..8e4e8586c02 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/mysql/text_primary_key/sql.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/primarykey/text_primary_key/mysql.xml
@@ -20,35 +20,10 @@
`id` varchar(255) NOT NULL COMMENT 'pk id',
`order_id` INT NOT NULL,
`user_id` INT NOT NULL,
- `update_date` DATETIME NULL,
+ `status` varchar(255) NULL,
+ `t_unsigned_int` int UNSIGNED NULL,
PRIMARY KEY ( `id` ),
INDEX ( `order_id` )
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
</create-table-order>
-
- <create-table-order-item>
- CREATE TABLE t_order_item (
- item_id bigint NOT NULL,
- order_id int NOT NULL,
- user_id int NOT NULL,
- status varchar(50) DEFAULT NULL,
- PRIMARY KEY (item_id)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
- </create-table-order-item>
-
- <insert-order>
- INSERT INTO t_order (id,order_id,user_id) VALUES (?, ?, ?)
- </insert-order>
-
- <insert-order-item>
- INSERT INTO t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)
- </insert-order-item>
-
- <delete-order-by-id>
- DELETE FROM t_order WHERE id = ?
- </delete-order-by-id>
-
- <delete-order-item-by-id>
- DELETE FROM t_order_item WHERE item_id = ?
- </delete-order-item-by-id>
</command>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/text_primary_key/sql.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/primarykey/text_primary_key/postgresql.xml
similarity index 80%
rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/text_primary_key/sql.xml
rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/primarykey/text_primary_key/postgresql.xml
index fdc7bbb7c17..56539e1b29a 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/manual/postgresql/text_primary_key/sql.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/scenario/primarykey/text_primary_key/postgresql.xml
@@ -16,19 +16,12 @@
-->
<command>
<create-table-order>
- CREATE TABLE test.t_order (
+ CREATE TABLE t_order (
id varchar(255) NOT NULL,
order_id int4 NOT NULL,
user_id int NOT NULL,
+ status varchar(255) NULL,
PRIMARY KEY (id)
)
</create-table-order>
-
- <full-insert-order>
- INSERT INTO t_order (id,order_id,user_id) VALUES (?, ?, ?)
- </full-insert-order>
-
- <delete-order-by-id>
- DELETE FROM t_order WHERE id = ?
- </delete-order-by-id>
</command>