Java 类org.junit.runners.model.RunnerScheduler 实例源码
项目:marathonv5
文件:ParallelComputer.java
private static Runner parallelize(Runner runner) {
int nThreads = Integer.getInteger(Constants.NTHREADS, Runtime.getRuntime().availableProcessors());
LOGGER.info("Using " + nThreads + " threads.");
if (runner instanceof ParentRunner) {
((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
private final ExecutorService fService = Executors.newFixedThreadPool(nThreads);
@Override public void schedule(Runnable childStatement) {
fService.submit(childStatement);
}
@Override public void finished() {
try {
fService.shutdown();
fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
return runner;
}
项目:aaf-junit
文件:ConcurrentDependsOnRunner.java
private void runChildren(@SuppressWarnings("hiding") final RunNotifier notifier) {
RunnerScheduler currentScheduler = scheduler;
try {
List<FrameworkMethod> roots = graph.getRoots().stream().map(r -> nameToMethod.get(r)).collect(Collectors.toList());
for (FrameworkMethod each : roots) {
currentScheduler.schedule(new Runnable() {
@Override
public void run() {
ConcurrentDependsOnRunner.this.runChild(each, notifier);
}
});
}
} finally {
currentScheduler.finished();
}
}
项目:aaf-junit
文件:ConcurrentDependsOnClasspathSuite.java
private void runChildren(@SuppressWarnings("hiding") final RunNotifier notifier) {
RunnerScheduler currentScheduler = scheduler;
try {
List<Runner> roots = graph.getRoots().stream().map(r -> nameToRunner.get(r)).collect(Collectors.toList());
for (Runner each : roots) {
currentScheduler.schedule(new Runnable() {
@Override
public void run() {
ConcurrentDependsOnClasspathSuite.this.runChild(each, notifier);
}
});
}
} finally {
currentScheduler.finished();
}
}
项目:typometer
文件:Parallelized.java
public Parallelized(Class<?> klass) throws Throwable {
super(klass);
setScheduler(new RunnerScheduler() {
private final ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
public void schedule(Runnable childStatement) {
service.submit(childStatement);
}
public void finished() {
try {
service.shutdown();
service.awaitTermination(5, TimeUnit.MINUTES);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
项目:pf-java-client
文件:ParallelSuite.java
public ParallelSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
super(klass, builder);
setScheduler(new RunnerScheduler() {
private final ExecutorService service = Executors.newCachedThreadPool();
public void schedule(Runnable childStatement) {
service.submit(childStatement);
}
public void finished() {
try {
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
项目:sosiefier
文件:ParallelComputer.java
private static Runner parallelize(Runner runner) {
if (runner instanceof ParentRunner) {
((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
private final ExecutorService fService = Executors.newCachedThreadPool();
public void schedule(Runnable childStatement) {
fService.submit(childStatement);
}
public void finished() {
try {
fService.shutdown();
fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
return runner;
}
项目:sosiefier
文件:ParentRunnerTest.java
@Test
public void useChildHarvester() throws InitializationError {
log = "";
ParentRunner<?> runner = new BlockJUnit4ClassRunner(FruitTest.class);
runner.setScheduler(new RunnerScheduler() {
public void schedule(Runnable childStatement) {
log += "before ";
childStatement.run();
log += "after ";
}
public void finished() {
log += "afterAll ";
}
});
runner.run(new RunNotifier());
assertEquals("before apple after before banana after afterAll ", log);
}
项目:pal
文件:ParallelParameterized.java
public ParallelParameterized(Class<?> arg0) throws Throwable {
super(arg0);
setScheduler(new RunnerScheduler() {
private final ExecutorService service = Executors.newFixedThreadPool(8);
public void schedule(Runnable childStatement) {
service.submit(childStatement);
}
public void finished() {
try {
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
项目:lcm
文件:ParallelComputer.java
private static Runner parallelize(Runner runner) {
if (runner instanceof ParentRunner) {
((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
private final ExecutorService fService = Executors.newCachedThreadPool();
public void schedule(Runnable childStatement) {
fService.submit(childStatement);
}
public void finished() {
try {
fService.shutdown();
fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
return runner;
}
项目:junit
文件:ParallelComputer.java
private static Runner parallelize(Runner runner) {
if (runner instanceof ParentRunner) {
((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
private final ExecutorService fService = Executors.newCachedThreadPool();
public void schedule(Runnable childStatement) {
fService.submit(childStatement);
}
public void finished() {
try {
fService.shutdown();
fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
return runner;
}
项目:junit
文件:ParentRunnerTest.java
@Test
public void useChildHarvester() throws InitializationError {
log = "";
ParentRunner<?> runner = new BlockJUnit4ClassRunner(FruitTest.class);
runner.setScheduler(new RunnerScheduler() {
public void schedule(Runnable childStatement) {
log += "before ";
childStatement.run();
log += "after ";
}
public void finished() {
log += "afterAll ";
}
});
runner.run(new RunNotifier());
assertEquals("before apple after before banana after afterAll ", log);
}
项目:org.openntf.domino
文件:ParallelComputer.java
private static Runner parallelize(Runner runner) {
if (runner instanceof ParentRunner) {
((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
private final ExecutorService fService = Executors.newCachedThreadPool();
public void schedule(Runnable childStatement) {
fService.submit(childStatement);
}
public void finished() {
try {
fService.shutdown();
fService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
return runner;
}
项目:health-and-care-developer-network
文件:ParentRunnerTest.java
@Test
public void useChildHarvester() throws InitializationError {
log = "";
ParentRunner<?> runner = new BlockJUnit4ClassRunner(FruitTest.class);
runner.setScheduler(new RunnerScheduler() {
public void schedule(Runnable childStatement) {
log += "before ";
childStatement.run();
log += "after ";
}
public void finished() {
log += "afterAll ";
}
});
runner.run(new RunNotifier());
assertEquals("before apple after before banana after afterAll ", log);
}
项目:shabdiz
文件:ParallelParameterized.java
/** Coppied from super constructor: Only called reflectively. Do not use problematically. */
public ParallelParameterized(final Class<?> test_class) throws Throwable {
super(test_class);
final String index_as_string = System.getProperty(TEST_PARAM_INDEX);
next_host_index = new AtomicInteger();
parameter_index = index_as_string != null ? Integer.valueOf(index_as_string) : null;
configuration = getParallelizationAnnotation();
process_builder = new AgentBasedJavaProcessBuilder();
configure(configuration);
setScheduler(new RunnerScheduler() {
@Override
public void schedule(final Runnable childStatement) {
executor_service.execute(childStatement);
}
@Override
public void finished() {
executor_service.shutdown();
try {
executor_service.awaitTermination(10, TimeUnit.MINUTES);
}
catch (InterruptedException exc) {
throw new RuntimeException(exc);
}
}
});
}
项目:offheap-store
文件:ParallelParameterized.java
@Override
public void setScheduler(RunnerScheduler scheduler) {
for (Runner child : getChildren()) {
if (child instanceof ParentRunner<?>) {
((ParentRunner<?>) child).setScheduler(scheduler);
}
}
}
项目:commons-test
文件:ConcurrentJunitRunner.java
public ConcurrentJunitRunner(final Class<?> klass) throws InitializationError {
super(klass);
setScheduler(new RunnerScheduler() {
ExecutorService executorService = Executors.newFixedThreadPool(
klass.isAnnotationPresent(Concurrent.class) ?
klass.getAnnotation(Concurrent.class).threads() :
(int) (Runtime.getRuntime().availableProcessors() * 1.5),
new NamedThreadFactory(klass.getSimpleName()));
CompletionService<Void> completionService = new ExecutorCompletionService<>(executorService);
Queue<Future<Void>> tasks = new LinkedList<>();
@Override
public void schedule(Runnable childStatement) {
tasks.offer(completionService.submit(childStatement, null));
}
@Override
public void finished() {
try {
while (!tasks.isEmpty())
tasks.remove(completionService.take());
} catch (@SuppressWarnings("unused") InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
while (!tasks.isEmpty())
tasks.poll().cancel(true);
executorService.shutdownNow();
}
}
});
}
项目:sosiefier
文件:ParentRunner.java
private void runChildren(final RunNotifier notifier) {
final RunnerScheduler scheduler = fScheduler;
try {
for (final T each : getFilteredChildren()) {
scheduler.schedule(new Runnable() {
public void run() {
ParentRunner.this.runChild(each, notifier);
}
});
}
} finally {
scheduler.finished();
}
}
项目:pinpoint
文件:PinpointPluginTestRunner.java
private void runChildren(final RunNotifier notifier) {
final RunnerScheduler currentScheduler = scheduler;
try {
for (final FrameworkMethod each : getFilteredChildren()) {
currentScheduler.schedule(new Runnable() {
public void run() {
runChild(each, notifier);
}
});
}
} finally {
currentScheduler.finished();
}
}
项目:pinpoint
文件:PinpointPluginTestSuite.java
private void runChildren(final RunNotifier notifier) {
final RunnerScheduler currentScheduler = scheduler;
try {
for (final Runner each : getFilteredChildren()) {
currentScheduler.schedule(new Runnable() {
public void run() {
runChild(each, notifier);
}
});
}
} finally {
currentScheduler.finished();
}
}
项目:xtext-core
文件:AbstractParallelScenarioRunner.java
@Override
public void setScheduler(RunnerScheduler scheduler) {
super.setScheduler(scheduler);
this.scheduler = scheduler;
}
项目:commons-test
文件:ConcurrentSuite.java
public ConcurrentSuite(final Class<?> klass) throws InitializationError {
super(klass, new AllDefaultPossibilitiesBuilder(true) {
@Override
public Runner runnerForClass(Class<?> testClass) throws Throwable {
List<RunnerBuilder> builders = Arrays.asList(
new RunnerBuilder() {
@Override
public Runner runnerForClass(Class<?> testClass2) throws Throwable {
Concurrent annotation = testClass2.getAnnotation(Concurrent.class);
if (annotation != null)
return new ConcurrentJunitRunner(testClass2);
return null;
}
},
ignoredBuilder(),
annotatedBuilder(),
suiteMethodBuilder(),
junit3Builder(),
junit4Builder());
for (RunnerBuilder each : builders) {
Runner runner = each.safeRunnerForClass(testClass);
if (runner != null)
return runner;
}
return null;
}
});
setScheduler(new RunnerScheduler() {
ExecutorService executorService = Executors.newFixedThreadPool(
klass.isAnnotationPresent(Concurrent.class) ?
klass.getAnnotation(Concurrent.class).threads() :
(int) (Runtime.getRuntime().availableProcessors() * 1.5),
new NamedThreadFactory(klass.getSimpleName()));
CompletionService<Void> completionService = new ExecutorCompletionService<>(executorService);
Queue<Future<Void>> tasks = new LinkedList<>();
@Override
public void schedule(Runnable childStatement) {
tasks.offer(completionService.submit(childStatement, null));
}
@Override
public void finished() {
try {
while (!tasks.isEmpty())
tasks.remove(completionService.take());
} catch (@SuppressWarnings("unused") InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
while (!tasks.isEmpty())
tasks.poll().cancel(true);
executorService.shutdownNow();
}
}
});
}
项目:j2objc
文件:ParentRunner.java
/**
* Sets a scheduler that determines the order and parallelization
* of children. Highly experimental feature that may change.
*/
public void setScheduler(RunnerScheduler scheduler) {
this.fScheduler = scheduler;
}
项目:sosiefier
文件:ParentRunner.java
/**
* Sets a scheduler that determines the order and parallelization
* of children. Highly experimental feature that may change.
*/
public void setScheduler(RunnerScheduler scheduler) {
this.fScheduler = scheduler;
}
项目:lcm
文件:ParentRunner.java
/**
* Sets a scheduler that determines the order and parallelization
* of children. Highly experimental feature that may change.
*/
public void setScheduler(RunnerScheduler scheduler) {
this.fScheduler = scheduler;
}
项目:orwell
文件:Corollaries.java
/**
* Sets a scheduler that determines the order and parallelization
* of children. Highly experimental feature that may change.
*/
public void setScheduler(RunnerScheduler scheduler) {
this.fScheduler = scheduler;
}
项目:junit
文件:ParentRunner.java
/**
* Sets a scheduler that determines the order and parallelization
* of children. Highly experimental feature that may change.
*/
public void setScheduler(RunnerScheduler scheduler) {
this.fScheduler = scheduler;
}
项目:org.openntf.domino
文件:ParentRunner.java
/**
* Sets a scheduler that determines the order and parallelization
* of children. Highly experimental feature that may change.
*/
public void setScheduler(RunnerScheduler scheduler) {
this.fScheduler = scheduler;
}