Skip to content

Commit 0e1a7a2

Browse files
authored
Validate deployment options and test worker with versioning off and custom build ID (#2807)
1 parent c195cd1 commit 0e1a7a2

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public WorkerDeploymentOptions build() {
6161
Preconditions.checkState(
6262
!(useVersioning && version == null),
6363
"If useVersioning is set, setVersion must be called");
64+
Preconditions.checkState(
65+
useVersioning || defaultVersioningBehavior == VersioningBehavior.UNSPECIFIED,
66+
"defaultVersioningBehavior must be UNSPECIFIED when useVersioning is false");
6467
return new WorkerDeploymentOptions(useVersioning, version, defaultVersioningBehavior);
6568
}
6669
}

temporal-sdk/src/test/java/io/temporal/worker/WorkerVersioningTest.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,64 @@ public void testAnnotationNotAllowedOnInterface() {
387387
e.getMessage());
388388
}
389389

390+
@Test
391+
public void testWorkerWithDeploymentOptionsVersioningOffCanRunWorkflows() {
392+
assumeTrue("Test Server doesn't support versioning", SDKTestWorkflowRule.useExternalService);
393+
394+
Worker w1 =
395+
testWorkflowRule.newWorker(
396+
(opts) ->
397+
opts.setDeploymentOptions(
398+
WorkerDeploymentOptions.newBuilder()
399+
.setVersion(
400+
new WorkerDeploymentVersion(
401+
testWorkflowRule.getDeploymentName(), "my-custom-build-id-1.0"))
402+
.setUseVersioning(false)
403+
.build()));
404+
w1.registerWorkflowImplementationTypes(TestWorkerVersioningMissingAnnotation.class);
405+
w1.start();
406+
407+
TestWorkflows.QueryableWorkflow wf =
408+
testWorkflowRule.newWorkflowStubTimeoutOptions(
409+
TestWorkflows.QueryableWorkflow.class, "versioning-off-build-id");
410+
WorkflowExecution we = WorkflowClient.start(wf::execute);
411+
wf.mySignal("done");
412+
String result =
413+
testWorkflowRule
414+
.getWorkflowClient()
415+
.newUntypedWorkflowStub(we.getWorkflowId())
416+
.getResult(String.class);
417+
Assert.assertEquals("no-annotation", result);
418+
419+
WorkflowExecutionHistory hist = testWorkflowRule.getExecutionHistory(we.getWorkflowId());
420+
// The Java SDK sends deployment_options on WFT completion, and the server records the
421+
// deployment name in the worker_deployment_name field of the history event.
422+
Assert.assertTrue(
423+
"Expected deployment name to appear in workflow history",
424+
hist.getHistory().getEventsList().stream()
425+
.anyMatch(
426+
e ->
427+
e.getEventType() == EventType.EVENT_TYPE_WORKFLOW_TASK_COMPLETED
428+
&& !e.getWorkflowTaskCompletedEventAttributes()
429+
.getWorkerDeploymentName()
430+
.isEmpty()));
431+
}
432+
433+
@Test
434+
public void testRejectsVersioningBehaviorWhenVersioningOff() {
435+
IllegalStateException e =
436+
Assert.assertThrows(
437+
IllegalStateException.class,
438+
() ->
439+
WorkerDeploymentOptions.newBuilder()
440+
.setVersion(
441+
new WorkerDeploymentVersion(testWorkflowRule.getDeploymentName(), "1.0"))
442+
.setUseVersioning(false)
443+
.setDefaultVersioningBehavior(VersioningBehavior.AUTO_UPGRADE)
444+
.build());
445+
Assert.assertTrue(e.getMessage().contains("defaultVersioningBehavior must be UNSPECIFIED"));
446+
}
447+
390448
@SuppressWarnings("deprecation")
391449
@Test
392450
public void testWorkflowsCanUseVersioningOverride() {

0 commit comments

Comments
 (0)