Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing null to signal and fix returning empty completion results for getSimpleWorkflowResultWithWait API #128

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ See [samples](https://github.com/indeedeng/iwf-java-samples) for how to use this
## Gradle
```gradle
// https://mvnrepository.com/artifact/io.iworkflow/iwf-java-sdk
implementation 'io.iworkflow:iwf-java-sdk:1.2.6'
implementation 'io.iworkflow:iwf-java-sdk:1.2.+'
```
## Maven
```
<!-- https://mvnrepository.com/artifact/io.iworkflow/iwf-java-sdk -->
<dependency>
<groupId>io.iworkflow</groupId>
<artifactId>iwf-java-sdk</artifactId>
<version>1.2.6</version>
<version>1.2.+</version>
<type>pom</type>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ signing {
}

group = "io.iworkflow"
version = "1.2.6"
version = "1.2.7"

nexusPublishing {
repositories {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/iworkflow/core/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void signalWorkflow(
throw new IllegalArgumentException(String.format("Workflow %s doesn't have signal %s", wfType, signalChannelName));
}
Class<?> signalType = nameToTypeMap.get(signalChannelName);
if (!signalType.isInstance(signalValue)) {
if (signalValue != null && !signalType.isInstance(signalValue)) {
throw new IllegalArgumentException(String.format("Signal value is not of type %s", signalType.getName()));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/iworkflow/core/UnregisteredClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public <T> T getSimpleWorkflowResultWithWait(
String checkErrorMessage = "this workflow should have one or zero state output for using this API";
Preconditions.checkNotNull(workflowGetResponse.getResults(), checkErrorMessage);
Preconditions.checkArgument(workflowGetResponse.getResults().size() == 1, checkErrorMessage);
Preconditions.checkNotNull(workflowGetResponse.getResults().get(0).getCompletedStateOutput(), checkErrorMessage);
//Preconditions.checkNotNull(workflowGetResponse.getResults().get(0).getCompletedStateOutput(), checkErrorMessage);

final StateCompletionOutput output = workflowGetResponse.getResults().get(0);
return clientOptions.getObjectEncoder().decode(output.getCompletedStateOutput(), valueClass);
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/io/iworkflow/integ/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public void testEmptyInputWorkflow() throws InterruptedException {
//client.StartWorkflow(EmptyInputWorkflow.class, EmptyInputWorkflowState1.StateId, null, wfId, startOptions);
client.getUnregisteredClient().startWorkflow(EmptyInputWorkflow.CUSTOM_WF_TYPE, EmptyInputWorkflowState1.class.getSimpleName(), wfId, 10, null, startOptions);
// wait for workflow to finish
client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
Integer out = client.getSimpleWorkflowResultWithWait(Integer.class, wfId);

Assertions.assertNull(out);

try {
client.getSimpleWorkflowResultWithWait(Integer.class, "a wrong workflowId");
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/io/iworkflow/integ/SignalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.concurrent.ExecutionException;

import static io.iworkflow.integ.signal.BasicSignalWorkflow.SIGNAL_CHANNEL_NAME_1;
import static io.iworkflow.integ.signal.BasicSignalWorkflow.SIGNAL_CHANNEL_NAME_3;
import static io.iworkflow.integ.signal.BasicSignalWorkflowState2.TIMER_COMMAND_ID;

public class SignalTest {
Expand All @@ -37,6 +38,10 @@ public void testBasicSignalWorkflow() throws InterruptedException {
client.signalWorkflow(
BasicSignalWorkflow.class, wfId, runId, SIGNAL_CHANNEL_NAME_1, Integer.valueOf(2));

// test sending null signal
client.signalWorkflow(
BasicSignalWorkflow.class, wfId, runId, SIGNAL_CHANNEL_NAME_3, null);

Thread.sleep(1000);// wait for timer to be ready to skip
client.skipTimer(wfId, "", BasicSignalWorkflowState2.class, 1, TIMER_COMMAND_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ public class BasicSignalWorkflow implements Workflow {

public static final String SIGNAL_CHANNEL_NAME_2 = "test-signal-2";

public static final String SIGNAL_CHANNEL_NAME_3 = "test-signal-3";

@Override
public List<CommunicationMethodDef> getCommunicationSchema() {
return Arrays.asList(
SignalChannelDef.create(Integer.class, SIGNAL_CHANNEL_NAME_1),
SignalChannelDef.create(Integer.class, SIGNAL_CHANNEL_NAME_2)
SignalChannelDef.create(Integer.class, SIGNAL_CHANNEL_NAME_2),
SignalChannelDef.create(Void.class, SIGNAL_CHANNEL_NAME_3)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

import static io.iworkflow.integ.signal.BasicSignalWorkflow.SIGNAL_CHANNEL_NAME_1;
import static io.iworkflow.integ.signal.BasicSignalWorkflow.SIGNAL_CHANNEL_NAME_2;
import static io.iworkflow.integ.signal.BasicSignalWorkflow.SIGNAL_CHANNEL_NAME_3;

public class BasicSignalWorkflowState2 implements WorkflowState<Integer> {
public static final String SIGNAL_COMMAND_ID = "test-signal-id";
public static final String SIGNAL_COMMAND_ID_1 = "test-signal-1";
public static final String SIGNAL_COMMAND_ID_2 = "test-signal-2";
public static final String TIMER_COMMAND_ID = "test-timer-id";

@Override
public Class<Integer> getInputType() {
return Integer.class;
Expand All @@ -37,10 +39,11 @@ public CommandRequest start(
final Communication communication) {
return CommandRequest.forAnyCommandCombinationCompleted(
Arrays.asList(
Arrays.asList(SIGNAL_COMMAND_ID, TIMER_COMMAND_ID)
Arrays.asList(SIGNAL_COMMAND_ID_1, TIMER_COMMAND_ID)
),
SignalCommand.create(SIGNAL_COMMAND_ID, SIGNAL_CHANNEL_NAME_1),
SignalCommand.create(SIGNAL_COMMAND_ID, SIGNAL_CHANNEL_NAME_2),
SignalCommand.create(SIGNAL_COMMAND_ID_1, SIGNAL_CHANNEL_NAME_1),
SignalCommand.create(SIGNAL_COMMAND_ID_1, SIGNAL_CHANNEL_NAME_2),
SignalCommand.create(SIGNAL_COMMAND_ID_2, SIGNAL_CHANNEL_NAME_3),
TimerCommand.createByDuration(TIMER_COMMAND_ID, Duration.ofDays(365))
);
}
Expand All @@ -59,6 +62,12 @@ public StateDecision decide(
if (signalCommandResult2.getSignalRequestStatusEnum() != ChannelRequestStatus.WAITING) {
throw new RuntimeException("the second signal should be waiting");
}

SignalCommandResult signalCommandResult3 = commandResults.getAllSignalCommandResults().get(2);
if (signalCommandResult3.getSignalRequestStatusEnum() != ChannelRequestStatus.RECEIVED || !signalCommandResult3.getCommandId().equals(SIGNAL_COMMAND_ID_2)) {
throw new RuntimeException("the 3 signal should be received");
}

final TimerCommandResult timerResult = commandResults.getAllTimerCommandResults().get(0);
if (timerResult.getTimerStatus() != TimerStatus.FIRED) {
throw new RuntimeException("the timer should be fired");
Expand Down