You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by do...@apache.org on 2020/06/12 10:47:17 UTC
[shardingsphere] branch master updated: Add auto table integrated
tests (#6017)
This is an automated email from the ASF dual-hosted git repository.
dongzonglei 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 44cbee0 Add auto table integrated tests (#6017)
44cbee0 is described below
commit 44cbee04357bc76836079ad1e4ff4bdc5dd9037b
Author: Juan Pan(Trista) <pa...@apache.org>
AuthorDate: Fri Jun 12 18:47:03 2020 +0800
Add auto table integrated tests (#6017)
* Add auto table integrated tests
* change import
* fix test
---
.../sharding/rule/TableRuleTest.java | 1 +
.../ShardingSpherePreparedStatementTest.java | 33 ++++++++++++++++++++++
.../src/test/resources/config-sharding.yaml | 20 ++++++++++++-
.../src/test/resources/jdbc_data.sql | 11 ++++++++
.../src/test/resources/jdbc_init.sql | 6 ++++
5 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
index f44e99e..9c1cc97 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
@@ -37,6 +37,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Properties;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatementTest.java
index fef9972..2eedda6 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatementTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatementTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.driver.jdbc.core.statement;
+import com.google.common.collect.Lists;
import org.apache.shardingsphere.driver.common.base.AbstractShardingSphereDataSourceForShardingTest;
import org.apache.shardingsphere.driver.fixture.ResetIncrementKeyGenerateAlgorithm;
import org.junit.Ignore;
@@ -27,8 +28,10 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.Collection;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
@@ -52,8 +55,12 @@ public final class ShardingSpherePreparedStatementTest extends AbstractShardingS
private static final String SELECT_SQL_WITH_PARAMETER_MARKER_RETURN_STATUS = "SELECT item_id, user_id, status FROM t_order_item WHERE order_id= ? AND user_id = ?";
+ private static final String SELECT_AUTO_SQL = "SELECT item_id, order_id, status FROM t_order_item_auto WHERE order_id >= ?";
+
private static final String UPDATE_SQL = "UPDATE t_order SET status = ? WHERE user_id = ? AND order_id = ?";
+ private static final String UPDATE_AUTO_SQL = "UPDATE t_order_auto SET status = ? WHERE order_id = ?";
+
private static final String UPDATE_BATCH_SQL = "UPDATE t_order SET status=? WHERE status=?";
@Test
@@ -434,6 +441,32 @@ public final class ShardingSpherePreparedStatementTest extends AbstractShardingS
}
@Test
+ public void assertExecuteUpdateAutoTableGetResultSet() throws SQLException {
+ try (PreparedStatement preparedStatement = getShardingSphereDataSource().getConnection().prepareStatement(UPDATE_AUTO_SQL)) {
+ preparedStatement.setString(1, "OK");
+ preparedStatement.setInt(2, 10);
+ preparedStatement.executeUpdate();
+ assertNull(preparedStatement.getResultSet());
+ }
+ }
+
+ @Test
+ public void assertExecuteSelectAutoTableGetResultSet() throws SQLException {
+ Collection<Integer> result = Lists.newArrayList(1001, 1100, 1101);
+ try (PreparedStatement preparedStatement = getShardingSphereDataSource().getConnection().prepareStatement(SELECT_AUTO_SQL)) {
+ preparedStatement.setInt(1, 1001);
+ int count = 0;
+ try (ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ result.contains(resultSet.getInt(2));
+ count++;
+ }
+ }
+ assertEquals(result.size(), count);
+ }
+ }
+
+ @Test
public void assertClearBatch() throws SQLException {
try (
Connection connection = getShardingSphereDataSource().getConnection();
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config-sharding.yaml b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config-sharding.yaml
index f897e7c..0e51a5a 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config-sharding.yaml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/config-sharding.yaml
@@ -39,6 +39,24 @@ rules:
keyGenerateStrategy:
column: id
keyGeneratorName: reset_increment
+ autoTables:
+ t_order_auto:
+ actualDataSources: jdbc_0, jdbc_1
+ shardingStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithm:
+ type: MOD
+ props:
+ mod.value: 2
+ t_order_item_auto:
+ shardingStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithm:
+ type: MOD
+ props:
+ mod.value: 2
bindingTables:
- t_order,t_order_item
broadcastTables:
@@ -53,7 +71,7 @@ rules:
shardingColumn: user_id
shardingAlgorithm:
type: STANDARD_TEST
-
+
keyGenerators:
increment:
type: INCREMENT
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_data.sql b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_data.sql
index 66d629d..dd6424f 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_data.sql
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_data.sql
@@ -17,7 +17,10 @@
DELETE FROM t_order;
DELETE FROM t_order_item;
+DELETE FROM t_order_auto;
+DELETE FROM t_order_item_auto;
DELETE FROM t_config;
+
INSERT INTO t_order VALUES(1000, 10, 'init');
INSERT INTO t_order VALUES(1001, 10, 'init');
INSERT INTO t_order VALUES(1100, 11, 'init');
@@ -30,4 +33,12 @@ INSERT INTO t_order_item VALUES(110000, 1100, 11, 'init');
INSERT INTO t_order_item VALUES(110001, 1100, 11, 'init');
INSERT INTO t_order_item VALUES(110100, 1101, 11, 'init');
INSERT INTO t_order_item VALUES(110101, 1101, 11, 'init');
+
+INSERT INTO t_order_auto VALUES(1000, 10, 'init');
+INSERT INTO t_order_auto VALUES(1100, 11, 'init');
+INSERT INTO t_order_item_auto VALUES(100000, 1000, 10, 'init');
+INSERT INTO t_order_item_auto VALUES(100100, 1001, 10, 'init');
+INSERT INTO t_order_item_auto VALUES(110000, 1100, 11, 'init');
+INSERT INTO t_order_item_auto VALUES(110100, 1101, 11, 'init');
+
INSERT INTO t_config VALUES(1, 'init');
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_init.sql b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_init.sql
index 514edaa..4e129c1 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_init.sql
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/jdbc_init.sql
@@ -19,6 +19,12 @@ CREATE TABLE IF NOT EXISTS t_order_0 (order_id INT NOT NULL, user_id INT NOT NUL
CREATE TABLE IF NOT EXISTS t_order_1 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE IF NOT EXISTS t_order_item_0 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE IF NOT EXISTS t_order_item_1 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
+
+CREATE TABLE IF NOT EXISTS t_order_auto_0 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
+CREATE TABLE IF NOT EXISTS t_order_auto_1 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
+CREATE TABLE IF NOT EXISTS t_order_item_auto_0 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
+CREATE TABLE IF NOT EXISTS t_order_item_auto_1 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
+
CREATE TABLE IF NOT EXISTS t_config (id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (id));
CREATE TABLE IF NOT EXISTS t_global (id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (id));
CREATE TABLE IF NOT EXISTS t_encrypt (id INT NOT NULL AUTO_INCREMENT, cipher_pwd VARCHAR(45) NULL, plain_pwd VARCHAR(45), PRIMARY KEY (id));