From ac25cb05f02952eee613df2e4471d999324e2ac2 Mon Sep 17 00:00:00 2001 From: tianhao960 Date: Fri, 9 Sep 2022 18:43:46 +0800 Subject: [PATCH 1/6] add support for test parallel run --- .../test/parallel/ParallelParameterized.java | 33 +++++++++++++ .../test/parallel/ParallelScheduler.java | 46 +++++++++++++++++++ ...ardingSphereParallelTestParameterized.java | 39 ++++++++++++++++ .../test/runner/parallel/ParallelRunner.java | 41 +++++++++++++++++ .../parallel/ParallelRunnerExecutor.java | 36 +++++++++++++++ .../ParallelRunnerExecutorFactory.java | 43 +++++++++++++++++ .../parallel/ParallelRunnerScheduler.java | 43 +++++++++++++++++ .../parallel/annotaion/ParallelLevel.java | 26 +++++++++++ .../annotaion/ParallelRuntimeStrategy.java | 42 +++++++++++++++++ .../impl/DefaultParallelRunnerExecutor.java | 35 ++++++++++++++ 10 files changed, 384 insertions(+) create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelLevel.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelRuntimeStrategy.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java new file mode 100644 index 0000000000000..677deef89e5d6 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java @@ -0,0 +1,33 @@ +/* + * 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.test.parallel; + +import org.junit.runners.Parameterized; + +/** + * parallel runner for parameterize test suite. + */ +public class ParallelParameterized extends Parameterized { + + // CHECKSTYLE:OFF + public ParallelParameterized(final Class klass) throws Throwable { + // CHECKSTYLE:ON + super(klass); + setScheduler(new ParallelScheduler()); + } +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java new file mode 100644 index 0000000000000..322206dd5aea3 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java @@ -0,0 +1,46 @@ +/* + * 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.test.parallel; + +import org.junit.runners.model.RunnerScheduler; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +/** + * parallel scheduler for junit. + */ +public class ParallelScheduler implements RunnerScheduler { + + private ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + + @Override + public void schedule(final Runnable childStatement) { + executorService.submit(childStatement); + } + + @Override + public void finished() { + executorService.shutdown(); + try { + executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java new file mode 100644 index 0000000000000..ae60ee44dba30 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java @@ -0,0 +1,39 @@ +/* + * 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.test.runner; + + +import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerScheduler; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.junit.runners.Parameterized; + +/** + * ShardingSphere integration test parameterized. + */ +public final class ShardingSphereParallelTestParameterized extends Parameterized { + + // CHECKSTYLE:OFF + public ShardingSphereParallelTestParameterized(final Class clazz) throws Throwable { + // CHECKSTYLE:ON + super(clazz); + ParallelRuntimeStrategy parallelRuntimeStrategy = clazz.getAnnotation(ParallelRuntimeStrategy.class); + if (null != parallelRuntimeStrategy) { + setScheduler(new ParallelRunnerScheduler(parallelRuntimeStrategy.value())); + } + } +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java new file mode 100644 index 0000000000000..19eb75e4c80d6 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java @@ -0,0 +1,41 @@ +/* + * 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.test.runner.parallel; + +import org.apache.shardingsphere.test.parallel.ParallelScheduler; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +/** + * parallel runner for junit. + */ +public class ParallelRunner extends BlockJUnit4ClassRunner { + + /** + * Creates a ParallelRunner to run {@code klass}. + * If you now annotate a test-class with @RunWith(ParallelRunner.class) each method will run within its own thread. + * + * @param klass test class + * @throws InitializationError if the test class is malformed. + */ + public ParallelRunner(final Class klass) throws InitializationError { + super(klass); + setScheduler(new ParallelScheduler()); + } + +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java new file mode 100644 index 0000000000000..9ab7dbeff00fc --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java @@ -0,0 +1,36 @@ +/* + * 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.test.runner.parallel; + +/** + * Parallel runner executor. + */ +public interface ParallelRunnerExecutor { + + /** + * Execute child statement. + * + * @param childStatement child statement + */ + void execute(Runnable childStatement); + + /** + * Override to implement any behavior that must occur after all children have been scheduled (for example, waiting for them all to finish). + */ + void finished(); +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java new file mode 100644 index 0000000000000..504e19d9ba1d2 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java @@ -0,0 +1,43 @@ +/* + * 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.test.runner.parallel; + +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor; + +/** + * Parallel runner executor factory. + */ +public final class ParallelRunnerExecutorFactory { + + /** + * Get parallel runner executor. + * + * @param parallelLevel parallel level + * @return parallel runner executor + */ + public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel) { + switch (parallelLevel) { + case DEFAULT: + return new DefaultParallelRunnerExecutor(); + default: + throw new UnsupportedOperationException("Unsupported runtime strategy."); + } + } + +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java new file mode 100644 index 0000000000000..b26314c3dc739 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java @@ -0,0 +1,43 @@ +/* + * 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.test.runner.parallel; + +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.junit.runners.model.RunnerScheduler; + +/** + * Parallel runner scheduler. + */ +@RequiredArgsConstructor +public final class ParallelRunnerScheduler implements RunnerScheduler { + + private final ParallelLevel parallelLevel; + + private final ParallelRunnerExecutorFactory executorFactory = new ParallelRunnerExecutorFactory(); + + @Override + public void schedule(final Runnable childStatement) { + executorFactory.getExecutor(parallelLevel).execute(childStatement); + } + + @Override + public void finished() { + executorFactory.getAllExecutors().forEach(ParallelRunnerExecutor::finished); + } +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelLevel.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelLevel.java new file mode 100644 index 0000000000000..4a3663b444c04 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelLevel.java @@ -0,0 +1,26 @@ +/* + * 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.test.runner.parallel.annotaion; + +/** + * Parallel level. + */ +public enum ParallelLevel { + + CASE, SCENARIO, DEFAULT +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelRuntimeStrategy.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelRuntimeStrategy.java new file mode 100644 index 0000000000000..5e999de9459a2 --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/annotaion/ParallelRuntimeStrategy.java @@ -0,0 +1,42 @@ +/* + * 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.test.runner.parallel.annotaion; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Parallel runtime strategy. + */ +@Documented +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface ParallelRuntimeStrategy { + + /** + * Get parallel level. + * + * @return value parallel level + */ + ParallelLevel value(); +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java new file mode 100644 index 0000000000000..62aecace336bc --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java @@ -0,0 +1,35 @@ +package org.apache.shardingsphere.test.runner.parallel.impl; + + +import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerExecutor; +import java.util.Collection; +import java.util.LinkedList; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +public class DefaultParallelRunnerExecutor implements ParallelRunnerExecutor { + + private final Collection> taskFeatures = new LinkedList<>(); + + public ExecutorService getExecuteService(){ + return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + } + + @Override + public void execute(final Runnable childStatement) { + taskFeatures.add(getExecuteService().submit(childStatement)); + } + + @Override + public void finished() { + taskFeatures.forEach(each -> { + try { + each.get(); + } catch (final InterruptedException | ExecutionException ignored) { + } + }); + getExecuteService().shutdownNow(); + } +} From d869598d866e06d12a803055a722cbd67f4b1775 Mon Sep 17 00:00:00 2001 From: tianhao960 Date: Fri, 9 Sep 2022 23:16:06 +0800 Subject: [PATCH 2/6] refactor parallel test framework #2 --- .../pom.xml | 6 ++ ...ingSphereIntegrationTestParameterized.java | 4 +- ...aseTypeParallelRunnerExecutorFactory.java} | 44 ++-------- .../parallel/ParallelRunnerExecutor.java | 39 --------- .../parallel/ParallelRunnerScheduler.java | 46 ---------- .../parallel/annotaion/ParallelLevel.java | 26 ------ .../annotaion/ParallelRuntimeStrategy.java | 42 ---------- .../impl/CaseParallelRunnerExecutor.java | 29 +------ .../impl/ScenarioParallelRunnerExecutor.java | 8 +- .../shardingsphere-test-common/pom.xml | 5 ++ .../DefaultParallelRunnerExecutorFactory.java | 84 +++++++++++++++++++ .../parallel/ParallelRunnerExecutor.java | 13 ++- .../ParallelRunnerExecutorFactory.java | 45 +++------- .../parallel/ParallelRunnerScheduler.java | 4 +- .../impl/DefaultParallelRunnerExecutor.java | 19 +++-- 15 files changed, 149 insertions(+), 265 deletions(-) rename shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/{ParallelRunnerExecutorFactory.java => DatabaseTypeParallelRunnerExecutorFactory.java} (54%) delete mode 100644 shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerExecutor.java delete mode 100644 shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerScheduler.java delete mode 100644 shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelLevel.java delete mode 100644 shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelRuntimeStrategy.java create mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml index bf7e64def164a..705e7c013a2e8 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml @@ -61,6 +61,12 @@ org.testcontainers testcontainers + + + org.apache.shardingsphere + shardingsphere-test-common + compile + diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java index 9b077995162a5..b96fda6119659 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java @@ -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; /** diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java similarity index 54% rename from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerExecutorFactory.java rename to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java index 02e4c11a96640..1de93144427a2 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java @@ -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 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 { + + @Override + public ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) { switch (parallelLevel) { case CASE: return new CaseParallelRunnerExecutor(); @@ -62,12 +41,5 @@ private ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) { } } - /** - * Get all executors. - * - * @return all executors - */ - public Collection getAllExecutors() { - return executors.values(); - } + } diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerExecutor.java deleted file mode 100644 index de5407f2dc6af..0000000000000 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerExecutor.java +++ /dev/null @@ -1,39 +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.test.integration.framework.runner.parallel; - -import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray; - -/** - * Parallel runner executor. - */ -public interface ParallelRunnerExecutor { - - /** - * Execute child statement. - * - * @param parameterizedArray parameterized array - * @param childStatement child statement - */ - void execute(ParameterizedArray parameterizedArray, Runnable childStatement); - - /** - * Override to implement any behavior that must occur after all children have been scheduled (for example, waiting for them all to finish). - */ - void finished(); -} diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerScheduler.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerScheduler.java deleted file mode 100644 index a7daf20bf634c..0000000000000 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParallelRunnerScheduler.java +++ /dev/null @@ -1,46 +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.test.integration.framework.runner.parallel; - -import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.param.RunnerParameters; -import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray; -import org.junit.runners.model.RunnerScheduler; - -/** - * Parallel runner scheduler. - */ -@RequiredArgsConstructor -public final class ParallelRunnerScheduler implements RunnerScheduler { - - private final ParallelLevel parallelLevel; - - private final ParallelRunnerExecutorFactory executorFactory = new ParallelRunnerExecutorFactory(); - - @Override - public void schedule(final Runnable childStatement) { - ParameterizedArray parameterizedArray = new RunnerParameters(childStatement).getParameterizedArray(); - executorFactory.getExecutor(parameterizedArray.getDatabaseType(), parallelLevel).execute(parameterizedArray, childStatement); - } - - @Override - public void finished() { - executorFactory.getAllExecutors().forEach(ParallelRunnerExecutor::finished); - } -} diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelLevel.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelLevel.java deleted file mode 100644 index 17711712af1fa..0000000000000 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelLevel.java +++ /dev/null @@ -1,26 +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.test.integration.framework.runner.parallel.annotaion; - -/** - * Parallel level. - */ -public enum ParallelLevel { - - CASE, SCENARIO -} diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelRuntimeStrategy.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelRuntimeStrategy.java deleted file mode 100644 index d66e6c2011b09..0000000000000 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/annotaion/ParallelRuntimeStrategy.java +++ /dev/null @@ -1,42 +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.test.integration.framework.runner.parallel.annotaion; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Parallel runtime strategy. - */ -@Documented -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -public @interface ParallelRuntimeStrategy { - - /** - * Get parallel level. - * - * @return value parallel level - */ - ParallelLevel value(); -} diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java index 82edbeb27a1b7..c63e24fd12e76 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java @@ -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> taskFeatures = new LinkedList<>(); +public final class CaseParallelRunnerExecutor extends DefaultParallelRunnerExecutor { @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); } } diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java index cac29458f2fe2..54c829b92e5ed 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java @@ -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; @@ -32,12 +32,10 @@ /** * Parallel runner executor with scenario. */ -public final class ScenarioParallelRunnerExecutor implements ParallelRunnerExecutor { +public final class ScenarioParallelRunnerExecutor extends DefaultParallelRunnerExecutor { private final Map executorServiceManagers = new ConcurrentHashMap<>(); - - private final Collection> taskFeatures = new LinkedList<>(); - + @Override public void execute(final ParameterizedArray parameterizedArray, final Runnable childStatement) { taskFeatures.add(getExecutorService(new ScenarioKey(parameterizedArray)).getExecutorService().submit(childStatement)); diff --git a/shardingsphere-test/shardingsphere-test-common/pom.xml b/shardingsphere-test/shardingsphere-test-common/pom.xml index 17506e9a841fa..02394fe5699d1 100644 --- a/shardingsphere-test/shardingsphere-test-common/pom.xml +++ b/shardingsphere-test/shardingsphere-test-common/pom.xml @@ -37,5 +37,10 @@ mockito-core compile + + junit + junit + compile + diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java new file mode 100644 index 0000000000000..2c89a408966be --- /dev/null +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java @@ -0,0 +1,84 @@ +/* + * 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.test.runner.parallel; + +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Parallel runner executor factory. + */ +public class DefaultParallelRunnerExecutorFactory implements ParallelRunnerExecutorFactory { + + private final Map executors = new ConcurrentHashMap<>(); + + private volatile ParallelRunnerExecutor defaultExecutor ; + + @Override + public ParallelRunnerExecutor getExecutor(T key, ParallelLevel parallelLevel) { + if (executors.containsKey(key)) { + return executors.get(key); + } + ParallelRunnerExecutor newExecutor = newInstance(parallelLevel); + if (null != executors.putIfAbsent(key, newExecutor)) { + newExecutor.finished(); + } + return executors.get(key); + } + + /** + * Get parallel runner executor. + * + * @param parallelLevel parallel level + * @return parallel runner executor + */ + public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel) { + if(null == defaultExecutor){ + synchronized (ParallelRunnerExecutor.class){ + if(null == defaultExecutor){ + defaultExecutor = new DefaultParallelRunnerExecutor(); + } + } + } + return defaultExecutor; + } + + public ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) { + return new DefaultParallelRunnerExecutor(); + } + + /** + * Get all executors. + * + * @return all executors + */ + public Collection getAllExecutors() { + List executors = new LinkedList<>(this.executors.values()); + if(null != defaultExecutor){ + executors.add(defaultExecutor); + } + return executors; + } + +} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java index 9ab7dbeff00fc..57e46ee6a73cc 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java @@ -20,8 +20,17 @@ /** * Parallel runner executor. */ -public interface ParallelRunnerExecutor { - +public interface ParallelRunnerExecutor { + + /** + * Execute child statement. + * + * + * @param childStatement child statement + */ + void execute(T key, Runnable childStatement); + + /** * Execute child statement. * diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java index 504e19d9ba1d2..fcc9a2bcb7b4c 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java @@ -1,43 +1,20 @@ -/* - * 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.test.runner.parallel; import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor; -/** - * Parallel runner executor factory. - */ -public final class ParallelRunnerExecutorFactory { +import java.util.Collection; + + +public interface ParallelRunnerExecutorFactory { + + public ParallelRunnerExecutor getExecutor(final T key, final ParallelLevel parallelLevel); + + public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel); /** - * Get parallel runner executor. + * Get all executors. * - * @param parallelLevel parallel level - * @return parallel runner executor + * @return all executors */ - public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel) { - switch (parallelLevel) { - case DEFAULT: - return new DefaultParallelRunnerExecutor(); - default: - throw new UnsupportedOperationException("Unsupported runtime strategy."); - } - } - + public Collection getAllExecutors(); } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java index b26314c3dc739..c46c15c1fa437 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java @@ -29,7 +29,7 @@ public final class ParallelRunnerScheduler implements RunnerScheduler { private final ParallelLevel parallelLevel; - private final ParallelRunnerExecutorFactory executorFactory = new ParallelRunnerExecutorFactory(); + private final DefaultParallelRunnerExecutorFactory executorFactory = new DefaultParallelRunnerExecutorFactory(); @Override public void schedule(final Runnable childStatement) { @@ -38,6 +38,6 @@ public void schedule(final Runnable childStatement) { @Override public void finished() { - executorFactory.getAllExecutors().forEach(ParallelRunnerExecutor::finished); + executorFactory.getAllExecutors().forEach(each -> ((ParallelRunnerExecutor)each).finished()); } } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java index 62aecace336bc..9882516a87a23 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java @@ -1,6 +1,7 @@ package org.apache.shardingsphere.test.runner.parallel.impl; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerExecutor; import java.util.Collection; import java.util.LinkedList; @@ -9,17 +10,23 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -public class DefaultParallelRunnerExecutor implements ParallelRunnerExecutor { +public class DefaultParallelRunnerExecutor implements ParallelRunnerExecutor { - private final Collection> taskFeatures = new LinkedList<>(); + protected final Collection> taskFeatures = new LinkedList<>(); + + private final ExecutorService executorService = Executors.newFixedThreadPool( + Runtime.getRuntime().availableProcessors(), + new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingSphere-ParallelTestThread-%d").build()); + + + @Override + public void execute(T key, Runnable childStatement) { - public ExecutorService getExecuteService(){ - return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); } @Override public void execute(final Runnable childStatement) { - taskFeatures.add(getExecuteService().submit(childStatement)); + taskFeatures.add(executorService.submit(childStatement)); } @Override @@ -30,6 +37,6 @@ public void finished() { } catch (final InterruptedException | ExecutionException ignored) { } }); - getExecuteService().shutdownNow(); + executorService.shutdownNow(); } } From 5891afa0b5d4b76ad5a709007e44f4565d3c5ad0 Mon Sep 17 00:00:00 2001 From: tianhao960 Date: Sat, 10 Sep 2022 09:46:34 +0800 Subject: [PATCH 3/6] refactor parallel test framework #3 --- .../mysql/MySQLParserParameterizedTest.java | 3 +- .../pom.xml | 3 +- .../integration/engine/dal/GeneralDALIT.java | 4 +- .../integration/engine/dcl/GeneralDCLIT.java | 4 +- .../integration/engine/ddl/GeneralDDLIT.java | 4 +- .../engine/dml/AdditionalDMLIT.java | 4 +- .../integration/engine/dml/BatchDMLIT.java | 4 +- .../integration/engine/dml/GeneralDMLIT.java | 4 +- .../engine/dql/AdditionalDQLIT.java | 4 +- .../integration/engine/dql/GeneralDQLIT.java | 4 +- .../integration/engine/ral/GeneralRALIT.java | 4 +- .../integration/engine/rdl/GeneralRDLIT.java | 4 +- .../integration/engine/rql/GeneralRQLIT.java | 4 +- ...ingSphereIntegrationTestParameterized.java | 3 +- ...baseTypeParallelRunnerExecutorFactory.java | 3 +- .../impl/CaseParallelRunnerExecutor.java | 3 +- .../impl/ScenarioParallelRunnerExecutor.java | 10 ++-- .../shardingsphere-parser-test/pom.xml | 6 ++- .../test/parallel/ParallelParameterized.java | 33 ------------ .../test/parallel/ParallelScheduler.java | 46 ----------------- ...ardingSphereParallelTestParameterized.java | 9 ++-- .../DefaultParallelRunnerExecutorFactory.java | 31 ++++++----- .../test/runner/parallel/ParallelRunner.java | 4 +- .../parallel/ParallelRunnerExecutor.java | 7 ++- .../ParallelRunnerExecutorFactory.java | 46 ++++++++++++++--- .../parallel/ParallelRunnerScheduler.java | 4 +- .../impl/DefaultParallelRunnerExecutor.java | 51 ++++++++++++++----- 27 files changed, 144 insertions(+), 162 deletions(-) delete mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java delete mode 100644 shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java index 36f18d68749f8..04bc2c56ed038 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.sql.parser.mysql; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.SQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; @@ -25,7 +26,7 @@ import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class MySQLParserParameterizedTest extends SQLParserParameterizedTest { public MySQLParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml index 705e7c013a2e8..afcdfb28c4109 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml @@ -61,10 +61,11 @@ org.testcontainers testcontainers - + org.apache.shardingsphere shardingsphere-test-common + ${project.version} compile diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java index cdf4ee441cad9..5bb9cd625e65e 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dal/GeneralDALIT.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.test.integration.cases.SQLCommandType; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java index fe55d67937770..3a8aaa0183aa4 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java @@ -21,8 +21,8 @@ import org.apache.shardingsphere.test.integration.cases.SQLExecuteType; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java index f8bb5f03c5063..d3d22b87992f5 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/GeneralDDLIT.java @@ -21,8 +21,8 @@ import org.apache.shardingsphere.test.integration.cases.SQLExecuteType; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java index da66b3fdba5be..fe06b26920948 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/AdditionalDMLIT.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.test.integration.env.runtime.IntegrationTestEnvironment; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java index c1376c20744fe..a3253838603e5 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BatchDMLIT.java @@ -24,8 +24,8 @@ import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.CaseParameterizedArray; import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java index 96263435aff88..8feab56625474 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java @@ -22,8 +22,8 @@ import org.apache.shardingsphere.test.integration.cases.value.SQLValue; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java index 4c5d4d47b493a..38e825609601a 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/AdditionalDQLIT.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.test.integration.env.runtime.IntegrationTestEnvironment; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java index 062151f4f5f1d..d6547864f85b8 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java @@ -22,8 +22,8 @@ import org.apache.shardingsphere.test.integration.cases.value.SQLValue; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java index f0ddad5264b74..08d2da449c89a 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/GeneralRALIT.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.test.integration.cases.SQLCommandType; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java index b4666049e8d33..568f2d65681f1 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rdl/GeneralRDLIT.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.test.integration.cases.SQLCommandType; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java index 7d51dd0b0f166..0d0482d3736c1 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/rql/GeneralRQLIT.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.test.integration.cases.SQLCommandType; import org.apache.shardingsphere.test.integration.framework.param.array.ParameterizedArrayFactory; import org.apache.shardingsphere.test.integration.framework.param.model.AssertionParameterizedArray; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelLevel; -import org.apache.shardingsphere.test.integration.framework.runner.parallel.annotaion.ParallelRuntimeStrategy; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java index b96fda6119659..d357d9dcf2acf 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java @@ -19,6 +19,7 @@ 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.DatabaseTypeParallelRunnerExecutorFactory; import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerScheduler; import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.runners.Parameterized; @@ -35,7 +36,7 @@ public ShardingSphereIntegrationTestParameterized(final Class clazz) throws T if (ClusterEnvironment.Type.DOCKER != IntegrationTestEnvironment.getInstance().getClusterEnvironment().getType()) { ParallelRuntimeStrategy parallelRuntimeStrategy = clazz.getAnnotation(ParallelRuntimeStrategy.class); if (null != parallelRuntimeStrategy) { - setScheduler(new ParallelRunnerScheduler(parallelRuntimeStrategy.value())); + setScheduler(new ParallelRunnerScheduler(parallelRuntimeStrategy.value(), new DatabaseTypeParallelRunnerExecutorFactory())); } } } diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java index 1de93144427a2..4025e6a2fb80d 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java @@ -28,7 +28,7 @@ * Parallel runner executor factory. */ public final class DatabaseTypeParallelRunnerExecutorFactory extends DefaultParallelRunnerExecutorFactory { - + @Override public ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) { switch (parallelLevel) { @@ -41,5 +41,4 @@ public ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) { } } - } diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java index c63e24fd12e76..48e31503966d5 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/CaseParallelRunnerExecutor.java @@ -17,10 +17,9 @@ package org.apache.shardingsphere.test.integration.framework.runner.parallel.impl; - import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray; -import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor; +import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor; /** * Parallel runner executor with case. diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java index 54c829b92e5ed..d31edd086af43 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java @@ -21,13 +21,9 @@ import org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorServiceManager; 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.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; /** * Parallel runner executor with scenario. @@ -35,10 +31,10 @@ public final class ScenarioParallelRunnerExecutor extends DefaultParallelRunnerExecutor { private final Map executorServiceManagers = new ConcurrentHashMap<>(); - + @Override public void execute(final ParameterizedArray parameterizedArray, final Runnable childStatement) { - taskFeatures.add(getExecutorService(new ScenarioKey(parameterizedArray)).getExecutorService().submit(childStatement)); + getTaskFeatures().add(getExecutorService(new ScenarioKey(parameterizedArray)).getExecutorService().submit(childStatement)); } private ExecutorServiceManager getExecutorService(final ScenarioKey scenarioKey) { @@ -55,7 +51,7 @@ private ExecutorServiceManager getExecutorService(final ScenarioKey scenarioKey) @Override public void finished() { - taskFeatures.forEach(each -> { + getTaskFeatures().forEach(each -> { try { each.get(); } catch (final InterruptedException | ExecutionException ignored) { diff --git a/shardingsphere-test/shardingsphere-parser-test/pom.xml b/shardingsphere-test/shardingsphere-parser-test/pom.xml index 93374dc754541..349b640d58b01 100644 --- a/shardingsphere-test/shardingsphere-parser-test/pom.xml +++ b/shardingsphere-test/shardingsphere-parser-test/pom.xml @@ -97,11 +97,15 @@ shardingsphere-shadow-distsql-parser ${project.version} - junit junit compile + + org.apache.shardingsphere + shardingsphere-test-common + ${project.version} + diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java deleted file mode 100644 index 677deef89e5d6..0000000000000 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelParameterized.java +++ /dev/null @@ -1,33 +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.test.parallel; - -import org.junit.runners.Parameterized; - -/** - * parallel runner for parameterize test suite. - */ -public class ParallelParameterized extends Parameterized { - - // CHECKSTYLE:OFF - public ParallelParameterized(final Class klass) throws Throwable { - // CHECKSTYLE:ON - super(klass); - setScheduler(new ParallelScheduler()); - } -} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java deleted file mode 100644 index 322206dd5aea3..0000000000000 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/parallel/ParallelScheduler.java +++ /dev/null @@ -1,46 +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.test.parallel; - -import org.junit.runners.model.RunnerScheduler; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -/** - * parallel scheduler for junit. - */ -public class ParallelScheduler implements RunnerScheduler { - - private ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - - @Override - public void schedule(final Runnable childStatement) { - executorService.submit(childStatement); - } - - @Override - public void finished() { - executorService.shutdown(); - try { - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } -} diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java index ae60ee44dba30..9557acd174353 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java @@ -17,8 +17,9 @@ package org.apache.shardingsphere.test.runner; - +import org.apache.shardingsphere.test.runner.parallel.DefaultParallelRunnerExecutorFactory; import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerScheduler; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.runners.Parameterized; @@ -31,9 +32,9 @@ public final class ShardingSphereParallelTestParameterized extends Parameterized public ShardingSphereParallelTestParameterized(final Class clazz) throws Throwable { // CHECKSTYLE:ON super(clazz); + ParallelLevel level; ParallelRuntimeStrategy parallelRuntimeStrategy = clazz.getAnnotation(ParallelRuntimeStrategy.class); - if (null != parallelRuntimeStrategy) { - setScheduler(new ParallelRunnerScheduler(parallelRuntimeStrategy.value())); - } + level = null != parallelRuntimeStrategy ? parallelRuntimeStrategy.value() : ParallelLevel.DEFAULT; + setScheduler(new ParallelRunnerScheduler(level, new DefaultParallelRunnerExecutorFactory())); } } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java index 2c89a408966be..b3f5d1791ae07 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java @@ -30,13 +30,13 @@ * Parallel runner executor factory. */ public class DefaultParallelRunnerExecutorFactory implements ParallelRunnerExecutorFactory { - + private final Map executors = new ConcurrentHashMap<>(); - - private volatile ParallelRunnerExecutor defaultExecutor ; - + + private volatile ParallelRunnerExecutor defaultExecutor; + @Override - public ParallelRunnerExecutor getExecutor(T key, ParallelLevel parallelLevel) { + public ParallelRunnerExecutor getExecutor(final T key, final ParallelLevel parallelLevel) { if (executors.containsKey(key)) { return executors.get(key); } @@ -46,7 +46,7 @@ public ParallelRunnerExecutor getExecutor(T key, ParallelLevel parallelLevel) { } return executors.get(key); } - + /** * Get parallel runner executor. * @@ -54,20 +54,25 @@ public ParallelRunnerExecutor getExecutor(T key, ParallelLevel parallelLevel) { * @return parallel runner executor */ public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel) { - if(null == defaultExecutor){ - synchronized (ParallelRunnerExecutor.class){ - if(null == defaultExecutor){ + if (null == defaultExecutor) { + synchronized (ParallelRunnerExecutor.class) { + if (null == defaultExecutor) { defaultExecutor = new DefaultParallelRunnerExecutor(); } } } return defaultExecutor; } - + + /** + * create executor instance by parallel level. + * @param parallelLevel parallel level + * @return executor by parallel level + */ public ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) { return new DefaultParallelRunnerExecutor(); } - + /** * Get all executors. * @@ -75,10 +80,10 @@ public ParallelRunnerExecutor newInstance(final ParallelLevel parallelLevel) { */ public Collection getAllExecutors() { List executors = new LinkedList<>(this.executors.values()); - if(null != defaultExecutor){ + if (null != defaultExecutor) { executors.add(defaultExecutor); } return executors; } - + } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java index 19eb75e4c80d6..06d91a4d0d446 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.test.runner.parallel; -import org.apache.shardingsphere.test.parallel.ParallelScheduler; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.InitializationError; @@ -35,7 +35,7 @@ public class ParallelRunner extends BlockJUnit4ClassRunner { */ public ParallelRunner(final Class klass) throws InitializationError { super(klass); - setScheduler(new ParallelScheduler()); + setScheduler(new ParallelRunnerScheduler(ParallelLevel.DEFAULT, new DefaultParallelRunnerExecutorFactory())); } } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java index 57e46ee6a73cc..3bbe86d4856d6 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java @@ -21,16 +21,15 @@ * Parallel runner executor. */ public interface ParallelRunnerExecutor { - + /** * Execute child statement. * - * + * @param key exector key * @param childStatement child statement */ void execute(T key, Runnable childStatement); - - + /** * Execute child statement. * diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java index fcc9a2bcb7b4c..a1324cd2e10f7 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java @@ -1,20 +1,50 @@ +/* + * 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.test.runner.parallel; import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; - import java.util.Collection; - +/** + * executor factory. + * @param key type which bind to executor + */ public interface ParallelRunnerExecutorFactory { - - public ParallelRunnerExecutor getExecutor(final T key, final ParallelLevel parallelLevel); - - public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel); - + + /** + * get executor factory by key and parallel level. + * @param key key bind to the factory + * @param parallelLevel parallel level + * @return executor by key and parallel level + */ + ParallelRunnerExecutor getExecutor(T key, ParallelLevel parallelLevel); + + /** + * get factory by parallel level. + * @param parallelLevel parallel level + * @return executor by parallel level + */ + ParallelRunnerExecutor getExecutor(ParallelLevel parallelLevel); + /** * Get all executors. * * @return all executors */ - public Collection getAllExecutors(); + Collection getAllExecutors(); } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java index c46c15c1fa437..454c73feed5c4 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java @@ -29,7 +29,7 @@ public final class ParallelRunnerScheduler implements RunnerScheduler { private final ParallelLevel parallelLevel; - private final DefaultParallelRunnerExecutorFactory executorFactory = new DefaultParallelRunnerExecutorFactory(); + private final DefaultParallelRunnerExecutorFactory executorFactory; @Override public void schedule(final Runnable childStatement) { @@ -38,6 +38,6 @@ public void schedule(final Runnable childStatement) { @Override public void finished() { - executorFactory.getAllExecutors().forEach(each -> ((ParallelRunnerExecutor)each).finished()); + executorFactory.getAllExecutors().forEach(each -> ((ParallelRunnerExecutor) each).finished()); } } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java index 9882516a87a23..bc132d8a0ab2d 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java @@ -1,7 +1,24 @@ -package org.apache.shardingsphere.test.runner.parallel.impl; +/* + * 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.test.runner.parallel.impl; import com.google.common.util.concurrent.ThreadFactoryBuilder; +import lombok.Getter; import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerExecutor; import java.util.Collection; import java.util.LinkedList; @@ -10,25 +27,33 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; +/** + * default parallel executor. + * @param key type bind to parallel executor + */ public class DefaultParallelRunnerExecutor implements ParallelRunnerExecutor { - - protected final Collection> taskFeatures = new LinkedList<>(); - - private final ExecutorService executorService = Executors.newFixedThreadPool( - Runtime.getRuntime().availableProcessors(), - new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingSphere-ParallelTestThread-%d").build()); - - + + @Getter + private final Collection> taskFeatures = new LinkedList<>(); + + private final ExecutorService executorService; + + public DefaultParallelRunnerExecutor() { + executorService = Executors.newFixedThreadPool( + Runtime.getRuntime().availableProcessors(), + new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingSphere-ParallelTestThread-%d").build()); + } + @Override - public void execute(T key, Runnable childStatement) { - + public void execute(final T key, final Runnable childStatement) { + } - + @Override public void execute(final Runnable childStatement) { taskFeatures.add(executorService.submit(childStatement)); } - + @Override public void finished() { taskFeatures.forEach(each -> { From b7a19696eaec5c1088fb1a76b5c3d955d6724737 Mon Sep 17 00:00:00 2001 From: tianhao960 Date: Sat, 10 Sep 2022 10:11:02 +0800 Subject: [PATCH 4/6] refactor parallel test framework #4 --- .../sql/parser/mysql/MySQLParserParameterizedTest.java | 1 - .../parser/mysql/UnsupportedMySQLParserParameterizedTest.java | 4 ++-- .../parser/opengauss/OpenGaussParserParameterizedTest.java | 4 ++-- .../UnsupportedOpenGaussParserParameterizedTest.java | 4 ++-- .../sql/parser/oracle/OracleParserParameterizedTest.java | 4 ++-- .../oracle/UnsupportedOracleParserParameterizedTest.java | 4 ++-- .../parser/postgresql/PostgreSQLParserParameterizedTest.java | 4 ++-- .../UnsupportedPostgreSQLParserParameterizedTest.java | 4 ++-- .../sql/parser/sql92/SQL92ParserParameterizedTest.java | 4 ++-- .../parser/sql92/UnsupportedSQL92ParserParameterizedTest.java | 4 ++-- .../parser/sqlserver/SQLServerParserParameterizedTest.java | 4 ++-- .../UnsupportedSQLServerParserParameterizedTest.java | 4 ++-- 12 files changed, 22 insertions(+), 23 deletions(-) diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java index 04bc2c56ed038..8264944119310 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserParameterizedTest.java @@ -21,7 +21,6 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.engine.SQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/UnsupportedMySQLParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/UnsupportedMySQLParserParameterizedTest.java index 19f5fbb28c70f..40c94c9e6621f 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/UnsupportedMySQLParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/test/java/org/apache/shardingsphere/sql/parser/mysql/UnsupportedMySQLParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.mysql; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.UnsupportedSQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class UnsupportedMySQLParserParameterizedTest extends UnsupportedSQLParserParameterizedTest { public UnsupportedMySQLParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/OpenGaussParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/OpenGaussParserParameterizedTest.java index d7b1214464858..cbda131bc7a61 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/OpenGaussParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/OpenGaussParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.opengauss; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.SQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class OpenGaussParserParameterizedTest extends SQLParserParameterizedTest { public OpenGaussParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/UnsupportedOpenGaussParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/UnsupportedOpenGaussParserParameterizedTest.java index e0ccb00055c41..23f64773a9a9a 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/UnsupportedOpenGaussParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/test/java/org/apache/shardingsphere/sql/parser/opengauss/UnsupportedOpenGaussParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.opengauss; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.UnsupportedSQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class UnsupportedOpenGaussParserParameterizedTest extends UnsupportedSQLParserParameterizedTest { public UnsupportedOpenGaussParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserParameterizedTest.java index b1ed7bb71e15a..c9b0f572086ff 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.oracle; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.SQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class OracleParserParameterizedTest extends SQLParserParameterizedTest { public OracleParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/UnsupportedOracleParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/UnsupportedOracleParserParameterizedTest.java index a091131fb3247..0311e5321e3a7 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/UnsupportedOracleParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/test/java/org/apache/shardingsphere/sql/parser/oracle/UnsupportedOracleParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.oracle; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.UnsupportedSQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class UnsupportedOracleParserParameterizedTest extends UnsupportedSQLParserParameterizedTest { public UnsupportedOracleParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserParameterizedTest.java index acc5c42ae87fd..f13037e52dabd 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.postgresql; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.SQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class PostgreSQLParserParameterizedTest extends SQLParserParameterizedTest { public PostgreSQLParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/UnsupportedPostgreSQLParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/UnsupportedPostgreSQLParserParameterizedTest.java index 6145f4d5ceac1..1eb910d985683 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/UnsupportedPostgreSQLParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/test/java/org/apache/shardingsphere/sql/parser/postgresql/UnsupportedPostgreSQLParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.postgresql; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.UnsupportedSQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class UnsupportedPostgreSQLParserParameterizedTest extends UnsupportedSQLParserParameterizedTest { public UnsupportedPostgreSQLParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserParameterizedTest.java index 826e7835bc3c7..1f1bcf7961467 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.sql92; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.SQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class SQL92ParserParameterizedTest extends SQLParserParameterizedTest { public SQL92ParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/UnsupportedSQL92ParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/UnsupportedSQL92ParserParameterizedTest.java index 6fb181ced7d0b..9ee80cec1aac2 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/UnsupportedSQL92ParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/test/java/org/apache/shardingsphere/sql/parser/sql92/UnsupportedSQL92ParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.sql92; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.UnsupportedSQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class UnsupportedSQL92ParserParameterizedTest extends UnsupportedSQLParserParameterizedTest { public UnsupportedSQL92ParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserParameterizedTest.java index 1408f6a308a2c..4a2cdadb7dc62 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.sqlserver; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.SQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class SQLServerParserParameterizedTest extends SQLParserParameterizedTest { public SQLServerParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/UnsupportedSQLServerParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/UnsupportedSQLServerParserParameterizedTest.java index f21ee353ed7e7..6461165d7ce2b 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/UnsupportedSQLServerParserParameterizedTest.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/test/java/org/apache/shardingsphere/sql/parser/sqlserver/UnsupportedSQLServerParserParameterizedTest.java @@ -17,15 +17,15 @@ package org.apache.shardingsphere.sql.parser.sqlserver; +import org.apache.shardingsphere.test.runner.ShardingSphereParallelTestParameterized; import org.apache.shardingsphere.test.sql.parser.parameterized.engine.UnsupportedSQLParserParameterizedTest; import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.sql.SQLCaseType; import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import java.util.Collection; -@RunWith(Parameterized.class) +@RunWith(ShardingSphereParallelTestParameterized.class) public final class UnsupportedSQLServerParserParameterizedTest extends UnsupportedSQLParserParameterizedTest { public UnsupportedSQLServerParserParameterizedTest(final String sqlCaseId, final String databaseType, final SQLCaseType sqlCaseType) { From 03e083eeb6c81c2916e191a4528b9f92c4f52a68 Mon Sep 17 00:00:00 2001 From: tianhao960 Date: Sun, 11 Sep 2022 22:36:02 +0800 Subject: [PATCH 5/6] refactor parallel test framework #5 --- ...baseTypeParallelRunnerExecutorFactory.java | 2 +- .../impl/ScenarioParallelRunnerExecutor.java | 40 ++++++-------- ...ardingSphereParallelTestParameterized.java | 3 +- .../DefaultParallelRunnerExecutorFactory.java | 8 +-- .../test/runner/parallel/ParallelRunner.java | 3 +- .../impl/DefaultParallelRunnerExecutor.java | 54 +++++++++++++++---- 6 files changed, 66 insertions(+), 44 deletions(-) diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java index 4025e6a2fb80d..204ae83948418 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/DatabaseTypeParallelRunnerExecutorFactory.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; /** - * Parallel runner executor factory. + * Database type parallel runner executor factory. */ public final class DatabaseTypeParallelRunnerExecutorFactory extends DefaultParallelRunnerExecutorFactory { diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java index d31edd086af43..b9d6d5890c711 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java @@ -17,47 +17,37 @@ package org.apache.shardingsphere.test.integration.framework.runner.parallel.impl; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import lombok.EqualsAndHashCode; -import org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorServiceManager; import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray; import org.apache.shardingsphere.test.runner.parallel.impl.DefaultParallelRunnerExecutor; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * Parallel runner executor with scenario. */ public final class ScenarioParallelRunnerExecutor extends DefaultParallelRunnerExecutor { - private final Map executorServiceManagers = new ConcurrentHashMap<>(); - @Override public void execute(final ParameterizedArray parameterizedArray, final Runnable childStatement) { - getTaskFeatures().add(getExecutorService(new ScenarioKey(parameterizedArray)).getExecutorService().submit(childStatement)); + getTaskFeatures().add(getExecutorService(parameterizedArray).submit(childStatement)); } - private ExecutorServiceManager getExecutorService(final ScenarioKey scenarioKey) { - if (executorServiceManagers.containsKey(scenarioKey)) { - return executorServiceManagers.get(scenarioKey); + @Override + public ExecutorService getExecutorService(final ParameterizedArray key) { + ScenarioKey scenarioKey = new ScenarioKey(key); + if (getExecutorServiceMap().containsKey(scenarioKey)) { + return getExecutorServiceMap().get(scenarioKey); } String threadPoolNameFormat = String.join("-", "ScenarioExecutorPool", scenarioKey.toString(), "%d"); - ExecutorServiceManager newExecutorServiceManager = new ExecutorServiceManager(1, threadPoolNameFormat); - if (null != executorServiceManagers.putIfAbsent(scenarioKey, newExecutorServiceManager)) { - newExecutorServiceManager.close(); + ExecutorService executorService = Executors.newFixedThreadPool( + Runtime.getRuntime().availableProcessors(), + new ThreadFactoryBuilder().setDaemon(true).setNameFormat(threadPoolNameFormat).build()); + if (null != getExecutorServiceMap().putIfAbsent(scenarioKey, executorService)) { + executorService.shutdownNow(); } - return executorServiceManagers.get(scenarioKey); - } - - @Override - public void finished() { - getTaskFeatures().forEach(each -> { - try { - each.get(); - } catch (final InterruptedException | ExecutionException ignored) { - } - }); - executorServiceManagers.values().forEach(each -> each.getExecutorService().shutdownNow()); + return getExecutorServiceMap().get(scenarioKey); } /** diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java index 9557acd174353..53f999a9f68a3 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/ShardingSphereParallelTestParameterized.java @@ -32,9 +32,8 @@ public final class ShardingSphereParallelTestParameterized extends Parameterized public ShardingSphereParallelTestParameterized(final Class clazz) throws Throwable { // CHECKSTYLE:ON super(clazz); - ParallelLevel level; ParallelRuntimeStrategy parallelRuntimeStrategy = clazz.getAnnotation(ParallelRuntimeStrategy.class); - level = null != parallelRuntimeStrategy ? parallelRuntimeStrategy.value() : ParallelLevel.DEFAULT; + ParallelLevel level = null != parallelRuntimeStrategy ? parallelRuntimeStrategy.value() : ParallelLevel.DEFAULT; setScheduler(new ParallelRunnerScheduler(level, new DefaultParallelRunnerExecutorFactory())); } } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java index b3f5d1791ae07..c06316d7a4f16 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/DefaultParallelRunnerExecutorFactory.java @@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; /** - * Parallel runner executor factory. + * Default parallel runner executor factory. */ public class DefaultParallelRunnerExecutorFactory implements ParallelRunnerExecutorFactory { @@ -55,7 +55,7 @@ public ParallelRunnerExecutor getExecutor(final T key, final ParallelLevel paral */ public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel) { if (null == defaultExecutor) { - synchronized (ParallelRunnerExecutor.class) { + synchronized (DefaultParallelRunnerExecutorFactory.class) { if (null == defaultExecutor) { defaultExecutor = new DefaultParallelRunnerExecutor(); } @@ -65,7 +65,8 @@ public ParallelRunnerExecutor getExecutor(final ParallelLevel parallelLevel) { } /** - * create executor instance by parallel level. + * Create executor instance by parallel level. + * * @param parallelLevel parallel level * @return executor by parallel level */ @@ -85,5 +86,4 @@ public Collection getAllExecutors() { } return executors; } - } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java index 06d91a4d0d446..10015ca6ae522 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunner.java @@ -22,7 +22,7 @@ import org.junit.runners.model.InitializationError; /** - * parallel runner for junit. + * Parallel runner for junit. */ public class ParallelRunner extends BlockJUnit4ClassRunner { @@ -37,5 +37,4 @@ public ParallelRunner(final Class klass) throws InitializationError { super(klass); setScheduler(new ParallelRunnerScheduler(ParallelLevel.DEFAULT, new DefaultParallelRunnerExecutorFactory())); } - } diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java index bc132d8a0ab2d..6016fac55dbfd 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java @@ -22,13 +22,15 @@ import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerExecutor; import java.util.Collection; import java.util.LinkedList; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; /** - * default parallel executor. + * Default parallel runner executor. * @param key type bind to parallel executor */ public class DefaultParallelRunnerExecutor implements ParallelRunnerExecutor { @@ -36,22 +38,51 @@ public class DefaultParallelRunnerExecutor implements ParallelRunnerExecutor< @Getter private final Collection> taskFeatures = new LinkedList<>(); - private final ExecutorService executorService; + @Getter + private final Map executorServiceMap = new ConcurrentHashMap<>(); - public DefaultParallelRunnerExecutor() { - executorService = Executors.newFixedThreadPool( - Runtime.getRuntime().availableProcessors(), - new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingSphere-ParallelTestThread-%d").build()); - } + private volatile ExecutorService defaultExecutorService; @Override public void execute(final T key, final Runnable childStatement) { - + taskFeatures.add(getExecutorService(key).submit(childStatement)); } @Override public void execute(final Runnable childStatement) { - taskFeatures.add(executorService.submit(childStatement)); + taskFeatures.add(getExecutorService().submit(childStatement)); + } + + private ExecutorService getExecutorService() { + if (null == defaultExecutorService) { + synchronized (DefaultParallelRunnerExecutor.class) { + if (null == defaultExecutorService) { + defaultExecutorService = Executors.newFixedThreadPool( + Runtime.getRuntime().availableProcessors(), + new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingSphere-ParallelTestThread-%d").build()); + } + } + } + return defaultExecutorService; + } + + /** + * get executor service by key. + * @param key key bind to the executor service + * @return executor service + */ + public ExecutorService getExecutorService(final T key) { + if (executorServiceMap.containsKey(key)) { + return executorServiceMap.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)) { + executorService.shutdownNow(); + } + return executorServiceMap.get(key); } @Override @@ -62,6 +93,9 @@ public void finished() { } catch (final InterruptedException | ExecutionException ignored) { } }); - executorService.shutdownNow(); + executorServiceMap.values().forEach(each -> each.shutdownNow()); + if (null != defaultExecutorService) { + defaultExecutorService.shutdownNow(); + } } } From 2f3f8bf2db18e82416c2f3fd17f5674fc11dc794 Mon Sep 17 00:00:00 2001 From: tianhao960 Date: Sun, 11 Sep 2022 23:47:09 +0800 Subject: [PATCH 6/6] refactor parallel test framework #7 --- ...ingSphereIntegrationTestParameterized.java | 4 +- .../ParameterizedParallelRunnerScheduler.java | 41 +++++++++++++++++++ .../impl/ScenarioParallelRunnerExecutor.java | 5 --- .../parallel/ParallelRunnerExecutor.java | 2 +- .../ParallelRunnerExecutorFactory.java | 8 ++-- .../parallel/ParallelRunnerScheduler.java | 7 +++- .../impl/DefaultParallelRunnerExecutor.java | 4 +- 7 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParameterizedParallelRunnerScheduler.java diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java index d357d9dcf2acf..d38bfa7f88e65 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/ShardingSphereIntegrationTestParameterized.java @@ -20,7 +20,7 @@ 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.DatabaseTypeParallelRunnerExecutorFactory; -import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerScheduler; +import org.apache.shardingsphere.test.integration.framework.runner.parallel.ParameterizedParallelRunnerScheduler; import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelRuntimeStrategy; import org.junit.runners.Parameterized; @@ -36,7 +36,7 @@ public ShardingSphereIntegrationTestParameterized(final Class clazz) throws T if (ClusterEnvironment.Type.DOCKER != IntegrationTestEnvironment.getInstance().getClusterEnvironment().getType()) { ParallelRuntimeStrategy parallelRuntimeStrategy = clazz.getAnnotation(ParallelRuntimeStrategy.class); if (null != parallelRuntimeStrategy) { - setScheduler(new ParallelRunnerScheduler(parallelRuntimeStrategy.value(), new DatabaseTypeParallelRunnerExecutorFactory())); + setScheduler(new ParameterizedParallelRunnerScheduler(parallelRuntimeStrategy.value(), new DatabaseTypeParallelRunnerExecutorFactory())); } } } diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParameterizedParallelRunnerScheduler.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParameterizedParallelRunnerScheduler.java new file mode 100644 index 0000000000000..ad3232cb18da7 --- /dev/null +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/ParameterizedParallelRunnerScheduler.java @@ -0,0 +1,41 @@ +/* + * 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.test.integration.framework.runner.parallel; + +import org.apache.shardingsphere.infra.database.type.DatabaseType; +import org.apache.shardingsphere.test.integration.framework.param.RunnerParameters; +import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray; +import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerExecutorFactory; +import org.apache.shardingsphere.test.runner.parallel.ParallelRunnerScheduler; +import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; + +/** + * Parameterized parallel runner scheduler. + */ +public class ParameterizedParallelRunnerScheduler extends ParallelRunnerScheduler { + + public ParameterizedParallelRunnerScheduler(final ParallelLevel parallelLevel, final ParallelRunnerExecutorFactory executorFactory) { + super(parallelLevel, executorFactory); + } + + @Override + public void schedule(final Runnable childStatement) { + ParameterizedArray parameterizedArray = new RunnerParameters(childStatement).getParameterizedArray(); + getExecutorFactory().getExecutor(parameterizedArray.getDatabaseType(), getParallelLevel()).execute(parameterizedArray, childStatement); + } +} diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java index b9d6d5890c711..91d91e90d62a3 100644 --- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/runner/parallel/impl/ScenarioParallelRunnerExecutor.java @@ -29,11 +29,6 @@ */ public final class ScenarioParallelRunnerExecutor extends DefaultParallelRunnerExecutor { - @Override - public void execute(final ParameterizedArray parameterizedArray, final Runnable childStatement) { - getTaskFeatures().add(getExecutorService(parameterizedArray).submit(childStatement)); - } - @Override public ExecutorService getExecutorService(final ParameterizedArray key) { ScenarioKey scenarioKey = new ScenarioKey(key); diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java index 3bbe86d4856d6..f7b21d7963ff5 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutor.java @@ -25,7 +25,7 @@ public interface ParallelRunnerExecutor { /** * Execute child statement. * - * @param key exector key + * @param key executor key * @param childStatement child statement */ void execute(T key, Runnable childStatement); diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java index a1324cd2e10f7..621a0ad2de6c4 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerExecutorFactory.java @@ -21,13 +21,14 @@ import java.util.Collection; /** - * executor factory. + * Parallel Runner Executor factory. * @param key type which bind to executor */ public interface ParallelRunnerExecutorFactory { /** - * get executor factory by key and parallel level. + * Get executor factory by key and parallel level. + * * @param key key bind to the factory * @param parallelLevel parallel level * @return executor by key and parallel level @@ -35,7 +36,8 @@ public interface ParallelRunnerExecutorFactory { ParallelRunnerExecutor getExecutor(T key, ParallelLevel parallelLevel); /** - * get factory by parallel level. + * Get factory by parallel level. + * * @param parallelLevel parallel level * @return executor by parallel level */ diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java index 454c73feed5c4..70e549907d4f8 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/ParallelRunnerScheduler.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.test.runner.parallel; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.test.runner.parallel.annotaion.ParallelLevel; import org.junit.runners.model.RunnerScheduler; @@ -25,11 +26,13 @@ * Parallel runner scheduler. */ @RequiredArgsConstructor -public final class ParallelRunnerScheduler implements RunnerScheduler { +public class ParallelRunnerScheduler implements RunnerScheduler { + @Getter private final ParallelLevel parallelLevel; - private final DefaultParallelRunnerExecutorFactory executorFactory; + @Getter + private final ParallelRunnerExecutorFactory executorFactory; @Override public void schedule(final Runnable childStatement) { diff --git a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java index 6016fac55dbfd..6135264e33e62 100644 --- a/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java +++ b/shardingsphere-test/shardingsphere-test-common/src/main/java/org/apache/shardingsphere/test/runner/parallel/impl/DefaultParallelRunnerExecutor.java @@ -35,7 +35,6 @@ */ public class DefaultParallelRunnerExecutor implements ParallelRunnerExecutor { - @Getter private final Collection> taskFeatures = new LinkedList<>(); @Getter @@ -67,7 +66,8 @@ private ExecutorService getExecutorService() { } /** - * get executor service by key. + * Get executor service by key. + * * @param key key bind to the executor service * @return executor service */