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

Validate with generic parameter types for workflow init #2318

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 @@ -58,7 +58,8 @@ public static Optional<Constructor<?>> getWorkflowInitConstructor(
throw new IllegalArgumentException(
"Constructor with @WorkflowInit annotation must be public: " + clazz.getName());
}
if (!Arrays.equals(ctor.getParameterTypes(), workflowMethod.get(0).getParameterTypes())) {
if (!Arrays.equals(
ctor.getGenericParameterTypes(), workflowMethod.get(0).getGenericParameterTypes())) {
throw new IllegalArgumentException(
"Constructor annotated with @WorkflowInit must have the same parameters as the workflow method: "
+ clazz.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import static org.junit.Assert.*;

import com.google.common.collect.ImmutableSet;
import io.temporal.common.converter.EncodedValuesTest;
import io.temporal.workflow.WorkflowInit;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -229,6 +231,26 @@ public void testWorkflowWithConstructor() {
Assert.assertNull(meta.getWorkflowInit());
}

@Test
public void testWorkflowWithGenericInput() {
POJOWorkflowImplMetadata meta =
POJOWorkflowImplMetadata.newInstance(WorkflowWithGenericInput.class);
Assert.assertNotNull(meta.getWorkflowInit());
}

@Test
public void testWorkflowWithGenericInputMismatchedInit() {
try {
POJOWorkflowImplMetadata.newInstance(WorkflowWithGenericInputMismatchedInit.class);
Assert.fail();
} catch (IllegalArgumentException e) {
assertTrue(
e.getMessage()
.contains(
"Constructor annotated with @WorkflowInit must have the same parameters as the workflow method:"));
}
}

@Test
public void testWorkflowWithConstructorArgsNoInit() {
try {
Expand Down Expand Up @@ -403,4 +425,21 @@ public WorkflowWithConstructorParameters(Integer i) {}
@Override
public void i() {}
}

public static class WorkflowWithGenericInput implements POJOWorkflowInterfaceMetadataTest.K {
@WorkflowInit
public WorkflowWithGenericInput(Map<String, EncodedValuesTest.Pair> input) {}

@Override
public void f(Map<String, EncodedValuesTest.Pair> input) {}
}

public static class WorkflowWithGenericInputMismatchedInit
implements POJOWorkflowInterfaceMetadataTest.K {
@WorkflowInit
public WorkflowWithGenericInputMismatchedInit(Map<String, Object> input) {}

@Override
public void f(Map<String, EncodedValuesTest.Pair> input) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import static org.junit.Assert.*;

import io.temporal.common.converter.EncodedValuesTest;
import io.temporal.common.metadata.testclasses.WorkflowInterfaceWithOneWorkflowMethod;
import io.temporal.worker.Worker;
import io.temporal.workflow.*;
Expand Down Expand Up @@ -271,6 +272,12 @@ public interface I {
void i();
}

@WorkflowInterface
public interface K {
@WorkflowMethod
void f(Map<String, EncodedValuesTest.Pair> input);
}

public interface DE extends D, E {}

@WorkflowInterface
Expand Down
Loading