another attempt to fix TestAbortingHeavyLoadQuery

This commit is contained in:
Axel Uhl
2024-08-29 14:19:19 +02:00
parent 348c0fcb22
commit 33799c421c
@@ -123,20 +123,30 @@ public class TestAbortingHeavyLoadQuery {
do {
Thread.sleep(10);
} while (query.getState() != QueryState.RUNNING);
// Aborting query and waiting for completion
Thread.sleep(AbortQueryDelay);
logExecution("Aborting query");
query.abort();
QueryResult<HashSet<Integer>> result = queryTask.get();
// Checking query, result and processor chain state
assertThat(query.getState(), is(QueryState.ABORTED));
assertThat(result.getState(), is(QueryResultState.ABORTED));
assertTrue("The result is not empty", result.isEmpty());
for (Processor<?, ?> processor : processors) {
assertTrue("Processor wasn't aborted", processor.isAborted());
}
// Execution of unfinished instructions
executor.shutdown();
boolean terminated = executor.awaitTermination(TerminationTimeout, TimeUnit.MILLISECONDS);
printExecutionRecord();
assertTrue("The executor didn't terminate in the given time", terminated);
// The query execution returned, so all processors have received the abort signal (checked below).
// The number of unfinished instructions mustn't change after this point
int unfinishedInstructionsCount = unfinishedInstructions.size();
Set<StatefulProcessorInstruction<?>> runningInstructions = new HashSet<>();
Set<StatefulProcessorInstruction<?>> notStartedInstructions = new HashSet<>();
for (StatefulProcessorInstruction<?> instruction : unfinishedInstructions) {
if (instruction.runWasCalled()) {
if (instruction.runWasCalled()) { // could be that computeResult still wasn't called because the instruction was aborted
runningInstructions.add(instruction);
} else {
notStartedInstructions.add(instruction);
@@ -146,21 +156,6 @@ public class TestAbortingHeavyLoadQuery {
runningInstructions.size() + " running, " + notStartedInstructions.size() + " not started");
printExecutionRecord();
assertThat("Number of unfinished instructions changed", runningInstructions.size() + notStartedInstructions.size(), is(unfinishedInstructionsCount));
// Checking query, result and processor chain state
assertThat(query.getState(), is(QueryState.ABORTED));
assertThat(result.getState(), is(QueryResultState.ABORTED));
assertTrue("The result is not empty", result.isEmpty());
for (Processor<?, ?> processor : processors) {
assertTrue("Processor wasn't aborted", processor.isAborted());
}
// Execution of unfinished instructions
executor.shutdown();
boolean terminated = executor.awaitTermination(TerminationTimeout, TimeUnit.MILLISECONDS);
printExecutionRecord();
assertTrue("The executor didn't terminate in the given time", terminated);
// Verify that the collection of unfinished instructions didn't change
assertThat("Number of unfinished instructions changed", unfinishedInstructions.size(), is(unfinishedInstructionsCount));
for (StatefulProcessorInstruction<?> instruction : unfinishedInstructions) {
@@ -173,11 +168,10 @@ public class TestAbortingHeavyLoadQuery {
for (StatefulProcessorInstruction<?> instruction : notStartedInstructions) {
assertTrue("A previously unstarted instruction was removed from unfinished instructions", unfinishedInstructions.contains(instruction));
}
// Checking state of unfinished instructions
for (StatefulProcessorInstruction<?> instruction : runningInstructions) {
assertTrue("computeResult() of a running unfinished instruction wasn't called", instruction.computeResultWasCalled());
assertTrue("computeResult() of a running unfinished instruction didn't finish", instruction.computeResultWasFinished());
assertTrue("computeResult() of a running unfinished instruction wasn't called", instruction.computeResultWasCalled() || instruction.getHandler().isAborted());
assertTrue("computeResult() of a running unfinished instruction didn't finish", !instruction.computeResultWasCalled() || instruction.computeResultWasFinished());
if (instruction instanceof StatefulBlockingInstruction) {
StatefulBlockingInstruction<?> blockingInstruction = (StatefulBlockingInstruction<?>) instruction;
assertTrue("computeResult() of a running heavy load instruction wasn't aborted", blockingInstruction.computeResultWasAborted());
@@ -185,7 +179,6 @@ public class TestAbortingHeavyLoadQuery {
}
for (StatefulProcessorInstruction<?> instruction : notStartedInstructions) {
assertTrue("run() of an unstarted unfinished instruction wasn't called", instruction.runWasCalled());
assertFalse("computeResult() of an unstarted unfinished instruction was called", instruction.computeResultWasCalled());
assertFalse("computeResult() of an unstarted unfinished instruction was finished", instruction.computeResultWasFinished());
}