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 @@ -306,6 +306,7 @@ private void configureWorkflowImplementationsByWorkerName(
WorkflowImpl annotation = clazz.getAnnotation(WorkflowImpl.class);

for (String workerName : annotation.workers()) {
workerName = environment.resolvePlaceholders(workerName);
Worker worker = workers.getByName(workerName);
if (worker == null) {
throw new BeanDefinitionValidationException(
Expand All @@ -328,6 +329,7 @@ private void configureActivityBeansByWorkerName(
ActivityImpl annotation = AnnotationUtils.findAnnotation(targetClass, ActivityImpl.class);
if (annotation != null) {
for (String workerName : annotation.workers()) {
workerName = environment.resolvePlaceholders(workerName);
Worker worker = workers.getByName(workerName);
if (worker == null) {
throw new BeanDefinitionValidationException(
Expand All @@ -353,6 +355,7 @@ private void configureNexusServiceBeansByWorkerName(
AnnotationUtils.findAnnotation(targetClass, NexusServiceImpl.class);
if (annotation != null) {
for (String workerName : annotation.workers()) {
workerName = environment.resolvePlaceholders(workerName);
Worker worker = workers.getByName(workerName);
if (worker == null) {
throw new BeanDefinitionValidationException(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.temporal.spring.boot.autoconfigure;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.spring.boot.autoconfigure.byworkernameresolver.TestWorkflow;
import io.temporal.testing.TestWorkflowEnvironment;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest(classes = AutoDiscoveryByWorkerNameResolverTest.Configuration.class)
@ActiveProfiles(profiles = "auto-discovery-by-worker-name-resolver")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AutoDiscoveryByWorkerNameResolverTest {
@Autowired ConfigurableApplicationContext applicationContext;

@Autowired TestWorkflowEnvironment testWorkflowEnvironment;

@Autowired WorkflowClient workflowClient;

@BeforeEach
void setUp() {
applicationContext.start();
}

@Test
@Timeout(value = 10)
public void testWorkerNamePropertyResolution() {
TestWorkflow testWorkflow =
workflowClient.newWorkflowStub(
TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue("UnitTest").build());
String result = testWorkflow.execute("done");
Assertions.assertEquals("done", result);
}

@ComponentScan(
excludeFilters = {
@ComponentScan.Filter(
pattern =
"io\\.temporal\\.spring\\.boot\\.autoconfigure"
+ "\\.(bytaskqueue|byworkername|workerversioning)\\..*",
type = FilterType.REGEX)
})
public static class Configuration {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.temporal.spring.boot.autoconfigure.byworkernameresolver;

import io.temporal.activity.ActivityInterface;

@ActivityInterface
public interface TestActivity {
String execute(String input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.temporal.spring.boot.autoconfigure.byworkernameresolver;

import io.temporal.spring.boot.ActivityImpl;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component("ResolverTestActivityImpl")
@ActivityImpl(workers = "${worker.name}")
@Profile("auto-discovery-by-worker-name-resolver")
public class TestActivityImpl implements TestActivity {
@Override
public String execute(String input) {
return input;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.temporal.spring.boot.autoconfigure.byworkernameresolver;

import io.temporal.workflow.WorkflowInterface;
import io.temporal.workflow.WorkflowMethod;

@WorkflowInterface
public interface TestWorkflow {

@WorkflowMethod
String execute(String input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.temporal.spring.boot.autoconfigure.byworkernameresolver;

import io.temporal.activity.ActivityOptions;
import io.temporal.spring.boot.WorkflowImpl;
import io.temporal.workflow.Workflow;
import java.time.Duration;
import org.springframework.context.annotation.Profile;

@WorkflowImpl(workers = "${worker.name}")
@Profile("auto-discovery-by-worker-name-resolver")
public class TestWorkflowImpl implements TestWorkflow {

@Override
public String execute(String input) {
return Workflow.newActivityStub(
TestActivity.class,
ActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofSeconds(1))
.validateAndBuildWithDefaults())
.execute(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ spring:
register-activity-beans: true
register-nexus-service-beans: true

---
spring:
config:
activate:
on-profile: auto-discovery-by-worker-name-resolver
temporal:
workers:
- task-queue: UnitTest
name: mainWorker
workers-auto-discovery:
workflow-packages:
- io.temporal.spring.boot.autoconfigure.byworkernameresolver
register-activity-beans: true
worker:
name: mainWorker

---
spring:
config:
Expand Down