Skip to content

Commit

Permalink
Add/update JavaDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
centic9 committed Feb 1, 2024
1 parent 81af5a5 commit 99f6dbb
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main/java/org/dstadler/commons/testing/ThreadTestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public ThreadTestHelper(int threadCount, int testsPerThread) {
executions = new int[threadCount];
}

/**
* This method executes the passed {@link TestRunnable} in multiple
* threads.
*
* @param run {@link TestRunnable} to execute
* @throws Throwable if an exception happened during the execution of the {@link TestRunnable}
*/
public void executeTest(TestRunnable run) throws Throwable {
log.info("Starting thread test");

Expand Down Expand Up @@ -103,13 +110,14 @@ public void executeTest(TestRunnable run) throws Throwable {
}

/**
* This methods executes the passed {@link Callable}. The number of executions depends
* on the given runs number.
* This method executes the provided {@link Callable} in an {@link ExecutorService}.
*
* The number of executions is specified via the given number of runs.
*
* @param <T> The return-type for the {@link Callable} testable.
* @param testable test {@link Callable} to execute
* @param runs defines how many times the passed {@link Callable} is executed
* @return the results of the the execution of the passed {@link Callable}
* @return the results of the execution of the passed {@link Callable}
* @throws Throwable if an exception happened during the execution of the {@link Callable}
*/
public static <T> List<T> executeTest(final Callable<T> testable, int runs) throws Throwable {
Expand Down Expand Up @@ -170,9 +178,9 @@ private Thread startThread(final int threadNum, final TestRunnable run) {
executions[threadNum]++;
}

// do end-work here, we don't do this in a finally as we log
// Exception
// then anyway
// do end-work here, we don't do this in a finally-block to avoid follow-up
// exceptions to hide the root-cause if the doEnd() implementation is not
// done carefully
run.doEnd(threadNum);
} catch (Throwable e) {
// log.log(Level.SEVERE, "Caught unexpected Throwable", e);
Expand Down Expand Up @@ -212,6 +220,9 @@ public interface TestRunnable {
* This method should throw an Exception if any check fails at this
* point.
*
* Note: This method is not invoked any more if run() throws an exception
* to not "hide" the root-cause exception by follow-up exceptions here
*
* @param threadNum
* The number of the thread executing this doEnd()
* @throws Exception Thrown on any failure during running the test
Expand Down

0 comments on commit 99f6dbb

Please sign in to comment.