Package net.officefloor.frame.test
Class ThreadedTestSupport
java.lang.Object
net.officefloor.frame.test.ThreadedTestSupport
- All Implemented Interfaces:
TestSupport
TestSupport for multiple Thread tests.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceMulti-threaded execution.static interfaceMulti-threaded test logic interface.static interfacePredicate to check for is true. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Throwable>
voiddoMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test) Undertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends Throwable>
voiddoMultiThreadedTest(int threadCount, int iterationCount, ThreadedTestSupport.MultithreadedTestLogic<T> test) Undertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.voidinit(org.junit.jupiter.api.extension.ExtensionContext context) Intialise.booleanIndicates if the GUI is available.voidsleep(int time) Facade helper function for invokingThread.sleep(long).voidtimeout(long startTime) Facade method to timeout operations after 3 seconds.voidtimeout(long startTime, int secondsToRun) Facade method to timeout operations after a second.voidFacade method to timeout operations after a second.voidFacade method to timeout operations after 3 seconds.<T extends Throwable>
ThreadedTestSupport.MultiThreadedExecution<T>triggerMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test) Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends Throwable>
ThreadedTestSupport.MultiThreadedExecution<T>triggerMultiThreadedTest(int threadCount, int iterationCount, ThreadedTestSupport.MultithreadedTestLogic<T> test) Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends Throwable>
ThreadedTestSupport.MultiThreadedExecution<T>Triggers single threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends Throwable>
voidWaits for the check to betrue.<T extends Throwable>
voidwaitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun) Waits for the check to betrue.<T extends Throwable>
voidwaitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun, String message) Waits for the check to betrue.<T extends Throwable>
voidwaitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, String message) Waits for the check to betrue.
-
Constructor Details
-
ThreadedTestSupport
public ThreadedTestSupport()Default constructor.
-
-
Method Details
-
init
Description copied from interface:TestSupportIntialise.- Specified by:
initin interfaceTestSupport- Parameters:
context-ExtensionContext.- Throws:
Exception- If fails to init.
-
isGuiAvailable
public boolean isGuiAvailable()Indicates if the GUI is available.- Returns:
trueif the GUI is available.
-
doMultiThreadedTest
public <T extends Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T Undertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- Type Parameters:
T- PossibleThrowabletype.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofThreadedTestSupport.MultithreadedTestLogicperThread.test-ThreadedTestSupport.MultithreadedTestLogic.- Throws:
T- Possible failure from failingThreadedTestSupport.MultithreadedTestLogic.
-
doMultiThreadedTest
public <T extends Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T Undertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- Type Parameters:
T- PossibleThrowabletype.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofThreadedTestSupport.MultithreadedTestLogicperThread.timeout- Timeout.test-ThreadedTestSupport.MultithreadedTestLogic.- Throws:
T- Possible failure from failingThreadedTestSupport.MultithreadedTestLogic.
-
triggerThreadedTest
public <T extends Throwable> ThreadedTestSupport.MultiThreadedExecution<T> triggerThreadedTest(ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T Triggers single threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- Type Parameters:
T- PossibleThrowabletype.- Parameters:
test-ThreadedTestSupport.MultithreadedTestLogic.- Returns:
ThreadedTestSupport.MultiThreadedExecution.- Throws:
T- Possible failure from failingThreadedTestSupport.MultithreadedTestLogic.
-
triggerMultiThreadedTest
public <T extends Throwable> ThreadedTestSupport.MultiThreadedExecution<T> triggerMultiThreadedTest(int threadCount, int iterationCount, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- Type Parameters:
T- PossibleThrowabletype.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofThreadedTestSupport.MultithreadedTestLogicperThread.test-ThreadedTestSupport.MultithreadedTestLogic.- Returns:
ThreadedTestSupport.MultiThreadedExecution.- Throws:
T- Possible failure from failingThreadedTestSupport.MultithreadedTestLogic.
-
triggerMultiThreadedTest
public <T extends Throwable> ThreadedTestSupport.MultiThreadedExecution<T> triggerMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- Type Parameters:
T- PossibleThrowabletype.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofThreadedTestSupport.MultithreadedTestLogicperThread.timeout- Timeout.test-ThreadedTestSupport.MultithreadedTestLogic.- Returns:
ThreadedTestSupport.MultiThreadedExecution.- Throws:
T- Possible failure from failingThreadedTestSupport.MultithreadedTestLogic.
-
sleep
public void sleep(int time) Facade helper function for invokingThread.sleep(long).- Parameters:
time- Sleep time in seconds.
-
timeout
public void timeout(long startTime) Facade method to timeout operations after 3 seconds.- Parameters:
startTime- Start time fromSystem.currentTimeMillis().
-
timeout
Facade method to timeout operations after 3 seconds.- Parameters:
startTime- Start time fromSystem.currentTimeMillis().message- Message to include in possible failure.
-
timeout
public void timeout(long startTime, int secondsToRun) Facade method to timeout operations after a second.- Parameters:
startTime- Start time fromSystem.currentTimeMillis().secondsToRun- Seconds to run before timeout.
-
timeout
Facade method to timeout operations after a second.- Parameters:
startTime- Start time fromSystem.currentTimeMillis().secondsToRun- Seconds to run before timeout.message- Message to include in possible failure.
-
waitForTrue
public <T extends Throwable> void waitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check) throws T Waits for the check to betrue.- Type Parameters:
T- Possible failure type.- Parameters:
check- Check.- Throws:
T- Possible failure.
-
waitForTrue
public <T extends Throwable> void waitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, String message) throws T Waits for the check to betrue.- Type Parameters:
T- Possible failure type.- Parameters:
check- Check.message- Message to include in possible failure.- Throws:
T- Possible failure.
-
waitForTrue
public <T extends Throwable> void waitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun) throws T Waits for the check to betrue.- Type Parameters:
T- Possible failure type.- Parameters:
check- Check.secondsToRun- Seconds to wait before timing out.- Throws:
T- Possible failure.
-
waitForTrue
public <T extends Throwable> void waitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun, String message) throws T Waits for the check to betrue.- Type Parameters:
T- Possible failure type.- Parameters:
check- Check.secondsToRun- Seconds to wait before timing out.message- Message to include in possible failure.- Throws:
T- Possible failure.
-