-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
Codecov Report
@@ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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())); | ||
} | ||
|
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { | ||
|
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
hi, @strongduanmu @terrymanu have changed code and reply as your review suggestion. thank you. |
There was a problem hiding this 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.
LGTM |
Fixes #20742.
Changes proposed in this pull request:
Before committing this PR, I'm sure that I have checked the following options:
mvn clean install -B -T2C -DskipTests -Dmaven.javadoc.skip=true -e
.