Skip to content

Ensure namespace exists on worker startup #2609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4

- name: Run unit tests
env:
USER: unittest
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4

- name: Run cloud test
# Only supported in non-fork runs, since secrets are not available in forks. We intentionally
# are only doing this check on the step instead of the job so we require job passing in CI
Expand Down Expand Up @@ -191,10 +191,10 @@ jobs:

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4

- name: Run copyright and code format checks
run: ./gradlew --no-daemon spotlessCheck

build_native_images:
name: Build native test server
uses: ./.github/workflows/build-native-image.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.uber.m3.tally.Scope;
import io.temporal.api.workflowservice.v1.DescribeNamespaceRequest;
import io.temporal.api.workflowservice.v1.DescribeNamespaceResponse;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.common.converter.DataConverter;
Expand Down Expand Up @@ -196,9 +198,14 @@ public synchronized void start() {

// Workers check and require that Temporal Server is available during start to fail-fast in case
// of configuration issues.
// TODO(https://github.com/temporalio/sdk-java/issues/2060) consider using describeNamespace as
// a connection check.
workflowClient.getWorkflowServiceStubs().getServerCapabilities();
DescribeNamespaceResponse response =
workflowClient
.getWorkflowServiceStubs()
.blockingStub()
.describeNamespace(
DescribeNamespaceRequest.newBuilder()
.setNamespace(workflowClient.getOptions().getNamespace())
.build());

for (Worker worker : workers.values()) {
worker.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package io.temporal.workerFactory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import io.temporal.worker.WorkerFactory;
Expand Down Expand Up @@ -128,4 +133,24 @@ public void factoryCanBeShutdownMoreThanOnce() {
factory.shutdown();
factory.awaitTermination(1, TimeUnit.MILLISECONDS);
}

@Test
public void startFailsOnNonexistentNamespace() {
WorkflowServiceStubs serviceLocal =
WorkflowServiceStubs.newServiceStubs(
WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
WorkflowClient clientLocal =
WorkflowClient.newInstance(
serviceLocal, WorkflowClientOptions.newBuilder().setNamespace("i_dont_exist").build());
WorkerFactory factoryLocal = WorkerFactory.newInstance(clientLocal);
factoryLocal.newWorker("task-queue");

StatusRuntimeException ex = assertThrows(StatusRuntimeException.class, factoryLocal::start);
assertEquals(Status.Code.NOT_FOUND, ex.getStatus().getCode());

factoryLocal.shutdownNow();
factoryLocal.awaitTermination(5, TimeUnit.SECONDS);
serviceLocal.shutdownNow();
serviceLocal.awaitTermination(5, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.temporal.common.WorkflowExecutionHistory;
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow;
import io.temporal.spring.boot.autoconfigure.workerversioning.TestWorkflow2;
import io.temporal.worker.WorkerFactory;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -20,7 +21,7 @@
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest(classes = WorkerVersioningTest.Configuration.class)
@ActiveProfiles(profiles = "worker-versioning")
@ActiveProfiles(profiles = {"worker-versioning", "disable-start-workers"})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class WorkerVersioningTest {
@Autowired ConfigurableApplicationContext applicationContext;
Expand All @@ -43,6 +44,12 @@ void setUp() {
@Test
@Timeout(value = 10)
public void testAutoDiscovery() {
// Manually start the worker because we disable automatic worker start, due to
// automatic worker start running prior to the docker check, which causes namespace
// errors when running in-mem unit tests
WorkerFactory workerFactory = applicationContext.getBean(WorkerFactory.class);
workerFactory.start();

workflowClient
.getWorkflowServiceStubs()
.blockingStub()
Expand Down
Loading