-
Notifications
You must be signed in to change notification settings - Fork 238
Fix NPE when a workflow implementation uses a composed @WorkflowImpl annotation #3024
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
Open
muhrifqii
wants to merge
2
commits into
temporalio:main
Choose a base branch
from
muhrifqii:worker-template-spring-annotation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../test/java/io/temporal/spring/boot/autoconfigure/AutoDiscoveryComposedAnnotationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package io.temporal.spring.boot.autoconfigure; | ||
|
|
||
| import io.temporal.client.WorkflowClient; | ||
| import io.temporal.client.WorkflowOptions; | ||
| import io.temporal.spring.boot.autoconfigure.composedannotation.ComposedAnnotatedActivityImpl; | ||
| import io.temporal.spring.boot.autoconfigure.composedannotation.ComposedAnnotatedWorkflow; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInstance; | ||
| import org.junit.jupiter.api.Timeout; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.context.ConfigurableApplicationContext; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.ComponentScan; | ||
| import org.springframework.context.annotation.FilterType; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
|
|
||
| @SpringBootTest(classes = AutoDiscoveryComposedAnnotationTest.Configuration.class) | ||
| @ActiveProfiles(profiles = "auto-discovery-composed-annotation") | ||
| @TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
| public class AutoDiscoveryComposedAnnotationTest { | ||
| @Autowired ConfigurableApplicationContext applicationContext; | ||
|
|
||
| @Autowired WorkflowClient workflowClient; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| applicationContext.start(); | ||
| } | ||
|
|
||
| @Test | ||
| @Timeout(value = 10) | ||
| public void testAutoDiscoveryViaComposedAnnotation() { | ||
| ComposedAnnotatedWorkflow workflow = | ||
| workflowClient.newWorkflowStub( | ||
| ComposedAnnotatedWorkflow.class, | ||
| WorkflowOptions.newBuilder().setTaskQueue("UnitTest").build()); | ||
| Assertions.assertEquals("composed:composed-activity:hi", workflow.execute("hi")); | ||
| } | ||
|
|
||
| @ComponentScan( | ||
| excludeFilters = | ||
| @ComponentScan.Filter( | ||
| pattern = | ||
| "io\\.temporal\\.spring\\.boot\\.autoconfigure\\.(bytaskqueue|byworkername)\\..*", | ||
| type = FilterType.REGEX)) | ||
| public static class Configuration { | ||
|
|
||
| // Not using @Component so that it stays scoped to this test | ||
| @Bean | ||
| public ComposedAnnotatedActivityImpl composedAnnotatedActivityImpl() { | ||
| return new ComposedAnnotatedActivityImpl(); | ||
| } | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...t/java/io/temporal/spring/boot/autoconfigure/composedannotation/ComposedActivityImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package io.temporal.spring.boot.autoconfigure.composedannotation; | ||
|
|
||
| import io.temporal.spring.boot.ActivityImpl; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| @ActivityImpl(taskQueues = "UnitTest") | ||
| public @interface ComposedActivityImpl {} |
8 changes: 8 additions & 0 deletions
8
...a/io/temporal/spring/boot/autoconfigure/composedannotation/ComposedAnnotatedActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package io.temporal.spring.boot.autoconfigure.composedannotation; | ||
|
|
||
| import io.temporal.activity.ActivityInterface; | ||
|
|
||
| @ActivityInterface | ||
| public interface ComposedAnnotatedActivity { | ||
| String execute(String input); | ||
| } |
10 changes: 10 additions & 0 deletions
10
.../temporal/spring/boot/autoconfigure/composedannotation/ComposedAnnotatedActivityImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.temporal.spring.boot.autoconfigure.composedannotation; | ||
|
|
||
| @ComposedActivityImpl | ||
| public class ComposedAnnotatedActivityImpl implements ComposedAnnotatedActivity { | ||
|
|
||
| @Override | ||
| public String execute(String input) { | ||
| return "composed-activity:" + input; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...a/io/temporal/spring/boot/autoconfigure/composedannotation/ComposedAnnotatedWorkflow.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package io.temporal.spring.boot.autoconfigure.composedannotation; | ||
|
|
||
| import io.temporal.workflow.WorkflowInterface; | ||
| import io.temporal.workflow.WorkflowMethod; | ||
|
|
||
| @WorkflowInterface | ||
| public interface ComposedAnnotatedWorkflow { | ||
|
|
||
| @WorkflowMethod | ||
| String execute(String input); | ||
| } |
20 changes: 20 additions & 0 deletions
20
.../temporal/spring/boot/autoconfigure/composedannotation/ComposedAnnotatedWorkflowImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package io.temporal.spring.boot.autoconfigure.composedannotation; | ||
|
|
||
| import io.temporal.activity.ActivityOptions; | ||
| import io.temporal.workflow.Workflow; | ||
| import java.time.Duration; | ||
|
|
||
| @ComposedWorkflowImpl | ||
| public class ComposedAnnotatedWorkflowImpl implements ComposedAnnotatedWorkflow { | ||
|
|
||
| @Override | ||
| public String execute(String input) { | ||
| ComposedAnnotatedActivity activity = | ||
| Workflow.newActivityStub( | ||
| ComposedAnnotatedActivity.class, | ||
| ActivityOptions.newBuilder() | ||
| .setStartToCloseTimeout(Duration.ofSeconds(1)) | ||
| .validateAndBuildWithDefaults()); | ||
| return "composed:" + activity.execute(input); | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
...t/java/io/temporal/spring/boot/autoconfigure/composedannotation/ComposedWorkflowImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package io.temporal.spring.boot.autoconfigure.composedannotation; | ||
|
|
||
| import io.temporal.spring.boot.WorkflowImpl; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| @WorkflowImpl(taskQueues = "UnitTest") | ||
| public @interface ComposedWorkflowImpl {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeout needs to be longer so that it works reliably in CI environment.