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 fc0baaf6d7f Improve E2E container to be compatible with Oracle (#28287)
fc0baaf6d7f is described below

commit fc0baaf6d7f9dc65f5855e7c8b8702dd2b7982c5
Author: Xinze Guo <[email protected]>
AuthorDate: Mon Aug 28 20:30:54 2023 +0800

    Improve E2E container to be compatible with Oracle (#28287)
    
    * Improve pipeline to be compatible with Oracle
    
    * Revise config of Pipeline IT
---
 .../impl/ShardingSphereProxyClusterContainer.java  |  1 +
 .../pipeline/cases/PipelineContainerComposer.java  | 14 ++++++---
 .../container/compose/DockerContainerComposer.java |  3 +-
 .../container/compose/NativeContainerComposer.java | 16 +++++++++++
 .../config_sharding_sphere_jdbc_source.yaml        | 15 ++++++++++
 .../config_sharding_sphere_jdbc_target.yaml        | 33 +++++++++++++++++-----
 6 files changed, 70 insertions(+), 12 deletions(-)

diff --git 
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
 
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
index c4971bd97ec..1b6de75eb34 100644
--- 
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
+++ 
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereProxyClusterContainer.java
@@ -69,6 +69,7 @@ public final class ShardingSphereProxyClusterContainer 
extends DockerITContainer
             setCommand(config.getContainerCommand());
         }
         withExposedPorts(3307, 33071, 3308);
+        addEnv("TZ", "UTC");
         mountConfigurationFiles();
         setWaitStrategy(new JdbcConnectionWaitStrategy(() -> 
DriverManager.getConnection(DataSourceEnvironment.getURL(databaseType,
                 getHost(), getMappedPort(3307), 
config.getProxyDataSourceName()), ProxyContainerConstants.USERNAME, 
ProxyContainerConstants.PASSWORD)));
diff --git 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/PipelineContainerComposer.java
 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/PipelineContainerComposer.java
index d730ccf823c..ac21dc787b2 100644
--- 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/PipelineContainerComposer.java
+++ 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/PipelineContainerComposer.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.test.e2e.data.pipeline.cases;
 
+import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import lombok.Getter;
 import lombok.SneakyThrows;
@@ -198,7 +199,8 @@ public final class PipelineContainerComposer implements 
AutoCloseable {
             return;
         }
         for (String each : Arrays.asList(DS_0, DS_1, DS_2, DS_3, DS_4)) {
-            containerComposer.cleanUpDatabase(each);
+            String databaseName = databaseType instanceof OracleDatabaseType ? 
each.toUpperCase() : each;
+            containerComposer.cleanUpDatabase(databaseName);
         }
     }
     
@@ -226,11 +228,12 @@ public final class PipelineContainerComposer implements 
AutoCloseable {
      * @throws SQLException SQL exception
      */
     public void registerStorageUnit(final String storageUnitName) throws 
SQLException {
+        String username = getDatabaseType() instanceof OracleDatabaseType ? 
storageUnitName : getUsername();
         String registerStorageUnitTemplate = "REGISTER STORAGE UNIT ${ds} ( 
URL='${url}', USER='${user}', PASSWORD='${password}')".replace("${ds}", 
storageUnitName)
-                .replace("${user}", getUsername())
+                .replace("${user}", username)
                 .replace("${password}", getPassword())
                 .replace("${url}", getActualJdbcUrlTemplate(storageUnitName, 
true));
-        proxyExecuteWithLog(registerStorageUnitTemplate, 1);
+        proxyExecuteWithLog(registerStorageUnitTemplate, 0);
         Awaitility.await().ignoreExceptions().atMost(10, 
TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> 
showStorageUnitsName().contains(storageUnitName));
     }
     
@@ -370,8 +373,11 @@ public final class PipelineContainerComposer implements 
AutoCloseable {
      */
     public void proxyExecuteWithLog(final String sql, final int sleepSeconds) 
throws SQLException {
         log.info("proxy execute :{}", sql);
+        List<String> sqlList = 
Splitter.on(";").trimResults().omitEmptyStrings().splitToList(sql);
         try (Connection connection = proxyDataSource.getConnection()) {
-            connection.createStatement().execute(sql);
+            for (String each : sqlList) {
+                connection.createStatement().execute(each);
+            }
         }
         Awaitility.await().pollDelay(Math.max(sleepSeconds, 0L), 
TimeUnit.SECONDS).until(() -> true);
     }
diff --git 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/DockerContainerComposer.java
 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/DockerContainerComposer.java
index 9a18c3c099e..66e0e88f47a 100644
--- 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/DockerContainerComposer.java
+++ 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/DockerContainerComposer.java
@@ -75,8 +75,9 @@ public final class DockerContainerComposer extends 
BaseContainerComposer {
             storageContainers.add(storageContainer);
         }
         AdaptorContainerConfiguration containerConfig = 
PipelineProxyClusterContainerConfigurationFactory.newInstance(databaseType);
+        DatabaseType proxyDatabaseType = databaseType instanceof 
OracleDatabaseType ? TypedSPILoader.getService(DatabaseType.class, "MySQL") : 
databaseType;
         ShardingSphereProxyClusterContainer proxyClusterContainer = 
(ShardingSphereProxyClusterContainer) AdapterContainerFactory.newInstance(
-                AdapterMode.CLUSTER, AdapterType.PROXY, databaseType, null, 
"", containerConfig);
+                AdapterMode.CLUSTER, AdapterType.PROXY, proxyDatabaseType, 
null, "", containerConfig);
         for (DockerStorageContainer each : storageContainers) {
             proxyClusterContainer.dependsOn(governanceContainer, each);
         }
