Skip to content

Commit

Permalink
refactor parallel test framework apache#2
Browse files Browse the repository at this point in the history
  • Loading branch information
tianhao960 committed Sep 9, 2022
1 parent ac25cb0 commit d869598
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-common</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import org.apache.shardingsphere.test.integration.env.runtime.IntegrationTestEnvironment;
import org.apache.shardingsphere.test.integration.env.runtime.cluster.ClusterEnvironment;
import org.apache.shardingsphere.test.integration.framework.runner.parallel.ParallelRunnerScheduler;
import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy;
import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerScheduler;
import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy;
import org.junit.runners.Parameterized;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,19 @@
package org.apache.shardingsphere.test.integration.framework.runner.parallel;

import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel;
import org.apache.shardingsphere.test.integration.framework.runner.parallel.impl.CaseParallelRunnerExecutor;
import org.apache.shardingsphere.test.integration.framework.runner.parallel.impl.ScenarioParallelRunnerExecutor;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.shardingsphere.test.runner.parallel.DefaultParallelRunnerExecutorFactory;
import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerExecutor;
import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel;

/**
* Parallel runner executor factory.
*/
public final class ParallelRunnerExecutorFactory {

private final Map<DatabaseType, ParallelRunnerExecutor> executors = new ConcurrentHashMap<>();

/**
* Get parallel runner executor.
*
* @param databaseType database type
* @param parallelLevel parallel level
* @return parallel runner executor
*/
public ParallelRunnerExecutor getExecutor(final DatabaseType databaseType, final ParallelLevel parallelLevel) {
if (executors.containsKey(databaseType)) {
return executors.get(databaseType);
}
ParallelRunnerExecutor newExecutor = newInstance(parallelLevel);
if (null != executors.putIfAbsent(databaseType, newExecutor)) {
newExecutor.finished();
}
return executors.get(databaseType);
}

private ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) {
public final class DatabaseTypeParallelRunnerExecutorFactory extends DefaultParallelRunnerExecutorFactory<DatabaseType> {

@Override
public ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) {
switch (parallelLevel) {
case CASE:
return new CaseParallelRunnerExecutor();
Expand All @@ -62,12 +41,5 @@ private ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) {
}
}

/**
* Get all executors.
*
* @return all executors
*/
public Collection<ParallelRunnerExecutor> getAllExecutors() {
return executors.values();
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,18 @@

package org.apache.shardingsphere.test.integration.framework.runner.parallel.impl;

import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorServiceManager;
import org.apache.shardingsphere.test.integration.framework.runner.parallel.ParallelRunnerExecutor;

import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor;

import java.util.Collection;
import java.util.LinkedList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
* Parallel runner executor with case.
*/
public final class CaseParallelRunnerExecutor implements ParallelRunnerExecutor {

// TODO ExecutorEngine.execute and callback
private final ExecutorServiceManager executorServiceManager = ExecutorEngine.createExecutorEngineWithCPU().getExecutorServiceManager();

private final Collection<Future<?>> taskFeatures = new LinkedList<>();
public final class CaseParallelRunnerExecutor extends DefaultParallelRunnerExecutor<ParameterizedArray> {

@Override
public void execute(final ParameterizedArray parameterizedArray, final Runnable childStatement) {
taskFeatures.add(executorServiceManager.getExecutorService().submit(childStatement));
}

@Override
public void finished() {
taskFeatures.forEach(each -> {
try {
each.get();
} catch (final InterruptedException | ExecutionException ignored) {
}
});
executorServiceManager.getExecutorService().shutdownNow();
execute(childStatement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import lombok.EqualsAndHashCode;
import org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorServiceManager;
import org.apache.shardingsphere.test.integration.framework.runner.parallel.ParallelRunnerExecutor;
import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor;

import java.util.Collection;
import java.util.LinkedList;
Expand All @@ -32,12 +32,10 @@
/**
* Parallel runner executor with scenario.
*/
public final class ScenarioParallelRunnerExecutor implements ParallelRunnerExecutor {
public final class ScenarioParallelRunnerExecutor extends DefaultParallelRunnerExecutor<ParameterizedArray> {

private final Map<ScenarioKey, ExecutorServiceManager> executorServiceManagers = new ConcurrentHashMap<>();

private final Collection<Future<?>> taskFeatures = new LinkedList<>();


@Override
public void execute(final ParameterizedArray parameterizedArray, final Runnable childStatement) {
taskFeatures.add(getExecutorService(new ScenarioKey(parameterizedArray)).getExecutorService().submit(childStatement));
Expand Down
5 changes: 5 additions & 0 deletions shardingsphere-test/shardingsphere-test-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@
<artifactId>mockito-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit d869598

Please sign in to comment.