|
| 1 | +package io.iworkflow.integ; |
| 2 | + |
| 3 | +import io.iworkflow.core.Client; |
| 4 | +import io.iworkflow.core.ClientOptions; |
| 5 | +import io.iworkflow.core.WorkflowUncompletedException; |
| 6 | +import io.iworkflow.gen.models.WorkflowErrorType; |
| 7 | +import io.iworkflow.gen.models.WorkflowStatus; |
| 8 | +import io.iworkflow.integ.forcefail.ForceFailWorkflow; |
| 9 | +import io.iworkflow.integ.signal.BasicSignalWorkflow; |
| 10 | +import io.iworkflow.integ.stateapifail.StateApiFailWorkflow; |
| 11 | +import io.iworkflow.integ.stateapitimeout.StateApiTimeoutFailWorkflow; |
| 12 | +import io.iworkflow.spring.TestSingletonWorkerService; |
| 13 | +import io.iworkflow.spring.controller.WorkflowRegistry; |
| 14 | +import org.junit.jupiter.api.Assertions; |
| 15 | +import org.junit.jupiter.api.BeforeEach; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | + |
| 18 | +import java.util.concurrent.ExecutionException; |
| 19 | + |
| 20 | +public class WorkflowUncompletedTest { |
| 21 | + |
| 22 | + @BeforeEach |
| 23 | + public void setup() throws ExecutionException, InterruptedException { |
| 24 | + TestSingletonWorkerService.startWorkerIfNotUp(); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testWorkflowTimeout() throws InterruptedException { |
| 29 | + final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault); |
| 30 | + final String wfId = "testWorkflowTimeout" + System.currentTimeMillis() / 1000; |
| 31 | + final Integer input = 1; |
| 32 | + final String runId = client.startWorkflow( |
| 33 | + BasicSignalWorkflow.class, wfId, 1, input); |
| 34 | + |
| 35 | + try { |
| 36 | + client.getSimpleWorkflowResultWithWait(Integer.class, wfId); |
| 37 | + } catch (WorkflowUncompletedException e) { |
| 38 | + Assertions.assertEquals(runId, e.getRunId()); |
| 39 | + Assertions.assertEquals(WorkflowStatus.TIMEOUT, e.getClosedStatus()); |
| 40 | + Assertions.assertNull(e.getErrorSubType()); |
| 41 | + Assertions.assertNull(e.getErrorMessage()); |
| 42 | + Assertions.assertEquals(0, e.getStateResultsSize()); |
| 43 | + return; |
| 44 | + } |
| 45 | + Assertions.fail("no exception caught"); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testWorkflowCanceled() throws InterruptedException { |
| 50 | + final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault); |
| 51 | + final String wfId = "testWorkflowTimeout" + System.currentTimeMillis() / 1000; |
| 52 | + final Integer input = 1; |
| 53 | + final String runId = client.startWorkflow( |
| 54 | + BasicSignalWorkflow.class, wfId, 10, input); |
| 55 | + |
| 56 | + client.stopWorkflow(wfId, ""); |
| 57 | + |
| 58 | + try { |
| 59 | + client.getSimpleWorkflowResultWithWait(Integer.class, wfId); |
| 60 | + } catch (WorkflowUncompletedException e) { |
| 61 | + Assertions.assertEquals(runId, e.getRunId()); |
| 62 | + Assertions.assertEquals(WorkflowStatus.CANCELED, e.getClosedStatus()); |
| 63 | + Assertions.assertNull(e.getErrorSubType()); |
| 64 | + Assertions.assertNull(e.getErrorMessage()); |
| 65 | + Assertions.assertEquals(0, e.getStateResultsSize()); |
| 66 | + return; |
| 67 | + } |
| 68 | + Assertions.fail("no exception caught"); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testForceFailWorkflow() throws InterruptedException { |
| 73 | + final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault); |
| 74 | + final long startTs = System.currentTimeMillis(); |
| 75 | + final String wfId = "testForceFailWorkflow" + startTs / 1000; |
| 76 | + final Integer input = 5; |
| 77 | + |
| 78 | + final String runId = client.startWorkflow( |
| 79 | + ForceFailWorkflow.class, wfId, 10, input); |
| 80 | + |
| 81 | + try { |
| 82 | + client.getSimpleWorkflowResultWithWait(Integer.class, wfId); |
| 83 | + } catch (WorkflowUncompletedException e) { |
| 84 | + Assertions.assertEquals(runId, e.getRunId()); |
| 85 | + Assertions.assertEquals(WorkflowStatus.FAILED, e.getClosedStatus()); |
| 86 | + Assertions.assertEquals(WorkflowErrorType.STATE_DECISION_FAILING_WORKFLOW_ERROR_TYPE, e.getErrorSubType()); |
| 87 | + Assertions.assertNull(e.getErrorMessage()); |
| 88 | + Assertions.assertEquals(1, e.getStateResultsSize()); |
| 89 | + String out = e.getStateResult(0, String.class); |
| 90 | + Assertions.assertEquals("a failing message", out); |
| 91 | + return; |
| 92 | + } |
| 93 | + Assertions.fail("no exception caught"); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testStateApiFailWorkflow() throws InterruptedException { |
| 98 | + final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault); |
| 99 | + final long startTs = System.currentTimeMillis(); |
| 100 | + final String wfId = "testStateApiFailWorkflow" + startTs / 1000; |
| 101 | + final Integer input = 5; |
| 102 | + |
| 103 | + final String runId = client.startWorkflow( |
| 104 | + StateApiFailWorkflow.class, wfId, 10, input); |
| 105 | + |
| 106 | + try { |
| 107 | + client.getSimpleWorkflowResultWithWait(Integer.class, wfId); |
| 108 | + } catch (WorkflowUncompletedException e) { |
| 109 | + Assertions.assertEquals(runId, e.getRunId()); |
| 110 | + Assertions.assertEquals(WorkflowStatus.FAILED, e.getClosedStatus()); |
| 111 | + Assertions.assertEquals(WorkflowErrorType.STATE_API_FAIL_MAX_OUT_RETRY_ERROR_TYPE, e.getErrorSubType()); |
| 112 | + Assertions.assertTrue(e.getErrorMessage().contains("/api/v1/workflowState/decide")); |
| 113 | + Assertions.assertEquals(0, e.getStateResultsSize()); |
| 114 | + return; |
| 115 | + } |
| 116 | + Assertions.fail("no exception caught"); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void testStateApiTimeoutWorkflow() throws InterruptedException { |
| 121 | + final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault); |
| 122 | + final long startTs = System.currentTimeMillis(); |
| 123 | + final String wfId = "testStateApiTimeoutWorkflow" + startTs / 1000; |
| 124 | + final Integer input = 5; |
| 125 | + |
| 126 | + final String runId = client.startWorkflow( |
| 127 | + StateApiTimeoutFailWorkflow.class, wfId, 10, input); |
| 128 | + |
| 129 | + try { |
| 130 | + client.getSimpleWorkflowResultWithWait(Integer.class, wfId); |
| 131 | + } catch (WorkflowUncompletedException e) { |
| 132 | + Assertions.assertEquals(runId, e.getRunId()); |
| 133 | + Assertions.assertEquals(WorkflowStatus.FAILED, e.getClosedStatus()); |
| 134 | + Assertions.assertEquals(WorkflowErrorType.STATE_API_FAIL_MAX_OUT_RETRY_ERROR_TYPE, e.getErrorSubType()); |
| 135 | + Assertions.assertTrue( |
| 136 | + e.getErrorMessage().contains("activity StartToClose timeout"), |
| 137 | + e.getErrorMessage() |
| 138 | + ); |
| 139 | + Assertions.assertEquals(0, e.getStateResultsSize()); |
| 140 | + return; |
| 141 | + } |
| 142 | + Assertions.fail("no exception caught"); |
| 143 | + } |
| 144 | +} |
0 commit comments