Skip to content

Issue/565/skilltrigger returnval #797

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

Merged
merged 5 commits into from
Nov 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public Optional<TypedData> getDataTargetTypedValue(String name) throws Exception
});
}

public Optional<BindingData> getOrAddDataTarget(UUID outputId, String name, Type target, boolean hasImplicitOutput) {
public Optional<BindingData> getOrAddDataTarget(UUID outputId, String name, Type target, boolean ignoreDefinition) {
DataTarget output = null;
if (this.isDataTargetValid(name, target)) {
output = this.getTarget(outputId).get(name);
if (output == null && (this.isDefinitionOutput(name) || hasImplicitOutput)) {
if (output == null && (this.isDefinitionOutput(name) || ignoreDefinition)) {
this.getTarget(outputId).put(name, output = rpcDataTargetFromType(target));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,22 @@ public List<ParamBindInfo> getParams() {
return params;
}

public boolean hasEffectiveReturnType(){
boolean nonVoidReturn = this.hasNonVoidReturnType();
// For function annotated with @HasImplicitOutput, we should allow it to send back data even function's return type is void
// Reference to https://github.com/microsoft/durabletask-java/issues/126
boolean implicitOutput = this.hasImplicitOutput();
return nonVoidReturn || implicitOutput;
}

public boolean hasImplicitOutput() {
return hasImplicitOutput;
}

public boolean hasNonVoidReturnType() {
Class<?> returnType = this.getMethod().getReturnType();
return !returnType.equals(void.class) && !returnType.equals(Void.class);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ else if (paramName == null && !paramBindingNameAnnotation.isEmpty()) {
BindingData actualArg = argument.orElseThrow(WrongMethodTypeException::new);
invokeInfo.appendArgument(actualArg.getValue());
}
// For function annotated with @HasImplicitOutput, we should allow it to send back data even function's return type is void
// Reference to https://github.com/microsoft/durabletask-java/issues/126
if (!method.getMethod().getReturnType().equals(void.class)
&& !method.getMethod().getReturnType().equals(Void.class)
|| method.hasImplicitOutput()) {
dataStore.getOrAddDataTarget(invokeInfo.getOutputsId(), BindingDataStore.RETURN_NAME, method.getMethod().getReturnType(), method.hasImplicitOutput());

if (method.hasEffectiveReturnType()){
dataStore.getOrAddDataTarget(invokeInfo.getOutputsId(), BindingDataStore.RETURN_NAME, method.getMethod().getReturnType(), true);
}

return invokeInfo;
} catch (Exception ex) {
ExceptionUtils.rethrow(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public <T> T getInstance(Class<T> functionClass) throws Exception {

@Test
public void testResolveArgumentsHasImplicitOutputTrue() throws Exception {
Method testMethod = this.getClass().getDeclaredMethod("testMethod");
Method testMethod = this.getClass().getDeclaredMethod("testMethodVoid");
when(methodBindInfo.hasNonVoidReturnType()).thenCallRealMethod();
when(methodBindInfo.hasEffectiveReturnType()).thenCallRealMethod();
when(methodBindInfo.hasImplicitOutput()).thenReturn(true);
when(methodBindInfo.getMethod()).thenReturn(testMethod);
when(methodBindInfo.getParams()).thenReturn(new ArrayList<>());
Expand All @@ -66,13 +68,40 @@ public void testResolveArgumentsHasImplicitOutputTrue() throws Exception {

@Test
public void testResolveArgumentsHasImplicitOutputFalse() throws Exception {
Method testMethod = this.getClass().getDeclaredMethod("testMethod");
Method testMethod = this.getClass().getDeclaredMethod("testMethodVoid");
when(methodBindInfo.hasNonVoidReturnType()).thenCallRealMethod();
when(methodBindInfo.hasEffectiveReturnType()).thenCallRealMethod();
when(methodBindInfo.hasImplicitOutput()).thenReturn(false);
when(methodBindInfo.getMethod()).thenReturn(testMethod);
when(methodBindInfo.getParams()).thenReturn(new ArrayList<>());
ParameterResolver.resolveArguments(executionContextDataSource);
assertFalse(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent());
}

public void testMethod() {}
@Test
public void testResolveArgumentsNonVoidReturnTypeTrue() throws Exception {
Method testMethod = this.getClass().getDeclaredMethod("testMethodNonVoid");
when(methodBindInfo.getMethod()).thenReturn(testMethod);
when(methodBindInfo.getParams()).thenReturn(new ArrayList<>());
when(methodBindInfo.hasNonVoidReturnType()).thenCallRealMethod(); // Ensures real logic is executed
when(methodBindInfo.hasImplicitOutput()).thenReturn(false);
when(methodBindInfo.hasEffectiveReturnType()).thenCallRealMethod();
ParameterResolver.resolveArguments(executionContextDataSource);
assertTrue(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent());
}

@Test
public void testResolveArgumentsNonVoidReturnTypeFalse() throws Exception {
Method testMethod = this.getClass().getDeclaredMethod("testMethodVoid");
when(methodBindInfo.getMethod()).thenReturn(testMethod);
when(methodBindInfo.getParams()).thenReturn(new ArrayList<>());
when(methodBindInfo.hasNonVoidReturnType()).thenCallRealMethod(); // Ensures real logic is executed
when(methodBindInfo.hasImplicitOutput()).thenReturn(false);
when(methodBindInfo.hasEffectiveReturnType()).thenCallRealMethod();
ParameterResolver.resolveArguments(executionContextDataSource);
assertFalse(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent());
}

public void testMethodVoid() {}
public String testMethodNonVoid() { return "test"; }
}