Skip to content

Commit

Permalink
IWF-107: Updating iwf-idl submodule to reflect changes for IdReusePol… (
Browse files Browse the repository at this point in the history
  • Loading branch information
stevo89519 authored Sep 26, 2024
1 parent 9fe4201 commit 4c9025f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion iwf-idl
22 changes: 22 additions & 0 deletions src/test/java/io/iworkflow/integ/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import io.iworkflow.core.WorkflowDefinitionException;
import io.iworkflow.core.WorkflowInfo;
import io.iworkflow.core.WorkflowOptions;
import io.iworkflow.core.WorkflowUncompletedException;
import io.iworkflow.core.exceptions.NoRunningWorkflowException;
import io.iworkflow.core.exceptions.WorkflowAlreadyStartedException;
import io.iworkflow.gen.models.Context;
import io.iworkflow.gen.models.ErrorSubStatus;
import io.iworkflow.gen.models.IDReusePolicy;
import io.iworkflow.gen.models.WorkflowConfig;
import io.iworkflow.gen.models.WorkflowStatus;
import io.iworkflow.integ.basic.AbnormalExitWorkflow;
import io.iworkflow.integ.basic.BasicWorkflow;
import io.iworkflow.integ.basic.EmptyInputWorkflow;
import io.iworkflow.integ.basic.EmptyInputWorkflowState1;
Expand Down Expand Up @@ -60,6 +62,26 @@ public void testBasicWorkflow() throws InterruptedException {
Assertions.fail("get results from closed workflow should fail");
}

@Test
public void testBasicWorkflowAbnormalExitReuse() {
final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);
final String wfId = "basic-abnormal-exit-reuse-test-id" + System.currentTimeMillis() / 1000;
final WorkflowOptions startOptions = ImmutableWorkflowOptions.builder()
.workflowIdReusePolicy(IDReusePolicy.ALLOW_IF_PREVIOUS_EXITS_ABNORMALLY)
.build();

final Integer input = 0;
client.startWorkflow(AbnormalExitWorkflow.class, wfId, 10, input, startOptions);
Assertions.assertThrows(WorkflowUncompletedException.class,
() -> client.getSimpleWorkflowResultWithWait(Integer.class, wfId));

// Starting a workflow with the same ID should be allowed since the previous failed abnormally
client.startWorkflow(BasicWorkflow.class, wfId, 10, input, startOptions);
// Wait for workflow to finish
final Integer output = client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
Assertions.assertEquals(input + 2, output);
}

@Test
public void testEmptyInputWorkflow() throws InterruptedException {
final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/io/iworkflow/integ/basic/AbnormalExitState1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.iworkflow.integ.basic;

import io.iworkflow.core.Context;
import io.iworkflow.core.StateDecision;
import io.iworkflow.core.WorkflowState;
import io.iworkflow.core.command.CommandResults;
import io.iworkflow.core.communication.Communication;
import io.iworkflow.core.persistence.Persistence;
import io.iworkflow.gen.models.RetryPolicy;
import io.iworkflow.gen.models.WorkflowStateOptions;

public class AbnormalExitState1 implements WorkflowState<Integer> {

@Override
public Class<Integer> getInputType() {
return Integer.class;
}

@Override
public StateDecision execute(
final Context context,
final Integer input,
final CommandResults commandResults,
Persistence persistence,
final Communication communication) {
throw new RuntimeException("abnormal exit state");
}

@Override
public WorkflowStateOptions getStateOptions() {
return new WorkflowStateOptions().executeApiRetryPolicy(
new RetryPolicy()
.maximumAttempts(1)
.backoffCoefficient(2f)
);
}
}
17 changes: 17 additions & 0 deletions src/test/java/io/iworkflow/integ/basic/AbnormalExitWorkflow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.iworkflow.integ.basic;

import com.google.common.collect.ImmutableList;
import io.iworkflow.core.ObjectWorkflow;
import io.iworkflow.core.StateDef;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AbnormalExitWorkflow implements ObjectWorkflow {

@Override
public List<StateDef> getWorkflowStates() {
return ImmutableList.of(StateDef.startingState(new AbnormalExitState1()));
}
}

0 comments on commit 4c9025f

Please sign in to comment.