|
25 | 25 | import static org.junit.Assert.assertTrue; |
26 | 26 | import static org.junit.Assert.fail; |
27 | 27 |
|
| 28 | +import com.google.common.util.concurrent.UncheckedExecutionException; |
28 | 29 | import com.uber.cadence.SignalExternalWorkflowExecutionFailedCause; |
29 | 30 | import com.uber.cadence.TimeoutType; |
30 | 31 | import com.uber.cadence.WorkflowExecution; |
@@ -634,6 +635,44 @@ public void testSyncUntypedAndStackTrace() throws InterruptedException { |
634 | 635 | assertEquals("activity10", result); |
635 | 636 | } |
636 | 637 |
|
| 638 | + public static class TestCancellationForWorkflowsWithFailedPromises implements TestWorkflow1 { |
| 639 | + |
| 640 | + @Override |
| 641 | + public String execute(String taskList) { |
| 642 | + Promise<String> failedPromise = |
| 643 | + Async.function( |
| 644 | + () -> { |
| 645 | + throw new UncheckedExecutionException(new Exception("Oh noo!")); |
| 646 | + }); |
| 647 | + Promise<String> failedPromise2 = |
| 648 | + Async.function( |
| 649 | + () -> { |
| 650 | + throw new UncheckedExecutionException(new Exception("Oh noo again!")); |
| 651 | + }); |
| 652 | + Workflow.await(() -> false); |
| 653 | + fail("unreachable"); |
| 654 | + return "done"; |
| 655 | + } |
| 656 | + } |
| 657 | + |
| 658 | + @Test |
| 659 | + public void WorkflowsWithFailedPromisesCanBeCancelled() { |
| 660 | + worker.registerWorkflowImplementationTypes( |
| 661 | + TestCancellationForWorkflowsWithFailedPromises.class); |
| 662 | + testEnvironment.start(); |
| 663 | + WorkflowStub client = |
| 664 | + workflowClient.newUntypedWorkflowStub( |
| 665 | + "TestWorkflow1::execute", newWorkflowOptionsBuilder(taskList).build()); |
| 666 | + client.start(taskList); |
| 667 | + client.cancel(); |
| 668 | + |
| 669 | + try { |
| 670 | + client.getResult(String.class); |
| 671 | + fail("unreachable"); |
| 672 | + } catch (CancellationException ignored) { |
| 673 | + } |
| 674 | + } |
| 675 | + |
637 | 676 | @Test |
638 | 677 | public void testWorkflowCancellation() { |
639 | 678 | startWorkerFor(TestSyncWorkflowImpl.class); |
|
0 commit comments