in src/main/java/com/amazonaws/services/simpleworkflow/flow/junit/WorkflowTestStatement.java [112:187]
private void asyncEvaluate(final WorkflowTestBase workflowTest) throws Throwable, InterruptedException {
try {
workflowTest.scope = new AsyncScope() {
@Override
protected void doAsync() throws Throwable {
new TryCatchFinally() {
@Override
protected void doTry() throws Throwable {
workflowTest.beforeEvaluate(workflowTest.decisionContext);
base.evaluate();
}
@Override
protected void doCatch(Throwable e) throws Throwable {
if (e instanceof IllegalStateException) {
if ("Called outside of the workflow definition code.".equals(e.getMessage())) {
throw new RuntimeException(
"Possible use of \"timeout\" parameter of @Test annotation without using Flow JUnit runner. "
+ "Supported runners are FlowBlockJUnit4ClassRunner and FlowSpringJUnit4ClassRunner.",
e);
}
}
throw e;
}
@Override
protected void doFinally() throws Throwable {
workflowTest.afterEvaluate();
}
};
}
};
boolean outstandingTasks = false;
while (!workflowTest.scope.isComplete()) {
outstandingTasks = workflowTest.scope.eventLoop();
if (workflowTest.waits.size() == 0) {
Long toNextTimerDelay = workflowTest.workflowClock.fireTimers();
if (toNextTimerDelay == null) {
break;
}
long timeToSleep = (long) (toNextTimerDelay / workflowTest.clockAcceleration);
if (timeToSleep > 5) {
waitingOnTimer = true;
try {
// If you are using @Test(timeout=...) annotation and your test timed out
// pointing to the Thread.sleep that follows this comment consider
// changing test runner to FlowBlockJUnit4ClassRunner or
// FlowSpringJUnit4ClassRunner to enable asynchronous thread dump.
Thread.sleep(timeToSleep);
}
finally {
waitingOnTimer = false;
}
}
if (!workflowTest.scope.isComplete()) {
workflowTest.workflowClock.advanceMilliseconds(toNextTimerDelay);
}
continue;
}
for (Settable<Void> listener : workflowTest.waits) {
listener.set(null);
}
workflowTest.waits.clear();
}
if (!workflowTest.disableOutstandingTasksCheck && !outstandingTasks) {
throw new IllegalStateException("There are outstanding tasks after test completed execution: \n"
+ workflowTest.scope.getAsynchronousThreadDumpAsString());
}
}
finally {
workflowTest.afterEvaluate();
}
}