org.junit.runners.model.RunnerScheduler Java Examples

The following examples show how to use org.junit.runners.model.RunnerScheduler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParallelComputer.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: Parallelized.java    From typometer with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example #3
Source File: ConcurrentJunitRunner.java    From Concurnas with MIT License 5 votes vote down vote up
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<Void>(executorService);
		Queue<Future<Void>> tasks = new LinkedList<Future<Void>>();

		@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 (InterruptedException e) {
				Thread.currentThread().interrupt();
			} finally {
				while (!tasks.isEmpty()) {
					tasks.poll().cancel(true);
				}
				executorService.shutdownNow();
			}
		}
	});
}
 
Example #4
Source File: ParallelParameterized.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
@Override
public void setScheduler(RunnerScheduler scheduler) {
  for (Runner child : getChildren()) {
    if (child instanceof ParentRunner<?>) {
      ((ParentRunner<?>) child).setScheduler(scheduler);
    }
  }
}
 
Example #5
Source File: PinpointPluginTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #6
Source File: PinpointPluginTestSuite.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #7
Source File: JustTestLahRunner.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
@Override
public void setScheduler(RunnerScheduler scheduler) {
  super.setScheduler(scheduler);
  multiThreadingAssumed = true;
}
 
Example #8
Source File: NeodymiumCucumberWrapper.java    From neodymium-library with MIT License 4 votes vote down vote up
@Override
public void setScheduler(RunnerScheduler scheduler)
{
    cucumber.setScheduler(scheduler);
}
 
Example #9
Source File: AbstractParallelScenarioRunner.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setScheduler(RunnerScheduler scheduler) {
	super.setScheduler(scheduler);
	this.scheduler = scheduler;
}
 
Example #10
Source File: AbstractParallelScenarioRunner.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setScheduler(RunnerScheduler scheduler) {
	super.setScheduler(scheduler);
	this.scheduler = scheduler;
}