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
TestSupport
for multipleThread
tests.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ThreadedTestSupport.MultiThreadedExecution<T extends java.lang.Throwable>
Multi-threaded execution.static interface
ThreadedTestSupport.MultithreadedTestLogic<T extends java.lang.Throwable>
Multi-threaded test logic interface.static interface
ThreadedTestSupport.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
.void
init(org.junit.jupiter.api.extension.ExtensionContext context)
Intialise.boolean
isGuiAvailable()
Indicates if the GUI is available.void
sleep(int time)
Facade helper function for invokingThread.sleep(long)
.void
timeout(long startTime)
Facade method to timeout operations after 3 seconds.void
timeout(long startTime, int secondsToRun)
Facade method to timeout operations after a second.void
timeout(long startTime, int secondsToRun, java.lang.String message)
Facade method to timeout operations after a second.void
timeout(long startTime, java.lang.String message)
Facade method to timeout operations after 3 seconds.<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
.<T extends java.lang.Throwable>
voidwaitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun, java.lang.String message)
Waits for the check to betrue
.<T extends java.lang.Throwable>
voidwaitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, java.lang.String message)
Waits for the check to betrue
.
-
-
-
Method Detail
-
init
public void init(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception
Description copied from interface:TestSupport
Intialise.- Specified by:
init
in interfaceTestSupport
- Parameters:
context
-ExtensionContext
.- Throws:
java.lang.Exception
- If fails to init.
-
isGuiAvailable
public boolean isGuiAvailable()
Indicates if the GUI is available.- Returns:
true
if 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.Throwable
Undertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic
.- Parameters:
threadCount
- Number ofThread
instances to run in parallel.iterationCount
- Number of iterations ofThreadedTestSupport.MultithreadedTestLogic
perThread
.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.Throwable
Undertakes multi-threaded testing ofThreadedTestSupport.MultithreadedTestLogic
.- Parameters:
threadCount
- Number ofThread
instances to run in parallel.iterationCount
- Number of iterations ofThreadedTestSupport.MultithreadedTestLogic
perThread
.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 ofThread
instances to run in parallel.iterationCount
- Number of iterations ofThreadedTestSupport.MultithreadedTestLogic
perThread
.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 ofThread
instances to run in parallel.iterationCount
- Number of iterations ofThreadedTestSupport.MultithreadedTestLogic
perThread
.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, java.lang.String message)
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
public void timeout(long startTime, int secondsToRun, java.lang.String message)
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 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, java.lang.String message) throws T extends java.lang.Throwable
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.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
-
waitForTrue
public <T extends java.lang.Throwable> void waitForTrue(ThreadedTestSupport.WaitForTruePredicate<T> check, int secondsToRun, java.lang.String message) 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.message
- Message to include in possible failure.- Throws:
T
- Possible failure.T extends java.lang.Throwable
-
-