fixing TestAbortingHeavyLoadQuery for good

This commit is contained in:
Axel Uhl
2024-08-27 13:16:04 +02:00
parent 918c6644e9
commit 68aa245f37
2 changed files with 11 additions and 7 deletions
@@ -83,7 +83,7 @@ public class TestAbortingHeavyLoadQuery {
/** The time a step of a heavy load instruction blocks the executing thread (using {@link Thread#sleep(long)}). */
private static final long HeavyLoadInstructionStepDuration = 50;
/** The number of steps a heavy load instruction performs */
private static final int HeavyLoadInstructionNumberOfSteps = 100;
private static final int HeavyLoadInstructionNumberOfSteps = 10;
/** The total time a heavy load instruction blocks the executing thread (using {@link Thread#sleep(long)}). */
private static final long HeavyLoadInstructionTotalDuration = HeavyLoadInstructionStepDuration * HeavyLoadInstructionNumberOfSteps;
@@ -30,18 +30,22 @@ public class StatefulBlockingInstruction<ResultType> extends StatefulProcessorIn
protected ResultType internalComputeResult() throws Exception {
if (getTotalBlockDuration() > 0) {
actionBeforeBlock();
for (int i = 0; i < numberOfSteps; i++) {
if (isAborted()) {
actionBeforeAbort();
computeResultWasAborted = true;
break;
}
for (int i = 0; !checkIsAborted() && i < numberOfSteps; i++) {
Thread.sleep(stepDuration);
}
actionAfterBlock();
}
return result;
}
private boolean checkIsAborted() {
final boolean result = isAborted();
if (result) {
actionBeforeAbort();
computeResultWasAborted = true;
}
return result;
}
protected void actionBeforeBlock() { }
protected void actionBeforeAbort() { }