fr.cnes.sirius.validate.parallel
Class ParallelRunner

java.lang.Object
  extended by fr.cnes.sirius.validate.parallel.ParallelRunner

public class ParallelRunner
extends Object

Runner for parallel tests written as ParallelTask instances.

Since:
1.2
Version:
$Id: ParallelRunner.java 17578 2017-05-10 12:20:20Z bignon $
Author:
cardosop
Use sample :
// Instantiate the tasks runner
final ParallelRunner runner = new ParallelRunner(5);
// Add task factories to the runner
runner.addTask(new TaskOneFactory(), 25);
runner.addTask(new TaskTwoFactory(), 15);
// Launch all tasks
final boolean result = runner.runAll();
Concurrency :
not thread-safe
Concurrency comment :
instantiates a thread pool, would not be reasonable to add even more threads to the mix.

Constructor Summary
ParallelRunner()
          Default constructor.
ParallelRunner(int iThreadPoolSize)
          Constructor with thread pool size parameter.
 
Method Summary
 void addTask(ParallelTaskFactory<?> taskFactory, int nbRuns)
          Adds a new task factory, with the number of instances it should provide, OR updates the number of instances if the task factory was added before.
 String getResultSummary()
          Gets the result summary.
 void resizeThreadPool(int thPoolSize)
          Resizes the thread pool.
 boolean runAll()
          Run all the tasks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParallelRunner

public ParallelRunner()
Default constructor.


ParallelRunner

public ParallelRunner(int iThreadPoolSize)
Constructor with thread pool size parameter.

Parameters:
iThreadPoolSize - thread pool size
Method Detail

addTask

public void addTask(ParallelTaskFactory<?> taskFactory,
                    int nbRuns)
Adds a new task factory, with the number of instances it should provide, OR updates the number of instances if the task factory was added before. The task factory provides ParallelTask instances. Each instance will be run once and produce a result.

Parameters:
taskFactory - the task factory
nbRuns - the number of instances to create, equal to the number of "runs" for the matching ParallelTask class.

getResultSummary

public String getResultSummary()
Gets the result summary.

Returns:
the result summary (empty string if called too early)

runAll

public boolean runAll()
               throws InterruptedException
Run all the tasks. Only ends when all the tasks have run.

Returns:
true if the results are as expected, false if some of the results differ from the reference.
Throws:
InterruptedException - in case of thread pool interruption

resizeThreadPool

public void resizeThreadPool(int thPoolSize)
Resizes the thread pool.

Parameters:
thPoolSize - new thread pool size


Copyright © 2017 CNES. All Rights Reserved.