You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2022/11/29 15:46:10 UTC
[shardingsphere] branch master updated: Refactor ParallelRunnerExecutor (#22512)
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 3d9a12b032a Refactor ParallelRunnerExecutor (#22512)
3d9a12b032a is described below
commit 3d9a12b032ad89b5d46c89c4350f3e5fa368d6e8
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Nov 29 23:46:01 2022 +0800
Refactor ParallelRunnerExecutor (#22512)
---
.../impl/ScenarioParallelRunnerExecutor.java | 8 ++++----
.../executor/ParallelRunnerExecutorFactory.java | 1 -
.../executor/impl/NormalParallelRunnerExecutor.java | 20 ++++++++++----------
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/test/integration-test/test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java b/test/integration-test/test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java
index 99548bff1a1..3c96e2d67af 100644
--- a/test/integration-test/test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java
+++ b/test/integration-test/test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java
@@ -33,17 +33,17 @@ public final class ScenarioParallelRunnerExecutor extends NormalParallelRunnerEx
@Override
protected ExecutorService getExecutorService(final Object key) {
ScenarioKey scenarioKey = new ScenarioKey((ITParameterizedArray) key);
- if (getExecutorServiceMap().containsKey(scenarioKey)) {
- return getExecutorServiceMap().get(scenarioKey);
+ if (getExecutorServices().containsKey(scenarioKey)) {
+ return getExecutorServices().get(scenarioKey);
}
String threadPoolNameFormat = String.join("-", "ScenarioExecutorPool", scenarioKey.toString(), "%d");
ExecutorService executorService = Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors(),
new ThreadFactoryBuilder().setDaemon(true).setNameFormat(threadPoolNameFormat).build());
- if (null != getExecutorServiceMap().putIfAbsent(scenarioKey, executorService)) {
+ if (null != getExecutorServices().putIfAbsent(scenarioKey, executorService)) {
executorService.shutdownNow();
}
- return getExecutorServiceMap().get(scenarioKey);
+ return getExecutorServices().get(scenarioKey);
}
@Override
diff --git a/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/ParallelRunnerExecutorFactory.java b/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/ParallelRunnerExecutorFactory.java
index ce796a97ab6..ae97e5d796b 100644
--- a/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/ParallelRunnerExecutorFactory.java
+++ b/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/ParallelRunnerExecutorFactory.java
@@ -29,7 +29,6 @@ import java.util.ServiceLoader;
/**
* Parallel runner executor factory.
*/
-@SuppressWarnings("rawtypes")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ParallelRunnerExecutorFactory {
diff --git a/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/impl/NormalParallelRunnerExecutor.java b/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/impl/NormalParallelRunnerExecutor.java
index ec91be65350..9450a75f806 100644
--- a/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/impl/NormalParallelRunnerExecutor.java
+++ b/test/runner/src/main/java/org/apache/shardingsphere/test/runner/executor/impl/NormalParallelRunnerExecutor.java
@@ -35,34 +35,34 @@ import java.util.concurrent.Future;
*/
public class NormalParallelRunnerExecutor implements ParallelRunnerExecutor {
- private final Collection<Future<?>> taskFeatures = new LinkedList<>();
+ private final Collection<Future<?>> futures = new LinkedList<>();
@Getter
- private final Map<Object, ExecutorService> executorServiceMap = new ConcurrentHashMap<>();
+ private final Map<Object, ExecutorService> executorServices = new ConcurrentHashMap<>();
private volatile ExecutorService defaultExecutorService;
@Override
public <T> void execute(final T key, final Runnable childStatement) {
- taskFeatures.add(getExecutorService(key).submit(childStatement));
+ futures.add(getExecutorService(key).submit(childStatement));
}
@Override
public void execute(final Runnable childStatement) {
- taskFeatures.add(getExecutorService().submit(childStatement));
+ futures.add(getExecutorService().submit(childStatement));
}
protected <T> ExecutorService getExecutorService(final T key) {
- if (executorServiceMap.containsKey(key)) {
- return executorServiceMap.get(key);
+ if (executorServices.containsKey(key)) {
+ return executorServices.get(key);
}
String threadPoolNameFormat = String.join("-", "ShardingSphere-KeyedParallelTestThread", key.toString(), "%d");
ExecutorService executorService = Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat(threadPoolNameFormat).build());
- if (null != executorServiceMap.putIfAbsent(key, executorService)) {
+ if (null != executorServices.putIfAbsent(key, executorService)) {
executorService.shutdownNow();
}
- return executorServiceMap.get(key);
+ return executorServices.get(key);
}
private ExecutorService getExecutorService() {
@@ -79,13 +79,13 @@ public class NormalParallelRunnerExecutor implements ParallelRunnerExecutor {
@Override
public void finished() {
- taskFeatures.forEach(each -> {
+ futures.forEach(each -> {
try {
each.get();
} catch (final InterruptedException | ExecutionException ignored) {
}
});
- executorServiceMap.values().forEach(ExecutorService::shutdownNow);
+ executorServices.values().forEach(ExecutorService::shutdownNow);
if (null != defaultExecutorService) {
defaultExecutorService.shutdownNow();
}