Skip to content

Commit 0bfa910

Browse files
authored
fix(spring-boot): use in-memory test server for non-root namespaces (#2736)
* fix(spring-boot): use in-memory test server for non-root namespaces\n\nFixes #2735.\n\n- Resolve TestWorkflowEnvironmentAdapter by type, fallback to correct bean name\n- Add regression test ensuring non-root namespaces use in-memory env even with connection.target set\n- Format code via spotlessApply * test(spring-boot): avoid javax.annotation.Resource in test to fix CI
1 parent b949929 commit 0bfa910

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootBeanPostProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ public Object postProcessAfterInitialization(@Nonnull Object bean, @Nonnull Stri
7171
// optional dependencies.
7272
metricsScope = findBean("temporalMetricsScope", Scope.class);
7373
tracer = findBean(Tracer.class);
74-
testWorkflowEnvironment =
75-
findBean("temporalTestWorkflowEnvironment", TestWorkflowEnvironmentAdapter.class);
74+
// Prefer resolving by type; fall back to the correctly named adapter bean
75+
testWorkflowEnvironment = findBean(TestWorkflowEnvironmentAdapter.class);
76+
if (testWorkflowEnvironment == null) {
77+
testWorkflowEnvironment =
78+
findBean(
79+
"temporalTestWorkflowEnvironmentAdapter", TestWorkflowEnvironmentAdapter.class);
80+
}
7681
namespaceProperties.forEach(this::injectBeanByNonRootNamespace);
7782
}
7883
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.temporal.spring.boot.autoconfigure;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import io.grpc.health.v1.HealthCheckResponse;
6+
import io.temporal.serviceclient.WorkflowServiceStubs;
7+
import io.temporal.testing.TestWorkflowEnvironment;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.TestInstance;
11+
import org.junit.jupiter.api.Timeout;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.beans.factory.annotation.Qualifier;
14+
import org.springframework.boot.test.context.SpringBootTest;
15+
import org.springframework.context.ConfigurableApplicationContext;
16+
import org.springframework.context.annotation.ComponentScan;
17+
import org.springframework.context.annotation.FilterType;
18+
19+
@SpringBootTest(
20+
classes = NonRootNamespacesUseTestServerTest.Configuration.class,
21+
properties = {
22+
"spring.temporal.test-server.enabled=true",
23+
"spring.temporal.connection.target=127.0.0.1:7233",
24+
"spring.temporal.start-workers=false",
25+
"spring.temporal.namespaces[0].namespace=pomegranate",
26+
"spring.temporal.namespaces[0].alias=pomegranate"
27+
})
28+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
29+
public class NonRootNamespacesUseTestServerTest {
30+
31+
@Autowired ConfigurableApplicationContext applicationContext;
32+
33+
@Autowired
34+
@Qualifier("temporalTestWorkflowEnvironment")
35+
TestWorkflowEnvironment testWorkflowEnvironment;
36+
37+
@Autowired
38+
@Qualifier("pomegranateWorkflowServiceStubs")
39+
WorkflowServiceStubs pomegranateWorkflowServiceStubs;
40+
41+
@BeforeEach
42+
void setUp() {
43+
applicationContext.start();
44+
}
45+
46+
@Test
47+
@Timeout(10)
48+
public void nonRootNamespaceUsesInMemoryTestServer() {
49+
HealthCheckResponse envHealth =
50+
testWorkflowEnvironment.getWorkflowClient().getWorkflowServiceStubs().healthCheck();
51+
HealthCheckResponse pomegranateHealth = pomegranateWorkflowServiceStubs.healthCheck();
52+
assertEquals(HealthCheckResponse.ServingStatus.SERVING, envHealth.getStatus());
53+
assertEquals(HealthCheckResponse.ServingStatus.SERVING, pomegranateHealth.getStatus());
54+
}
55+
56+
@ComponentScan(
57+
excludeFilters =
58+
@ComponentScan.Filter(
59+
pattern =
60+
"io\\.temporal\\.spring\\.boot\\.autoconfigure\\.(byworkername|bytaskqueue)\\..*",
61+
type = FilterType.REGEX))
62+
public static class Configuration {}
63+
}

0 commit comments

Comments
 (0)