本文整理汇总了Java中org.junit.runners.model.RunnerScheduler类的典型用法代码示例。如果您正苦于以下问题:Java RunnerScheduler类的具体用法?Java RunnerScheduler怎么用?Java RunnerScheduler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RunnerScheduler类属于org.junit.runners.model包,在下文中一共展示了RunnerScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parallelize
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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;
}
示例2: runChildren
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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();
}
}
示例3: runChildren
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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();
}
}
示例4: Parallelized
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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);
}
}
});
}
示例5: ParallelSuite
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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);
}
}
});
}
示例6: parallelize
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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;
}
示例7: useChildHarvester
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
@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);
}
示例8: ParallelParameterized
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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);
}
}
});
}
示例9: ParallelParameterized
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
/** 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);
}
}
});
}
示例10: setScheduler
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
@Override
public void setScheduler(RunnerScheduler scheduler) {
for (Runner child : getChildren()) {
if (child instanceof ParentRunner<?>) {
((ParentRunner<?>) child).setScheduler(scheduler);
}
}
}
示例11: ConcurrentJunitRunner
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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();
}
}
});
}
示例12: runChildren
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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();
}
}
示例13: runChildren
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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();
}
}
示例14: runChildren
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
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();
}
}
示例15: setScheduler
import org.junit.runners.model.RunnerScheduler; //导入依赖的package包/类
@Override
public void setScheduler(RunnerScheduler scheduler) {
super.setScheduler(scheduler);
this.scheduler = scheduler;
}