use of java.util.concurrent.CancellationException in project cadence-client by uber-java.
the class WorkflowDecisionContext method handleChildWorkflowExecutionCanceled.
void handleChildWorkflowExecutionCanceled(HistoryEvent event) {
ChildWorkflowExecutionCanceledEventAttributes attributes = event.getChildWorkflowExecutionCanceledEventAttributes();
WorkflowExecution execution = attributes.getWorkflowExecution();
String workflowId = execution.getWorkflowId();
if (decisions.handleChildWorkflowExecutionCanceled(workflowId)) {
OpenChildWorkflowRequestInfo scheduled = scheduledExternalWorkflows.remove(workflowId);
if (scheduled != null) {
CancellationException e = new CancellationException();
BiConsumer<byte[], Exception> completionCallback = scheduled.getCompletionCallback();
completionCallback.accept(null, e);
}
}
}
use of java.util.concurrent.CancellationException in project cadence-client by uber-java.
the class WorkflowTest method testDetachedScope.
@Test
public void testDetachedScope() throws InterruptedException {
startWorkerFor(TestDetachedCancellationScope.class);
WorkflowStub client = workflowClient.newUntypedWorkflowStub("TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build());
client.start();
// To let activityWithDelay start.
Thread.sleep(500);
client.cancel();
try {
client.getResult(String.class);
fail("unreachable");
} catch (CancellationException ignored) {
}
activitiesImpl.assertInvocations("activityWithDelay", "activity1", "activity2", "activity3");
}
use of java.util.concurrent.CancellationException in project cadence-client by uber-java.
the class WorkflowTest method testWorkflowCancellation.
@Test
public void testWorkflowCancellation() {
startWorkerFor(TestSyncWorkflowImpl.class);
WorkflowStub client = workflowClient.newUntypedWorkflowStub("TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build());
client.start();
client.cancel();
try {
client.getResult(String.class);
fail("unreachable");
} catch (CancellationException ignored) {
}
}
use of java.util.concurrent.CancellationException in project cadence-client by uber-java.
the class DeterministicRunnerTest method testDetachedCancellation.
@Test
public void testDetachedCancellation() throws Throwable {
trace.add("init");
DeterministicRunner d = new DeterministicRunnerImpl(() -> {
trace.add("root started");
CompletablePromise<Void> done = Workflow.newPromise();
Workflow.newDetachedCancellationScope(() -> {
Async.procedure(() -> {
trace.add("thread started");
WorkflowInternal.await("reason1", () -> unblock1 || CancellationScope.current().isCancelRequested());
if (CancellationScope.current().isCancelRequested()) {
done.completeExceptionally(new CancellationException());
} else {
done.complete(null);
}
trace.add("await done");
});
});
try {
done.get();
} catch (CancellationException e) {
trace.add("done cancelled");
}
trace.add("root done");
});
d.runUntilAllBlocked();
assertFalse(trace.toString(), d.isDone());
d.cancel("I just feel like it");
d.runUntilAllBlocked();
assertFalse(d.isDone());
String[] expected = new String[] { "init", "root started", "thread started" };
trace.setExpected(expected);
trace.assertExpected();
unblock1 = true;
d.runUntilAllBlocked();
assertTrue(d.stackTrace(), d.isDone());
expected = new String[] { "init", "root started", "thread started", "await done", "root done" };
trace.setExpected(expected);
}
use of java.util.concurrent.CancellationException in project cadence-client by uber-java.
the class DeterministicRunnerTest method testExplicitDetachedScopeCancellation.
@Test
public void testExplicitDetachedScopeCancellation() throws Throwable {
trace.add("init");
DeterministicRunner d = new DeterministicRunnerImpl(() -> {
trace.add("root started");
CompletablePromise<Void> var = Workflow.newPromise();
CancellationScope scope = Workflow.newDetachedCancellationScope(() -> {
trace.add("scope started");
var.completeFrom(newTimer(300));
trace.add("scope done");
});
trace.add("root before cancel");
scope.cancel("from root");
try {
var.get();
trace.add("after get");
} catch (CancellationException e) {
trace.add("scope cancelled");
}
trace.add("root done");
});
d.runUntilAllBlocked();
assertTrue(trace.toString(), d.isDone());
String[] expected = new String[] { "init", "root started", "scope started", "scope done", "root before cancel", "timer cancelled", "scope cancelled", "root done" };
trace.setExpected(expected);
}
Aggregations