Search in sources :

Example 96 with CancellationException

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);
        }
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) WorkflowExecution(com.uber.cadence.WorkflowExecution) ChildWorkflowExecutionCanceledEventAttributes(com.uber.cadence.ChildWorkflowExecutionCanceledEventAttributes) StartChildWorkflowFailedException(com.uber.cadence.workflow.StartChildWorkflowFailedException) ChildWorkflowTerminatedException(com.uber.cadence.workflow.ChildWorkflowTerminatedException) CancellationException(java.util.concurrent.CancellationException) ChildWorkflowTimedOutException(com.uber.cadence.workflow.ChildWorkflowTimedOutException) SignalExternalWorkflowException(com.uber.cadence.workflow.SignalExternalWorkflowException)

Example 97 with CancellationException

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");
}
Also used : WorkflowStub(com.uber.cadence.client.WorkflowStub) CancellationException(java.util.concurrent.CancellationException) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 98 with CancellationException

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) {
    }
}
Also used : WorkflowStub(com.uber.cadence.client.WorkflowStub) CancellationException(java.util.concurrent.CancellationException) DeterministicRunnerTest(com.uber.cadence.internal.sync.DeterministicRunnerTest) Test(org.junit.Test)

Example 99 with CancellationException

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);
}
Also used : CancellationException(java.util.concurrent.CancellationException) WorkflowTest(com.uber.cadence.workflow.WorkflowTest) Test(org.junit.Test)

Example 100 with CancellationException

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);
}
Also used : CancellationScope(com.uber.cadence.workflow.CancellationScope) CancellationException(java.util.concurrent.CancellationException) WorkflowTest(com.uber.cadence.workflow.WorkflowTest) Test(org.junit.Test)

Aggregations

CancellationException (java.util.concurrent.CancellationException)505 ExecutionException (java.util.concurrent.ExecutionException)150 Test (org.junit.Test)91 TimeoutException (java.util.concurrent.TimeoutException)76 ArrayList (java.util.ArrayList)47 CountDownLatch (java.util.concurrent.CountDownLatch)46 Future (java.util.concurrent.Future)46 IOException (java.io.IOException)42 ExecutorService (java.util.concurrent.ExecutorService)30 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)29 CompletableFuture (java.util.concurrent.CompletableFuture)28 Callable (java.util.concurrent.Callable)27 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)27 List (java.util.List)24 Map (java.util.Map)23 HashMap (java.util.HashMap)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 TimeUnit (java.util.concurrent.TimeUnit)20 CharStream (org.antlr.v4.runtime.CharStream)20 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)20