diff --git 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java
 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java
index 445926387ca..10a89e4cebf 100644
--- 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java
+++ 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/NativeContainerComposer.java
@@ -79,6 +79,12 @@ public final class NativeContainerComposer extends 
BaseContainerComposer {
                     connection.createStatement().execute("DROP SCHEMA IF 
EXISTS test;");
                 }
                 break;
+            case "Oracle":
+                jdbcUrl = DataSourceEnvironment.getURL(databaseType, 
"localhost", actualDatabasePort, "");
+                try (Connection connection = 
DriverManager.getConnection(jdbcUrl, username, password)) {
+                    dropTableWithOracle(connection, databaseName);
+                }
+                break;
             default:
         }
     }
@@ -101,6 +107,16 @@ public final class NativeContainerComposer extends 
BaseContainerComposer {
         }
     }
     
+    private void dropTableWithOracle(final Connection connection, final String 
schema) throws SQLException {
+        String queryAllTables = String.format("SELECT TABLE_NAME FROM 
ALL_TABLES WHERE OWNER = '%s'", schema);
+        try (ResultSet resultSet = 
connection.createStatement().executeQuery(String.format(queryAllTables, 
schema))) {
+            List<String> actualTableNames = 
getFirstColumnValueFromResult(resultSet);
+            for (String each : actualTableNames) {
+                connection.createStatement().executeUpdate(String.format("DROP 
TABLE %s.%s", schema, each));
+            }
+        }
+    }
+    
     @Override
     public String getProxyJdbcUrl(final String databaseName) {
         if (databaseType instanceof OracleDatabaseType) {
diff --git 
a/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml 
b/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml
index ac7775e1204..c48220f058a 100644
--- 
a/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml
+++ 
b/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_source.yaml
@@ -55,6 +55,16 @@ rules:
 #        standard:
 #          shardingAlgorithmName: t_order_tbl_inline
 #          shardingColumn: order_id
+    t_order_item:
+      actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+      tableStrategy:
+        standard:
+          shardingColumn: order_id
+          shardingAlgorithmName: t_order_item_inline
+      keyGenerateStrategy:
+        column: order_id
+        keyGeneratorName: snowflake
+
   shardingAlgorithms:
     default_db_inline:
       type: INLINE
@@ -64,6 +74,11 @@ rules:
       type: INLINE
       props:
         algorithm-expression: t_order
+    t_order_item_inline:
+      type: INLINE
+      props:
+        algorithm-expression: t_order_item_${order_id % 2}
+
   keyGenerators:
     snowflake:
       type: SNOWFLAKE
diff --git 
a/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_target.yaml 
b/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_target.yaml
index 92ee83b8211..eef745c81c8 100644
--- 
a/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_target.yaml
+++ 
b/test/it/pipeline/src/test/resources/config_sharding_sphere_jdbc_target.yaml
@@ -36,22 +36,41 @@ rules:
     standard:
       shardingAlgorithmName: default_db_inline
       shardingColumn: user_id
-  tables:
+  autoTables:
     t_order:
-      actualDataNodes: ds_$->{1..2}.t_order_$->{0..1}
+      actualDataSources: ds_1,ds_2
       keyGenerateStrategy:
         column: order_id
         keyGeneratorName: snowflake
+      shardingStrategy:
+        standard:
+          shardingAlgorithmName: t_order_hash_mod
+          shardingColumn: order_id
+  tables:
+    t_order_item:
+      actualDataNodes: ds_${0..2}.t_order_item_${0..2}
       tableStrategy:
         standard:
-          shardingAlgorithmName: t1_tbl_inline
           shardingColumn: order_id
+          shardingAlgorithmName: new_t_order_item_inline
+      keyGenerateStrategy:
+        column: order_id
+        keyGeneratorName: snowflake
+
   shardingAlgorithms:
-    default_db_inline:
+    database_inline:
+      props:
+        algorithm-expression: ds_${user_id % 2 + 1}
+      type: INLINE
+    t_order_inline:
+      props:
+        algorithm-expression: t_order_${order_id % 2}
       type: INLINE
+    t_order_hash_mod:
       props:
-        algorithm-expression: ds_$->{user_id % 2 + 1}
-    t_order_tbl_inline:
+        sharding-count: '6'
+      type: hash_mod
+    new_t_order_item_inline:
       type: INLINE
       props:
-        algorithm-expression: t_order_$->{order_id % 2}
+        algorithm-expression: t_order_item_${order_id % 4}

Reply via email to