Skip to content

Commit 6e43e55

Browse files
committed
Merge remote-tracking branch 'origin/namespace_worker_start' into namespace_worker_start
2 parents 94007cc + ed3fa79 commit 6e43e55

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
- name: Set up Gradle
3030
uses: gradle/actions/setup-gradle@v4
31-
31+
3232
- name: Run unit tests
3333
env:
3434
USER: unittest
@@ -152,7 +152,7 @@ jobs:
152152

153153
- name: Set up Gradle
154154
uses: gradle/actions/setup-gradle@v4
155-
155+
156156
- name: Run cloud test
157157
# Only supported in non-fork runs, since secrets are not available in forks. We intentionally
158158
# are only doing this check on the step instead of the job so we require job passing in CI
@@ -191,10 +191,10 @@ jobs:
191191

192192
- name: Set up Gradle
193193
uses: gradle/actions/setup-gradle@v4
194-
194+
195195
- name: Run copyright and code format checks
196196
run: ./gradlew --no-daemon spotlessCheck
197-
197+
198198
build_native_images:
199199
name: Build native test server
200200
uses: ./.github/workflows/build-native-image.yml

temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.google.common.base.Preconditions;
55
import com.google.common.base.Strings;
66
import com.uber.m3.tally.Scope;
7+
import io.temporal.api.workflowservice.v1.DescribeNamespaceRequest;
8+
import io.temporal.api.workflowservice.v1.DescribeNamespaceResponse;
79
import io.temporal.client.WorkflowClient;
810
import io.temporal.client.WorkflowClientOptions;
911
import io.temporal.common.converter.DataConverter;
@@ -196,9 +198,14 @@ public synchronized void start() {
196198

197199
// Workers check and require that Temporal Server is available during start to fail-fast in case
198200
// of configuration issues.
199-
// TODO(https://github.com/temporalio/sdk-java/issues/2060) consider using describeNamespace as
200-
// a connection check.
201-
workflowClient.getWorkflowServiceStubs().getServerCapabilities();
201+
DescribeNamespaceResponse response =
202+
workflowClient
203+
.getWorkflowServiceStubs()
204+
.blockingStub()
205+
.describeNamespace(
206+
DescribeNamespaceRequest.newBuilder()
207+
.setNamespace(workflowClient.getOptions().getNamespace())
208+
.build());
202209

203210
for (Worker worker : workers.values()) {
204211
worker.start();

temporal-sdk/src/test/java/io/temporal/workerFactory/WorkerFactoryTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package io.temporal.workerFactory;
22

3+
import static org.junit.Assert.assertEquals;
34
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertThrows;
46
import static org.junit.Assert.assertTrue;
57

8+
import io.grpc.Status;
9+
import io.grpc.StatusRuntimeException;
610
import io.temporal.client.WorkflowClient;
11+
import io.temporal.client.WorkflowClientOptions;
712
import io.temporal.serviceclient.WorkflowServiceStubs;
813
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
914
import io.temporal.worker.WorkerFactory;
@@ -128,4 +133,24 @@ public void factoryCanBeShutdownMoreThanOnce() {
128133
factory.shutdown();
129134
factory.awaitTermination(1, TimeUnit.MILLISECONDS);
130135
}
136+
137+
@Test
138+
public void startFailsOnNonexistentNamespace() {
139+
WorkflowServiceStubs serviceLocal =
140+
WorkflowServiceStubs.newServiceStubs(
141+
WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
142+
WorkflowClient clientLocal =
143+
WorkflowClient.newInstance(
144+
serviceLocal, WorkflowClientOptions.newBuilder().setNamespace("i_dont_exist").build());
145+
WorkerFactory factoryLocal = WorkerFactory.newInstance(clientLocal);
146+
factoryLocal.newWorker("task-queue");
147+
148+
StatusRuntimeException ex = assertThrows(StatusRuntimeException.class, factoryLocal::start);
149+
assertEquals(Status.Code.NOT_FOUND, ex.getStatus().getCode());
150+
151+
factoryLocal.shutdownNow();
152+
factoryLocal.awaitTermination(5, TimeUnit.SECONDS);
153+
serviceLocal.shutdownNow();
154+
serviceLocal.awaitTermination(5, TimeUnit.SECONDS);
155+
}
131156
}

temporal-spring-boot-autoconfigure/src/test/java/io/temporal/spring/boot/autoconfigure/WorkerVersioningTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.temporal.common.WorkflowExecutionHistory;
1212
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow;
1313
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow2;
14+
import io.temporal.worker.WorkerFactory;
1415
import org.junit.jupiter.api.*;
1516
import org.springframework.beans.factory.annotation.Autowired;
1617
import org.springframework.boot.test.context.SpringBootTest;
@@ -20,7 +21,7 @@
2021
import org.springframework.test.context.ActiveProfiles;
2122

2223
@SpringBootTest(classes = WorkerVersioningTest.Configuration.class)
23-
@ActiveProfiles(profiles = "worker-versioning")
24+
@ActiveProfiles(profiles = {"worker-versioning", "disable-start-workers"})
2425
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2526
public class WorkerVersioningTest {
2627
@Autowired ConfigurableApplicationContext applicationContext;
@@ -43,6 +44,12 @@ void setUp() {
4344
@Test
4445
@Timeout(value = 10)
4546
public void testAutoDiscovery() {
47+
// Manually start the worker because we disable automatic worker start, due to
48+
// automatic worker start running prior to the docker check, which causes namespace
49+
// errors when running in-mem unit tests
50+
WorkerFactory workerFactory = applicationContext.getBean(WorkerFactory.class);
51+
workerFactory.start();
52+
4653
workflowClient
4754
.getWorkflowServiceStubs()
4855
.blockingStub()

0 commit comments

Comments
 (0)