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 2020/08/05 05:33:31 UTC

[shardingsphere] branch master updated: refactor the example for XA JDBC example (#6602)

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

zhangliang 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 6e2324f  refactor the example for XA JDBC example (#6602)
6e2324f is described below

commit 6e2324f3fce3820c6361c8d9cf140f1d9a247418
Author: 孙念君 Sun Nianjun <su...@huobi.com>
AuthorDate: Wed Aug 5 13:33:18 2020 +0800

    refactor the example for XA JDBC example (#6602)
    
    * Add: add H2 config for xa testing
    
    * Refactor: update the test case for xa raw jdbc (#5841)
    
    * Add: add final modifier for class
    
    * Add: add back the indent (#5841)
---
 examples/pom.xml                                   |  9 ++-
 .../xa/raw/jdbc/XAOrderServiceTest.java            |  2 +-
 .../sharding-databases-tables-postgresql.yaml      | 65 +++++++++++++++++++++
 .../META-INF/sharding-databases-tables.yaml        | 68 ++++++++++++++++++++++
 4 files changed, 142 insertions(+), 2 deletions(-)

diff --git a/examples/pom.xml b/examples/pom.xml
index 03b34ed..c3ff6b4 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -46,6 +46,7 @@
         <hikari-cp.version>2.4.11</hikari-cp.version>
         <mysql-connector-java.version>5.1.42</mysql-connector-java.version>
         <postgresql.version>42.2.5.jre7</postgresql.version>
+        <h2.version>1.4.196</h2.version>
         <slf4j.version>1.7.7</slf4j.version>
         <logback.version>1.2.0</logback.version>
         
@@ -57,7 +58,7 @@
         <jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
         <jboss-logging.version>3.2.1.Final</jboss-logging.version>
         <btm.version>2.1.3</btm.version>
-
+        
         <seata.version>1.0.0</seata.version>
         
         <junit.version>4.12</junit.version>
@@ -303,6 +304,12 @@
             <version>${postgresql.version}</version>
         </dependency>
         <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>${h2.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
             <version>${slf4j.version}</version>
diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/java/org/apache/shardingsphere/example/transaction/xa/raw/jdbc/XAOrderServiceTest.java b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/java/org/apache/shardingsphere/example/transaction/xa/raw/jdbc/XAOrderServiceTest.java
index cc0635f..5a79b50 100644
--- a/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/java/org/apache/shardingsphere/example/transaction/xa/raw/jdbc/XAOrderServiceTest.java
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/java/org/apache/shardingsphere/example/transaction/xa/raw/jdbc/XAOrderServiceTest.java
@@ -27,7 +27,7 @@ import java.sql.SQLException;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 
-public class XAOrderServiceTest {
+public final class XAOrderServiceTest {
     
     private XAOrderService orderService;
     
diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/resources/META-INF/sharding-databases-tables-postgresql.yaml b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/resources/META-INF/sharding-databases-tables-postgresql.yaml
new file mode 100644
index 0000000..10f7327
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/resources/META-INF/sharding-databases-tables-postgresql.yaml
@@ -0,0 +1,65 @@
+#
+# 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.
+#
+
+dataSources:
+  ds_0: !!com.zaxxer.hikari.HikariDataSource
+    jdbcUrl: jdbc:h2:mem:demo_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=PostgreSQL
+    username: "sa"
+    password: ""
+  ds_1: !!com.zaxxer.hikari.HikariDataSource
+    jdbcUrl: jdbc:h2:mem:demo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=PostgreSQL
+    username: "sa"
+    password: ""
+
+rules:
+- !SHARDING
+  tables:
+    t_order: 
+      actualDataNodes: ds_${0..1}.t_order_${0..1}
+      tableStrategy: 
+        standard:
+          shardingColumn: order_id
+          shardingAlgorithmName: table_inline
+      keyGenerateStrategy:
+        column: order_id
+        keyGeneratorName: snowflake
+  
+  defaultDatabaseStrategy:
+    standard:
+      shardingColumn: user_id
+      shardingAlgorithmName: database_inline
+  defaultTableStrategy:
+    none:
+  
+  shardingAlgorithms:
+    database_inline:
+      type: INLINE
+      props:
+        algorithm.expression: ds_${user_id % 2}
+    table_inline:
+      type: INLINE
+      props:
+        algorithm.expression: t_order_${order_id % 2}
+    
+  keyGenerators:
+    snowflake:
+      type: SNOWFLAKE
+      props:
+          worker.id: 123
+
+props:
+  sql.show: false
diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/resources/META-INF/sharding-databases-tables.yaml b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/resources/META-INF/sharding-databases-tables.yaml
new file mode 100644
index 0000000..13578e5
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/test/resources/META-INF/sharding-databases-tables.yaml
@@ -0,0 +1,68 @@
+#
+# 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.
+#
+
+dataSources:
+  ds_0: !!com.zaxxer.hikari.HikariDataSource
+    driverClassName: org.h2.Driver
+    jdbcUrl: jdbc:h2:mem:demo_ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
+    username: "sa"
+    password: ""
+    autoCommit: false
+  ds_1: !!com.zaxxer.hikari.HikariDataSource
+    driverClassName: org.h2.Driver
+    jdbcUrl: jdbc:h2:mem:demo_ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
+    username: "sa"
+    password: ""
+    autoCommit: false
+
+rules:
+- !SHARDING
+  tables:
+    t_order: 
+      actualDataNodes: ds_${0..1}.t_order_${0..1}
+      tableStrategy: 
+        standard:
+          shardingColumn: order_id
+          shardingAlgorithmName: table_inline
+      keyGenerateStrategy:
+        column: order_id
+        keyGeneratorName: snowflake
+  defaultDatabaseStrategy:
+    standard:
+      shardingColumn: user_id
+      shardingAlgorithmName: database_inline
+  defaultTableStrategy:
+    none:
+  
+  shardingAlgorithms:
+    database_inline:
+      type: INLINE
+      props:
+        algorithm.expression: ds_${user_id % 2}
+    table_inline:
+      type: INLINE
+      props:
+        algorithm.expression: t_order_${order_id % 2}
+  
+  keyGenerators:
+    snowflake:
+      type: SNOWFLAKE
+      props:
+          worker.id: 123
+
+props:
+  sql.show: false