Skip to content
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 @@ -311,7 +311,7 @@ private void configureNexusServiceBeansByWorkerName(

private Collection<Class<?>> autoDiscoverWorkflowImplementations() {
ClassPathScanningCandidateComponentProvider scanner =
new ClassPathScanningCandidateComponentProvider(false);
new ClassPathScanningCandidateComponentProvider(false, environment);
scanner.addIncludeFilter(new AnnotationTypeFilter(WorkflowImpl.class));
Set<Class<?>> implementations = new HashSet<>();
for (String pckg : namespaceProperties.getWorkersAutoDiscovery().getPackages()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.temporal.spring.boot.autoconfigure;

import static org.junit.jupiter.api.Assertions.assertEquals;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import io.temporal.spring.boot.autoconfigure.bytaskqueue.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 = AutoDiscoveryWithProfileTest.Configuration.class)
@ActiveProfiles(profiles = "auto-discovery-with-profile")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AutoDiscoveryWithProfileTest {
@Autowired ConfigurableApplicationContext applicationContext;

@Autowired TestWorkflowEnvironment testWorkflowEnvironment;

@Autowired WorkflowClient workflowClient;

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

@Test
@Timeout(value = 10)
public void testAutoDiscoveryWithProfile() {
TestWorkflow testWorkflow =
workflowClient.newWorkflowStub(
TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue("UnitTest").build());
assertEquals("other workflow discovered", testWorkflow.execute("profile"));
}

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

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

@Component("TestActivityImpl")
@ActivityImpl(workers = "mainWorker")
@Profile("auto-discovery-with-profile")
public class OtherTestActivityImpl implements TestActivity {
@Override
public String execute(String input) {
return "other workflow " + input;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.temporal.spring.boot.autoconfigure.byworkername;

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

@WorkflowImpl(workers = "mainWorker")
@Profile("auto-discovery-with-profile")
public class OtherTestWorkflowImpl implements TestWorkflow {

// Test auto-wiring of the application context works, this is not indicative of a real-world use
// case as the workflow implementation should be stateless.
public OtherTestWorkflowImpl(ConfigurableApplicationContext applicationContext) {}

@Override
public String execute(String input) {
return Workflow.newActivityStub(
TestActivity.class,
ActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofSeconds(1))
.validateAndBuildWithDefaults())
.execute("discovered");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.temporal.spring.boot.autoconfigure.byworkername;

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

@Component("TestActivityImpl")
@ActivityImpl(workers = "mainWorker")
@Profile("!auto-discovery-with-profile")
public class TestActivityImpl implements TestActivity {
@Override
public String execute(String input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import io.temporal.workflow.Workflow;
import java.time.Duration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Profile;

@WorkflowImpl(workers = "mainWorker")
@Profile("!auto-discovery-with-profile")
public class TestWorkflowImpl implements TestWorkflow {

// Test auto-wiring of the application context works, this is not indicative of a real-world use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ spring:
packages:
- io.temporal.spring.boot.autoconfigure.byworkername

---
spring:
config:
activate:
on-profile: auto-discovery-with-profile
temporal:
workers:
- task-queue: UnitTest
name: mainWorker
workers-auto-discovery:
packages:
- io.temporal.spring.boot.autoconfigure.byworkername

---
spring:
config:
Expand Down
Loading