Package net.officefloor.frame.test
Class ThreadedTestSupport
- java.lang.Object
-
- net.officefloor.frame.test.ThreadedTestSupport
-
- All Implemented Interfaces:
TestSupport
public class ThreadedTestSupport extends java.lang.Object implements TestSupport
TestSupportfor multipleThreadtests.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceThreadedTestSupport.MultiThreadedExecution<T extends java.lang.Throwable>Multi-threaded execution.static interfaceThreadedTestSupport.MultithreadedTestLogic<T extends java.lang.Throwable>Multi-threaded test logic interface.static interfaceThreadedTestSupport.WaitForTruePredicate<T extends java.lang.Throwable>Predicate to check for is true.
-
Constructor Summary
Constructors Constructor Description ThreadedTestSupport()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends java.lang.Throwable>
voiddoMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test)Undertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends java.lang.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.booleanisGuiAvailable()Indicates 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.<T extends java.lang.Throwable>
ThreadedTestSupport.MultiThreadedExecution<T>triggerMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test)Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends java.lang.Throwable>
ThreadedTestSupport.MultiThreadedExecution<T>triggerMultiThreadedTest(int threadCount, int iterationCount, ThreadedTestSupport.MultithreadedTestLogic<T> test)Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends java.lang.Throwable>
ThreadedTestSupport.MultiThreadedExecution<T>triggerThreadedTest(ThreadedTestSupport.MultithreadedTestLogic<T> test)Triggers single threaded testing ofThreadedTestSupport.MultithreadedTestLogic.<T extends java.lang.Throwable>
voidwaitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check)Waits for the check to betrue.<T extends java.lang.Throwable>
voidwaitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun)Waits for the check to betrue.
-
-
-
Method Detail
-
init
public void init(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.ExceptionDescription copied from interface:TestSupportIntialise.- Specified by:
initin interfaceTestSupport- Parameters:
context-ExtensionContext.- Throws:
java.lang.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 java.lang.Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T extends java.lang.ThrowableUndertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofThreadedTestSupport.MultithreadedTestLogicperThread.test-ThreadedTestSupport.MultithreadedTestLogic.- Throws:
T- Possible failure from failingThreadedTestSupport.MultithreadedTestLogic.T extends java.lang.Throwable
-
doMultiThreadedTest
public <T extends java.lang.Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T extends java.lang.ThrowableUndertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- 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.T extends java.lang.Throwable
-
triggerThreadedTest
public <T extends java.lang.Throwable> ThreadedTestSupport.MultiThreadedExecution<T> triggerThreadedTest(ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T extends java.lang.Throwable
Triggers single threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- Parameters:
test-ThreadedTestSupport.MultithreadedTestLogic.- Returns:
ThreadedTestSupport.MultiThreadedExecution.- Throws:
T- Possible failure from failingThreadedTestSupport.MultithreadedTestLogic.T extends java.lang.Throwable
-
triggerMultiThreadedTest
public <T extends java.lang.Throwable> ThreadedTestSupport.MultiThreadedExecution<T> triggerMultiThreadedTest(int threadCount, int iterationCount, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T extends java.lang.Throwable
Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- 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.T extends java.lang.Throwable
-
triggerMultiThreadedTest
public <T extends java.lang.Throwable> ThreadedTestSupport.MultiThreadedExecution<T> triggerMultiThreadedTest(int threadCount, int iterationCount, int timeout, ThreadedTestSupport.MultithreadedTestLogic<T> test) throws T extends java.lang.Throwable
Triggers multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic.- 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.T extends java.lang.Throwable
-
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
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.
-
waitForTrue
public <T extends java.lang.Throwable> void waitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check) throws T extends java.lang.Throwable
Waits for the check to betrue.- Type Parameters:
T- Possible failure type.- Parameters:
check- Check.- Throws:
T- Possible failure.T extends java.lang.Throwable
-
waitForTrue
public <T extends java.lang.Throwable> void waitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun) throws T extends java.lang.Throwable
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.T extends java.lang.Throwable
-
-