This is an automated email from the ASF dual-hosted git repository.
panjuan 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 8420202 Refactor ParallelRunnerExecutorFactory (#9482)
8420202 is described below
commit 8420202c34608fe579027421b7b6e72ddd73a3bd
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 24 12:40:41 2021 +0800
Refactor ParallelRunnerExecutorFactory (#9482)
---
.../parallel/ParallelRunnerExecutorFactory.java | 33 +++++++++++++++++++---
.../junit/parallel/ParallelRunnerScheduler.java | 18 ++----------
2 files changed, 31 insertions(+), 20 deletions(-)
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerExecutorFactory.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerExecutorFactory.java
index eb035bd..3cdb646 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerExecutorFactory.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerExecutorFactory.java
@@ -19,23 +19,39 @@ package
org.apache.shardingsphere.test.integration.engine.junit.parallel;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import
org.apache.shardingsphere.test.integration.engine.junit.parallel.annotaion.ParallelLevel;
import
org.apache.shardingsphere.test.integration.engine.junit.parallel.impl.CaseParallelRunnerExecutor;
import
org.apache.shardingsphere.test.integration.engine.junit.parallel.impl.ScenarioParallelRunnerExecutor;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
/**
* Parallel runner executor factory.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ParallelRunnerExecutorFactory {
+ private static final ConcurrentMap<DatabaseType, ParallelRunnerExecutor>
EXECUTORS = new ConcurrentHashMap<>();
+
/**
- * Create new instance of parallel runner executor.
- *
+ * Get parallel runner executor.
+ *
+ * @param databaseType database type
* @param parallelLevel parallel level
- * @return new instance of parallel runner executor
+ * @return parallel runner executor
*/
- public static ParallelRunnerExecutor newInstance(final ParallelLevel
parallelLevel) {
+ public static ParallelRunnerExecutor getExecutor(final DatabaseType
databaseType, final ParallelLevel parallelLevel) {
+ if (EXECUTORS.containsKey(databaseType)) {
+ return EXECUTORS.get(databaseType);
+ }
+ EXECUTORS.putIfAbsent(databaseType, newInstance(parallelLevel));
+ return EXECUTORS.get(databaseType);
+ }
+
+ private static ParallelRunnerExecutor newInstance(final ParallelLevel
parallelLevel) {
switch (parallelLevel) {
case CASE:
return new CaseParallelRunnerExecutor();
@@ -45,4 +61,13 @@ public final class ParallelRunnerExecutorFactory {
throw new UnsupportedOperationException("Unsupported runtime
strategy.");
}
}
+
+ /**
+ * Get all executors.
+ *
+ * @return all executors
+ */
+ public static Collection<ParallelRunnerExecutor> getAllExecutors() {
+ return EXECUTORS.values();
+ }
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerScheduler.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerScheduler.java
index 5e75d36..d8c8321 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerScheduler.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/junit/parallel/ParallelRunnerScheduler.java
@@ -18,15 +18,11 @@
package org.apache.shardingsphere.test.integration.engine.junit.parallel;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
import
org.apache.shardingsphere.test.integration.engine.junit.parallel.annotaion.ParallelLevel;
import
org.apache.shardingsphere.test.integration.engine.param.RunnerParameters;
import
org.apache.shardingsphere.test.integration.engine.param.model.ParameterizedArray;
import org.junit.runners.model.RunnerScheduler;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
/**
* Parallel runner scheduler.
*/
@@ -35,24 +31,14 @@ public final class ParallelRunnerScheduler implements
RunnerScheduler {
private final ParallelLevel parallelLevel;
- private final ConcurrentMap<DatabaseType, ParallelRunnerExecutor>
runnerExecutors = new ConcurrentHashMap<>();
-
@Override
public void schedule(final Runnable childStatement) {
ParameterizedArray parameterizedArray = new
RunnerParameters(childStatement).getParameterizedArray();
-
getRunnerExecutor(parameterizedArray.getDatabaseType()).execute(parameterizedArray,
childStatement);
- }
-
- private ParallelRunnerExecutor getRunnerExecutor(final DatabaseType
databaseType) {
- if (runnerExecutors.containsKey(databaseType)) {
- return runnerExecutors.get(databaseType);
- }
- runnerExecutors.putIfAbsent(databaseType,
ParallelRunnerExecutorFactory.newInstance(parallelLevel));
- return runnerExecutors.get(databaseType);
+
ParallelRunnerExecutorFactory.getExecutor(parameterizedArray.getDatabaseType(),
parallelLevel).execute(parameterizedArray, childStatement);
}
@Override
public void finished() {
- runnerExecutors.values().forEach(ParallelRunnerExecutor::finished);
+
ParallelRunnerExecutorFactory.getAllExecutors().forEach(ParallelRunnerExecutor::finished);
}
}