Skip to content
Open
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 @@ -224,7 +224,7 @@ private void configureWorkflowImplementationsByTaskQueue(
Workers workers,
Collection<Class<?>> autoDiscoveredWorkflowImplementationClasses) {
for (Class<?> clazz : autoDiscoveredWorkflowImplementationClasses) {
WorkflowImpl annotation = clazz.getAnnotation(WorkflowImpl.class);
WorkflowImpl annotation = AnnotationUtils.findAnnotation(clazz, WorkflowImpl.class);
for (String taskQueue : annotation.taskQueues()) {
taskQueue = environment.resolvePlaceholders(taskQueue);
Worker worker = workerFactory.tryGetWorker(taskQueue);
Expand Down Expand Up @@ -303,7 +303,7 @@ private void configureNexusServiceBeansByTaskQueue(
private void configureWorkflowImplementationsByWorkerName(
Workers workers, Collection<Class<?>> autoDiscoveredWorkflowImplementationClasses) {
for (Class<?> clazz : autoDiscoveredWorkflowImplementationClasses) {
WorkflowImpl annotation = clazz.getAnnotation(WorkflowImpl.class);
WorkflowImpl annotation = AnnotationUtils.findAnnotation(clazz, WorkflowImpl.class);

for (String workerName : annotation.workers()) {
Worker worker = workers.getByName(workerName);
Expand Down
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();
}
}
}
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 {}
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);
}
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;
}
}
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);
}
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))

Copy link
Copy Markdown
Contributor

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.

Suggested change
.setStartToCloseTimeout(Duration.ofSeconds(1))
.setStartToCloseTimeout(Duration.ofSeconds(10))

.validateAndBuildWithDefaults());
return "composed:" + activity.execute(input);
}
}
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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ spring:
register-activity-beans: true
register-nexus-service-beans: true

---
spring:
config:
activate:
on-profile: auto-discovery-composed-annotation
temporal:
workers-auto-discovery:
enabled: true
workflow-packages:
- io.temporal.spring.boot.autoconfigure.composedannotation
register-activity-beans: true

---
spring:
config:
Expand Down
Loading