You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/10/14 02:20:50 UTC

[shardingsphere] branch master updated: Clean up transaction test code (#21506)

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

tuichenchuxin 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 c4d7c123926 Clean up transaction test code (#21506)
c4d7c123926 is described below

commit c4d7c12392685762f61f06a4214b82ba3cef877f
Author: ZhangCheng <fl...@outlook.com>
AuthorDate: Fri Oct 14 10:20:40 2022 +0800

    Clean up transaction test code (#21506)
---
 .../transaction/engine/base/BaseITCase.java        |  2 +-
 .../engine/base/BaseTransactionITCase.java         | 13 ++++----
 .../transaction/engine/entity/JdbcInfoEntity.java  | 35 ----------------------
 .../env/IntegrationTestEnvironment.java            | 33 --------------------
 .../transaction/util/TestCaseClassScanner.java     | 15 ++++++----
 5 files changed, 17 insertions(+), 81 deletions(-)

diff --git a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java
index 56d2f68232e..43692409966 100644
--- a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java
+++ b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java
@@ -103,7 +103,7 @@ public abstract class BaseITCase {
     private final String adapter;
     
     @Getter
-    private AutoDataSource dataSource;
+    private final AutoDataSource dataSource;
     
     static {
         long startTime = System.currentTimeMillis();
diff --git a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java
index 3b6d901097f..20a9fe5ef82 100644
--- a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java
+++ b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java
@@ -53,7 +53,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
     private void initProxyConfig() throws SQLException {
         addResources();
         initShardingAlgorithm();
-        assertTrue(waitShardingAlgorithmEffect(15));
+        assertTrue(waitShardingAlgorithmEffect());
         initTableRules();
         createTables();
     }
@@ -67,7 +67,8 @@ public abstract class BaseTransactionITCase extends BaseITCase {
         executeWithLog(connection, getCommonSQLCommand().getCreateAccountShardingAlgorithm());
     }
     
-    private boolean waitShardingAlgorithmEffect(final int maxWaitTimes) throws SQLException {
+    private boolean waitShardingAlgorithmEffect() throws SQLException {
+        long maxWaitTimes = 15;
         long startTime = System.currentTimeMillis();
         int waitTimes = 0;
         do {
@@ -162,7 +163,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
         }
         String alterLocalTransactionRule = getCommonSQLCommand().getAlterLocalTransactionRule();
         executeWithLog(connection, alterLocalTransactionRule);
-        assertTrue(waitExpectedTransactionRule(TransactionType.LOCAL, "", 5));
+        assertTrue(waitExpectedTransactionRule(TransactionType.LOCAL, ""));
     }
     
     private void alterXaTransactionRule(final String providerType) throws SQLException {
@@ -172,7 +173,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
         }
         String alterXaTransactionRule = getCommonSQLCommand().getAlterXATransactionRule().replace("${providerType}", providerType);
         executeWithLog(connection, alterXaTransactionRule);
-        assertTrue(waitExpectedTransactionRule(TransactionType.XA, providerType, 5));
+        assertTrue(waitExpectedTransactionRule(TransactionType.XA, providerType));
     }
     
     private boolean isExpectedTransactionRule(final Connection connection, final TransactionType expectedTransType, final String expectedProviderType) throws SQLException {
@@ -181,7 +182,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
                 && Objects.equals(transactionRuleMap.get(TransactionTestConstants.PROVIDER_TYPE), expectedProviderType);
     }
     
-    private boolean waitExpectedTransactionRule(final TransactionType expectedTransType, final String expectedProviderType, final int maxWaitTimes) throws SQLException {
+    private boolean waitExpectedTransactionRule(final TransactionType expectedTransType, final String expectedProviderType) throws SQLException {
         ThreadUtil.sleep(5, TimeUnit.SECONDS);
         Connection connection = getProxyConnection();
         int waitTimes = 0;
@@ -191,7 +192,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
             }
             ThreadUtil.sleep(2, TimeUnit.SECONDS);
             waitTimes++;
-        } while (waitTimes <= maxWaitTimes);
+        } while (waitTimes <= 3);
         return false;
     }
     
diff --git a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/entity/JdbcInfoEntity.java b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/entity/JdbcInfoEntity.java
deleted file mode 100644
index c27feab99dc..00000000000
--- a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/entity/JdbcInfoEntity.java
+++ /dev/null
@@ -1,35 +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.transaction.engine.entity;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * JDBC info entity.
- */
-@RequiredArgsConstructor
-@Getter
-public final class JdbcInfoEntity {
-    
-    private final String username;
-    
-    private final String password;
-    
-    private final int port;
-}
diff --git a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java
index 27e4a7f3b4c..821fd4bbb6f 100644
--- a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java
+++ b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java
@@ -21,7 +21,6 @@ import com.google.common.base.Strings;
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.integration.transaction.engine.entity.JdbcInfoEntity;
 import org.apache.shardingsphere.integration.transaction.env.enums.TransactionITEnvTypeEnum;
 import org.apache.shardingsphere.integration.transaction.env.enums.TransactionTestCaseRegistry;
 import org.apache.shardingsphere.test.integration.env.container.atomic.constants.ProxyContainerConstants;
@@ -100,38 +99,6 @@ public final class IntegrationTestEnvironment {
         return result;
     }
     
-    /**
-     * Get actual data source connection.
-     *
-     * @param databaseType database type.
-     * @return jdbc connection
-     */
-    public JdbcInfoEntity getActualDatabaseJdbcInfo(final DatabaseType databaseType) {
-        String username;
-        String password;
-        int port;
-        switch (databaseType.getType()) {
-            case "MySQL":
-                username = props.getOrDefault("transaction.it.native.mysql.username", "root").toString();
-                password = props.getOrDefault("transaction.it.native.mysql.password", "root").toString();
-                port = Integer.parseInt(props.getOrDefault("transaction.it.native.mysql.port", 3307).toString());
-                break;
-            case "PostgreSQL":
-                username = props.getOrDefault("transaction.it.native.postgresql.username", "postgres").toString();
-                password = props.getOrDefault("transaction.it.native.postgresql.password", "postgres").toString();
-                port = Integer.parseInt(props.getOrDefault("transaction.it.native.postgresql.port", 5432).toString());
-                break;
-            case "openGauss":
-                username = props.getOrDefault("transaction.it.native.opengauss.username", "gaussdb").toString();
-                password = props.getOrDefault("transaction.it.native.opengauss.password", "Root@123").toString();
-                port = Integer.parseInt(props.getOrDefault("transaction.it.native.opengauss.port", 5432).toString());
-                break;
-            default:
-                throw new UnsupportedOperationException("Unsupported database type: " + databaseType.getType());
-        }
-        return new JdbcInfoEntity(username, password, port);
-    }
-    
     /**
      * Get actual data source default port.
      *
diff --git a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/util/TestCaseClassScanner.java b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/util/TestCaseClassScanner.java
index 02eab108504..43f4f67cb51 100644
--- a/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/util/TestCaseClassScanner.java
+++ b/test/integration-test/transaction/src/test/java/org/apache/shardingsphere/integration/transaction/util/TestCaseClassScanner.java
@@ -101,13 +101,18 @@ public final class TestCaseClassScanner {
             if (jarEntryName.contains(CLASS_SUFFIX) && jarEntryName.replace(File.separator, ".").startsWith(TEST_CASE_PACKAGE_NAME)) {
                 String className = jarEntryName.substring(0, jarEntryName.lastIndexOf(".")).replace(File.separator, ".");
                 Class<?> clazz = Class.forName(className);
-                if (clazz.isAssignableFrom(BaseTransactionTestCase.class)) {
-                    caseClasses.add((Class<? extends BaseTransactionTestCase>) clazz);
-                }
+                addClass(caseClasses, clazz);
             }
         }
     }
     
+    @SuppressWarnings("unchecked")
+    private static void addClass(final List<Class<? extends BaseTransactionTestCase>> caseClasses, final Class<?> clazz) {
+        if (clazz.isAssignableFrom(BaseTransactionTestCase.class)) {
+            caseClasses.add((Class<? extends BaseTransactionTestCase>) clazz);
+        }
+    }
+    
     private static void scanClassFiles(final File file) {
         if (file.isDirectory()) {
             for (File f : Objects.requireNonNull(file.listFiles())) {
@@ -127,9 +132,7 @@ public final class TestCaseClassScanner {
                 String noSuffixFileName = fileName.substring(8 + fileName.lastIndexOf("classes"), fileName.indexOf(CLASS_SUFFIX));
                 String filePackage = noSuffixFileName.replace(File.separator, ".");
                 Class<?> clazz = Class.forName(filePackage);
-                if (BaseTransactionTestCase.class.isAssignableFrom(clazz)) {
-                    caseClasses.add((Class<? extends BaseTransactionTestCase>) clazz);
-                }
+                addClass(caseClasses, clazz);
             }
         }
     }