public class MultithreadingTester extends Object
RunnableAsserts concurrently in multiple threads several times. Use this class for testing the robustness of thread-safe code like this:new MultithreadingTester().add(...).run();If an
Exception or Error is caught in any of the threads, the run() method (and therefore the test which calls the run() methods) will fail. Per default 100 threads are used whereby each thread executes its RunnableAssert 1000 times. You can change these settings like this:new MultithreadingTester().numThreads(...) .numRoundsPerThread(...) .add(...) .run();
| Constructor and Description |
|---|
MultithreadingTester() |
| Modifier and Type | Method and Description |
|---|---|
MultithreadingTester | add(Callable<?> callable, Callable<?>... moreCallables) Converts the given Callables into RunnableAsserts and adds them to this MultithreadingTester, returns this to allow method chaining. |
MultithreadingTester | add(Collection<RunnableAssert> runnableAsserts) |
MultithreadingTester | add(RunnableAssert runnableAssert, RunnableAssert... moreRunnableAsserts) |
MultithreadingTester | add(Runnable runnable, Runnable... moreRunnables) Converts the given Runnables into RunnableAsserts and adds them to this MultithreadingTester, returns this to allow method chaining. |
MultithreadingTester | numRoundsPerThread(int roundsPerThreads) Sets the number of rounds per thread, default is 1000, returns this to allow method chaining. |
MultithreadingTester | numThreads(int numThreads) |
void | run() Starts multiple threads, which execute the added RunnableAsserts several times. |
public MultithreadingTester numThreads(int numThreads)
public MultithreadingTester numRoundsPerThread(int roundsPerThreads)
1000, returns this to allow method chaining.public MultithreadingTester add(@Nonnull RunnableAssert runnableAssert, RunnableAssert... moreRunnableAsserts)
public MultithreadingTester add(@Nonnull Collection<RunnableAssert> runnableAsserts)
public MultithreadingTester add(@Nonnull Runnable runnable, Runnable... moreRunnables)
Runnables into RunnableAsserts and adds them to this MultithreadingTester, returns this to allow method chaining.public MultithreadingTester add(@Nonnull Callable<?> callable, Callable<?>... moreCallables)
Callables into RunnableAsserts and adds them to this MultithreadingTester, returns this to allow method chaining.public void run()
RunnableAsserts several times. This method blocks until all started threads are finished. If an Exception or Error is caught in any of the started threads, this method will also throw an Exception or Error.numThreads(int), numRoundsPerThread(int)Copyright © 2017. All rights reserved.