You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/12/02 03:24:12 UTC
[shardingsphere] branch master updated: Revise 22557 (#22580)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 1cf962bc796 Revise 22557 (#22580)
1cf962bc796 is described below
commit 1cf962bc796024b5734ad20ee60e5a9e6aad38d9
Author: Hongsheng Zhong <zh...@apache.org>
AuthorDate: Fri Dec 2 11:24:01 2022 +0800
Revise 22557 (#22580)
* Fix ShardingSphereDriverURL.toConfigurationBytes ignore newline
* Improve ShardingSphereDriverTest
---
.../jdbc/core/driver/ShardingSphereDriverURL.java | 2 +-
.../driver/ShardingSphereDriverTest.java | 19 +++++++++--
.../core/driver/ShardingSphereDriverURLTest.java | 8 +++--
.../config/driver/foo-driver-fixture.yaml | 39 ++++++++++++++++++++++
4 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java
index 9b496a56737..a16387aa8a5 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java
@@ -66,7 +66,7 @@ public final class ShardingSphereDriverURL {
String line;
while ((line = reader.readLine()) != null) {
if (!line.startsWith("#")) {
- builder.append(line);
+ builder.append(line).append('\n');
}
}
return builder.toString().getBytes(StandardCharsets.UTF_8);
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java
index 5f850c9b9db..b5b1b36b58f 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/ShardingSphereDriverTest.java
@@ -22,10 +22,14 @@ import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
public final class ShardingSphereDriverTest {
@@ -35,9 +39,18 @@ public final class ShardingSphereDriverTest {
}
@Test
- public void assertConnect() throws SQLException {
- try (Connection actual = DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml")) {
- assertThat(actual, instanceOf(ShardingSphereConnection.class));
+ public void assertDriverWorks() throws SQLException {
+ try (
+ Connection connection = DriverManager.getConnection("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml");
+ Statement statement = connection.createStatement()) {
+ assertThat(connection, instanceOf(ShardingSphereConnection.class));
+ statement.execute("DROP TABLE IF EXISTS t_order");
+ statement.execute("CREATE TABLE t_order (order_id INT PRIMARY KEY, user_id INT)");
+ statement.execute("INSERT INTO t_order (order_id, user_id) VALUES (1, 101), (2, 102)");
+ try (ResultSet resultSet = statement.executeQuery("SELECT COUNT(1) FROM t_order")) {
+ assertTrue(resultSet.next());
+ assertThat(resultSet.getInt(1), is(2));
+ }
}
}
}
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java
index 43e684965d5..377ee61cd42 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java
@@ -26,6 +26,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
public final class ShardingSphereDriverURLTest {
+ private final int fooDriverConfigLength = 995;
+
@Test(expected = IllegalArgumentException.class)
public void assertNewConstructorWithEmptyURL() {
new ShardingSphereDriverURL("jdbc:shardingsphere:");
@@ -34,20 +36,20 @@ public final class ShardingSphereDriverURLTest {
@Test
public void assertToClasspathConfigurationFile() {
ShardingSphereDriverURL actual = new ShardingSphereDriverURL("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml");
- assertThat(actual.toConfigurationBytes().length, is(35));
+ assertThat(actual.toConfigurationBytes().length, is(fooDriverConfigLength));
}
@Test
public void assertToConfigurationFile() {
String absolutePath = Objects.requireNonNull(ShardingSphereDriverURLTest.class.getClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
ShardingSphereDriverURL actual = new ShardingSphereDriverURL("jdbc:shardingsphere:" + absolutePath);
- assertThat(actual.toConfigurationBytes().length, is(35));
+ assertThat(actual.toConfigurationBytes().length, is(fooDriverConfigLength));
}
@Test
public void assertToConfigurationFileWithOtherParameters() {
String absolutePath = Objects.requireNonNull(ShardingSphereDriverURLTest.class.getClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
ShardingSphereDriverURL actual = new ShardingSphereDriverURL("jdbc:shardingsphere:" + absolutePath + "?xxx=xxx&yyy=yyy");
- assertThat(actual.toConfigurationBytes().length, is(35));
+ assertThat(actual.toConfigurationBytes().length, is(fooDriverConfigLength));
}
}
diff --git a/jdbc/core/src/test/resources/config/driver/foo-driver-fixture.yaml b/jdbc/core/src/test/resources/config/driver/foo-driver-fixture.yaml
index 51c73d240b1..98e72e43eb7 100644
--- a/jdbc/core/src/test/resources/config/driver/foo-driver-fixture.yaml
+++ b/jdbc/core/src/test/resources/config/driver/foo-driver-fixture.yaml
@@ -16,3 +16,42 @@
#
databaseName: foo_driver_fixture_db
+
+dataSources:
+ ds_0:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: org.h2.Driver
+ jdbcUrl: jdbc:h2:mem:foo_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+ username: sa
+ password:
+ ds_1:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: org.h2.Driver
+ jdbcUrl: jdbc:h2:mem:foo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL
+ username: sa
+ password:
+
+rules:
+ - !SHARDING
+ autoTables:
+ t_order:
+ actualDataSources: ds_0,ds_1
+ shardingStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: auto-mod
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ shardingAlgorithms:
+ auto-mod:
+ type: MOD
+ props:
+ sharding-count: 2
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+props:
+ sql-show: true