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

sunnianjun 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 c60ab56c9c3 Use BatchE2EITContainerComposer to instead of BatchE2EIT 
(#24656)
c60ab56c9c3 is described below

commit c60ab56c9c3cec6dd6c6627f7751ea155ec5a0af
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Mar 17 00:05:40 2023 +0800

    Use BatchE2EITContainerComposer to instead of BatchE2EIT (#24656)
---
 ...E2EIT.java => BatchE2EITContainerComposer.java} | 37 +++++-----
 .../test/e2e/engine/SingleE2EIT.java               |  2 +-
 .../test/e2e/engine/dml/BatchDMLE2EIT.java         | 83 ++++++++++++----------
 .../param/array/E2ETestParameterFactory.java       | 10 +++
 4 files changed, 76 insertions(+), 56 deletions(-)

diff --git 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EIT.java
 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EITContainerComposer.java
similarity index 93%
rename from 
test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EIT.java
rename to 
test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EITContainerComposer.java
index 956086a1cd1..b5615e370e4 100644
--- 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EIT.java
+++ 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EITContainerComposer.java
@@ -30,10 +30,6 @@ import 
org.apache.shardingsphere.test.e2e.env.DataSetEnvironmentManager;
 import 
org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath;
 import 
org.apache.shardingsphere.test.e2e.env.runtime.scenario.path.ScenarioDataPath.Type;
 import 
org.apache.shardingsphere.test.e2e.framework.param.model.CaseTestParameter;
-import 
org.apache.shardingsphere.test.e2e.framework.runner.ParallelParameterized;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.runner.RunWith;
 
 import javax.sql.DataSource;
 import javax.xml.bind.JAXBException;
@@ -57,10 +53,11 @@ import java.util.Set;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-@RunWith(ParallelParameterized.class)
-public abstract class BatchE2EIT {
+/**
+ * Batch E2E IT container composer.
+ */
+public final class BatchE2EITContainerComposer implements AutoCloseable {
     
-    @Getter
     private final CaseTestParameter testParam;
     
     @Getter
@@ -70,7 +67,7 @@ public abstract class BatchE2EIT {
     
     private final DataSetEnvironmentManager dataSetEnvironmentManager;
     
-    public BatchE2EIT(final CaseTestParameter testParam) throws JAXBException, 
IOException, SQLException, ParseException {
+    public BatchE2EITContainerComposer(final CaseTestParameter testParam) 
throws JAXBException, IOException, SQLException, ParseException {
         this.testParam = testParam;
         containerComposer = new E2EContainerComposer(testParam);
         for (IntegrationTestCaseAssertion each : 
testParam.getTestCaseContext().getTestCase().getAssertions()) {
@@ -80,17 +77,13 @@ public abstract class BatchE2EIT {
         dataSetEnvironmentManager.fillData();
     }
     
-    @After
-    public void tearDown() {
-        dataSetEnvironmentManager.cleanData();
-    }
-    
-    @AfterClass
-    public static void closeContainers() {
-        E2EContainerComposer.closeContainers();
-    }
-    
-    protected final void assertDataSets(final int[] actualUpdateCounts) throws 
SQLException {
+    /**
+     * Assert data sets.
+     * 
+     * @param actualUpdateCounts actual update counts
+     * @throws SQLException SQL exception
+     */
+    public void assertDataSets(final int[] actualUpdateCounts) throws 
SQLException {
         DataSet expected = getDataSet(actualUpdateCounts);
         assertThat("Only support single table for DML.", 
expected.getMetaDataList().size(), is(1));
         DataSetMetaData expectedDataSetMetaData = 
expected.getMetaDataList().get(0);
@@ -190,4 +183,10 @@ public abstract class BatchE2EIT {
     private boolean isPostgreSQLOrOpenGaussMoney(final String columnTypeName) {
         return "money".equalsIgnoreCase(columnTypeName) && 
("PostgreSQL".equals(testParam.getDatabaseType().getType()) || 
"openGauss".equals(testParam.getDatabaseType().getType()));
     }
+    
+    @Override
+    public void close() {
+        dataSetEnvironmentManager.cleanData();
+        E2EContainerComposer.closeContainers();
+    }
 }
diff --git 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/SingleE2EIT.java
 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/SingleE2EIT.java
index 8eb60952834..b05af574ae7 100644
--- 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/SingleE2EIT.java
+++ 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/SingleE2EIT.java
@@ -45,7 +45,7 @@ public abstract class SingleE2EIT {
     public E2EWatcher watcher = new E2EWatcher();
     
     private final AssertionTestParameter testParam;
-            
+    
     private final E2EContainerComposer containerComposer;
     
     private final SQLExecuteType sqlExecuteType;
diff --git 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BatchDMLE2EIT.java
 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BatchDMLE2EIT.java
index 4f6b3d41d5f..857d5cb06a4 100644
--- 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BatchDMLE2EIT.java
+++ 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BatchDMLE2EIT.java
@@ -20,14 +20,15 @@ package org.apache.shardingsphere.test.e2e.engine.dml;
 import org.apache.shardingsphere.test.e2e.cases.SQLCommandType;
 import 
org.apache.shardingsphere.test.e2e.cases.assertion.IntegrationTestCaseAssertion;
 import org.apache.shardingsphere.test.e2e.cases.value.SQLValue;
-import org.apache.shardingsphere.test.e2e.engine.BatchE2EIT;
+import org.apache.shardingsphere.test.e2e.engine.BatchE2EITContainerComposer;
 import 
org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory;
 import 
org.apache.shardingsphere.test.e2e.framework.param.model.CaseTestParameter;
-import 
org.apache.shardingsphere.test.e2e.framework.param.model.E2ETestParameter;
-import 
org.apache.shardingsphere.test.e2e.framework.runner.ParallelRunningStrategy;
-import 
org.apache.shardingsphere.test.e2e.framework.runner.ParallelRunningStrategy.ParallelLevel;
-import org.junit.Test;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.condition.EnabledIf;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import javax.xml.bind.JAXBException;
 import java.io.IOException;
@@ -35,35 +36,29 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.text.ParseException;
-import java.util.Collection;
+import java.util.stream.Stream;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-@ParallelRunningStrategy(ParallelLevel.SCENARIO)
-public final class BatchDMLE2EIT extends BatchE2EIT {
+public final class BatchDMLE2EIT {
     
-    public BatchDMLE2EIT(final CaseTestParameter testParam) throws 
SQLException, JAXBException, IOException, ParseException {
-        super(testParam);
-    }
-    
-    @Parameters(name = "{0}")
-    public static Collection<E2ETestParameter> getTestParameters() {
-        return 
E2ETestParameterFactory.getCaseTestParameters(SQLCommandType.DML);
-    }
-    
-    @Test
-    public void assertExecuteBatch() throws SQLException, ParseException {
-        int[] actualUpdateCounts;
-        try (Connection connection = 
getContainerComposer().getTargetDataSource().getConnection()) {
-            actualUpdateCounts = executeBatchForPreparedStatement(connection);
+    @ParameterizedTest(name = "{0}")
+    @EnabledIf("isEnabled")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    public void assertExecuteBatch(final CaseTestParameter testParam) throws 
SQLException, ParseException, JAXBException, IOException {
+        try (BatchE2EITContainerComposer containerComposer = new 
BatchE2EITContainerComposer(testParam)) {
+            int[] actualUpdateCounts;
+            try (Connection connection = 
containerComposer.getContainerComposer().getTargetDataSource().getConnection()) 
{
+                actualUpdateCounts = 
executeBatchForPreparedStatement(testParam, connection);
+            }
+            containerComposer.assertDataSets(actualUpdateCounts);
         }
-        assertDataSets(actualUpdateCounts);
     }
     
-    private int[] executeBatchForPreparedStatement(final Connection 
connection) throws SQLException, ParseException {
-        try (PreparedStatement preparedStatement = 
connection.prepareStatement(getTestParam().getTestCaseContext().getTestCase().getSql()))
 {
-            for (IntegrationTestCaseAssertion each : 
getTestParam().getTestCaseContext().getTestCase().getAssertions()) {
+    private int[] executeBatchForPreparedStatement(final CaseTestParameter 
testParam, final Connection connection) throws SQLException, ParseException {
+        try (PreparedStatement preparedStatement = 
connection.prepareStatement(testParam.getTestCaseContext().getTestCase().getSql()))
 {
+            for (IntegrationTestCaseAssertion each : 
testParam.getTestCaseContext().getTestCase().getAssertions()) {
                 addBatch(preparedStatement, each);
             }
             return preparedStatement.executeBatch();
@@ -77,16 +72,32 @@ public final class BatchDMLE2EIT extends BatchE2EIT {
         preparedStatement.addBatch();
     }
     
-    @Test
-    public void assertClearBatch() throws SQLException, ParseException {
-        try (
-                Connection connection = 
getContainerComposer().getTargetDataSource().getConnection();
-                PreparedStatement preparedStatement = 
connection.prepareStatement(getTestParam().getTestCaseContext().getTestCase().getSql()))
 {
-            for (IntegrationTestCaseAssertion each : 
getTestParam().getTestCaseContext().getTestCase().getAssertions()) {
-                addBatch(preparedStatement, each);
+    @ParameterizedTest(name = "{0}")
+    @EnabledIf("isEnabled")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    public void assertClearBatch(final CaseTestParameter testParam) throws 
SQLException, ParseException, JAXBException, IOException {
+        try (BatchE2EITContainerComposer containerComposer = new 
BatchE2EITContainerComposer(testParam)) {
+            try (
+                    Connection connection = 
containerComposer.getContainerComposer().getTargetDataSource().getConnection();
+                    PreparedStatement preparedStatement = 
connection.prepareStatement(testParam.getTestCaseContext().getTestCase().getSql()))
 {
+                for (IntegrationTestCaseAssertion each : 
testParam.getTestCaseContext().getTestCase().getAssertions()) {
+                    addBatch(preparedStatement, each);
+                }
+                preparedStatement.clearBatch();
+                assertThat(preparedStatement.executeBatch().length, is(0));
             }
-            preparedStatement.clearBatch();
-            assertThat(preparedStatement.executeBatch().length, is(0));
+        }
+    }
+    
+    private static boolean isEnabled() {
+        return E2ETestParameterFactory.containsTestParameter();
+    }
+    
+    private static class TestCaseArgumentsProvider implements 
ArgumentsProvider {
+        
+        @Override
+        public Stream<? extends Arguments> provideArguments(final 
ExtensionContext extensionContext) {
+            return 
E2ETestParameterFactory.getCaseTestParameters(SQLCommandType.DML).stream().map(Arguments::of);
         }
     }
 }
diff --git 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/framework/param/array/E2ETestParameterFactory.java
 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/framework/param/array/E2ETestParameterFactory.java
index c85b30e10b6..7b84fdc69f6 100644
--- 
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/framework/param/array/E2ETestParameterFactory.java
+++ 
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/framework/param/array/E2ETestParameterFactory.java
@@ -79,4 +79,14 @@ public final class E2ETestParameterFactory {
     private static boolean isDistSQLCommandType(final SQLCommandType 
sqlCommandType) {
         return SQLCommandType.RDL == sqlCommandType || SQLCommandType.RAL == 
sqlCommandType || SQLCommandType.RQL == sqlCommandType;
     }
+    
+    /**
+     * Judge whether contains test parameter.
+     * 
+     * @return contains or not
+     */
+    public static boolean containsTestParameter() {
+        return IntegrationTestEnvironment.getInstance().getRunModes().stream()
+                .anyMatch(each -> 
AdapterMode.STANDALONE.getValue().equalsIgnoreCase(each) || 
AdapterMode.CLUSTER.getValue().equalsIgnoreCase(each));
+    }
 }

Reply via email to