Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor parallel executor framework for junit #20910

Merged
merged 6 commits into from
Sep 14, 2022

Conversation

tianhao960
Copy link
Contributor

@tianhao960 tianhao960 commented Sep 10, 2022

Fixes #20742.

Changes proposed in this pull request:

  • refactor parallel executor framework for junit
  • mv some implement from test-suit to test-common
  • use parallel executor to run test of sql parser

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have triggered maven check: mvn clean install -B -T2C -DskipTests -Dmaven.javadoc.skip=true -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.

@codecov-commenter
Copy link

codecov-commenter commented Sep 10, 2022

Codecov Report

Merging #20910 (2f3f8bf) into master (b7770e7) will increase coverage by 0.04%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master   #20910      +/-   ##
============================================
+ Coverage     61.64%   61.69%   +0.04%     
- Complexity     2462     2465       +3     
============================================
  Files          4022     4034      +12     
  Lines         55560    55578      +18     
  Branches       9422     9422              
============================================
+ Hits          34249    34287      +38     
+ Misses        18429    18410      -19     
+ Partials       2882     2881       -1     
Impacted Files Coverage Δ
.../shardingsphere/infra/check/SQLCheckException.java 0.00% <0.00%> (ø)
...ere/infra/lock/exception/TableLockedException.java 0.00% <0.00%> (ø)
...fra/exception/InvalidDataNodesFormatException.java 100.00% <0.00%> (ø)
.../lock/exception/TableLockWaitTimeoutException.java 0.00% <0.00%> (ø)
...here/sql/parser/exception/SQLParsingException.java 0.00% <0.00%> (ø)
...exception/OverallConnectionNotEnoughException.java 0.00% <0.00%> (ø)
...ser/core/kernel/KernelDistSQLStatementVisitor.java 0.00% <0.00%> (ø)
...andler/distsql/ral/UpdatableRALBackendHandler.java 100.00% <0.00%> (ø)
...external/sql/type/generic/GenericSQLException.java 0.00% <0.00%> (ø)
...external/sql/type/wrapper/SQLWrapperException.java 100.00% <0.00%> (ø)
... and 144 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@strongduanmu strongduanmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tianhao960, thank you for your great contribution. This PR is great, there are only a few minor issues that need to be optimized.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify java doc to Database type parallel runner executor factory.

*/
public final class ShardingSphereParallelTestParameterized extends Parameterized {

// CHECKSTYLE:OFF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add CHECKSTYLE:OFF here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check style don't allow throw Throwable and don't allow Catch Throwable, So turn off it temporary. This is follow the solution of class ShardingSphereIntegrationTestParameterized.

super(clazz);
ParallelLevel level;
ParallelRuntimeStrategy parallelRuntimeStrategy = clazz.getAnnotation(ParallelRuntimeStrategy.class);
level = null != parallelRuntimeStrategy ? parallelRuntimeStrategy.value() : ParallelLevel.DEFAULT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move ParallelLevel level; here.

/**
* Parallel runner executor factory.
*/
public class DefaultParallelRunnerExecutorFactory<T> implements ParallelRunnerExecutorFactory<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think use abstract modifier for DefaultParallelRunnerExecutorFactory is better?

Copy link
Contributor Author

@tianhao960 tianhao960 Sep 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShardingSphereParallelTestParameterized will create instance of DefaultParallelRunnerExecutorFactory. if make it abstract, then can't create instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShardingSphereParallelTestParameterized will create instance of DefaultParallelRunnerExecutorFactory. if make it abstract, then can't create instance

Ok, I got it.

import java.util.concurrent.ConcurrentHashMap;

/**
* Parallel runner executor factory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default parallel runner executor factory. may be better.

super(klass);
setScheduler(new ParallelRunnerScheduler(ParallelLevel.DEFAULT, new DefaultParallelRunnerExecutorFactory()));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this useless blank line.

import org.junit.runners.model.InitializationError;

/**
* parallel runner for junit.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please modify parallel to Parallel.


/**
* Parallel level.
*/
public enum ParallelLevel {

CASE, SCENARIO
CASE, SCENARIO, DEFAULT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the scenarios where DEFAULT is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParallelRunnerScheduler constructors use ParallelLevel as an input parameter;
ParallelRuntimeStrategy parallelRuntimeStrategy = clazz.getAnnotation(ParallelRuntimeStrategy.class); ParallelLevel level = null != parallelRuntimeStrategy ? parallelRuntimeStrategy.value() : ParallelLevel.DEFAULT; setScheduler(new ParallelRunnerScheduler(level, new DefaultParallelRunnerExecutorFactory()));

and I just don't want to use Case or Scenario as an default level which may be cause an confusion that why not use CaseParallelRunnerExecutor or ScenarioParallelRunnerExecutor as the executor


@Override
public void execute(final T key, final Runnable childStatement) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this useless blank line.

* default parallel executor.
* @param <T> key type bind to parallel executor
*/
public class DefaultParallelRunnerExecutor<T> implements ParallelRunnerExecutor<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think add abstract for DefaultParallelRunnerExecutor is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefaultParallelRunnerExecutorFactory need create instance of DefaultParallelRunnerExecutorFactory and have added an implement of method
@Override public void execute(final T key, final Runnable childStatement) { taskFeatures.add(getExecutorService(key).submit(childStatement)); }

the reason why not make DefaultParallelRunnerExecutorFactory and DefaultParallelRunnerExecutor as an abstract class is that users can just depend on test-common package , and don't depend on test-suite package

/**
* ShardingSphere integration test parameterized.
*/
public final class ShardingSphereParallelTestParameterized extends Parameterized {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class ShardingSphereIntegrationTestParameterized had still existed.
How about consider about reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this pr is based on the implement of framework of
ShardingSphereIntegrationTestParameterized. And the reason refactoring to move the implements to test-common package is that unit test cases could use this framework for parallel execution which just need to depend on test-common. And from my first thought is that ShardingSphereIntegrationTestParameterized is for integration test; while most of unit test cases don't want to depend on integration-test-suite package. and integration-test-suite could rely on test-common package. and I can't just move the framework implement from integration-test-suite package to test-common package, because the implement use some classes in integration modules and I don't want test-common package depend on it. so the basic idea of this refactor is that make an default parallel execution framework in test-common which follow the implement in integration-test-suite other than the part related with integration test, then other modules could use this framework in test-common for parallel testing . and the origin implement in integration-test-suite extend the framework in test-common for specific integration test cases.
thanks.

@tianhao960
Copy link
Contributor Author

hi, @strongduanmu @terrymanu have changed code and reply as your review suggestion. thank you.

Copy link
Member

@strongduanmu strongduanmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's wait @terrymanu review this pr again.

@terrymanu terrymanu merged commit 541a528 into apache:master Sep 14, 2022
@terrymanu
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants