Skip to content

Commit 69769cb

Browse files
authored
Fix empty-string fields on CaN not working (#2120)
1 parent ddda99b commit 69769cb

File tree

3 files changed

+126
-2
lines changed

3 files changed

+126
-2
lines changed

temporal-test-server/src/main/java/io/temporal/internal/testservice/StateMachines.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,12 @@ private static void continueAsNewWorkflow(
936936
} else {
937937
a.setWorkflowRunTimeout(sr.getWorkflowRunTimeout());
938938
}
939-
if (d.hasTaskQueue()) {
939+
if (d.hasTaskQueue() && !d.getTaskQueue().getName().isEmpty()) {
940940
a.setTaskQueue(d.getTaskQueue());
941941
} else {
942942
a.setTaskQueue(sr.getTaskQueue());
943943
}
944-
if (d.hasWorkflowType()) {
944+
if (d.hasWorkflowType() && !d.getWorkflowType().getName().isEmpty()) {
945945
a.setWorkflowType(d.getWorkflowType());
946946
} else {
947947
a.setWorkflowType(sr.getWorkflowType());
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this material except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package io.temporal.testserver.functional;
22+
23+
import io.temporal.api.common.v1.WorkflowExecution;
24+
import io.temporal.client.WorkflowOptions;
25+
import io.temporal.client.WorkflowStub;
26+
import io.temporal.common.WorkflowExecutionHistory;
27+
import io.temporal.common.interceptors.*;
28+
import io.temporal.testing.internal.SDKTestWorkflowRule;
29+
import io.temporal.testserver.functional.common.TestWorkflows;
30+
import io.temporal.worker.WorkerFactoryOptions;
31+
import io.temporal.workflow.ContinueAsNewOptions;
32+
import io.temporal.workflow.Workflow;
33+
import java.time.Duration;
34+
import org.junit.Assert;
35+
import org.junit.Rule;
36+
import org.junit.Test;
37+
38+
public class ContinueAsNewTest {
39+
40+
@Rule
41+
public SDKTestWorkflowRule testWorkflowRule =
42+
SDKTestWorkflowRule.newBuilder()
43+
.setWorkerFactoryOptions(
44+
WorkerFactoryOptions.newBuilder()
45+
.setWorkerInterceptors(new StripsTqFromCanInterceptor())
46+
.build())
47+
.setWorkflowTypes(TestWorkflow.class)
48+
.build();
49+
50+
@Test
51+
public void repeatedFailure() {
52+
WorkflowOptions options =
53+
WorkflowOptions.newBuilder()
54+
.setWorkflowTaskTimeout(Duration.ofSeconds(1))
55+
.setTaskQueue(testWorkflowRule.getTaskQueue())
56+
.build();
57+
58+
TestWorkflows.WorkflowTakesBool workflowStub =
59+
testWorkflowRule
60+
.getWorkflowClient()
61+
.newWorkflowStub(TestWorkflows.WorkflowTakesBool.class, options);
62+
workflowStub.execute(true);
63+
64+
WorkflowExecution execution = WorkflowStub.fromTyped(workflowStub).getExecution();
65+
// Verify the latest history is from being CaN'd
66+
WorkflowExecutionHistory lastHist =
67+
testWorkflowRule.getExecutionHistory(execution.getWorkflowId());
68+
Assert.assertFalse(
69+
lastHist
70+
.getEvents()
71+
.get(0)
72+
.getWorkflowExecutionStartedEventAttributes()
73+
.getFirstExecutionRunId()
74+
.isEmpty());
75+
}
76+
77+
public static class TestWorkflow implements TestWorkflows.WorkflowTakesBool {
78+
@Override
79+
public void execute(boolean doContinue) {
80+
if (doContinue) {
81+
Workflow.continueAsNew(false);
82+
}
83+
}
84+
}
85+
86+
// Verify that we can strip the TQ name and test server continues onto same TQ
87+
private static class StripsTqFromCanInterceptor extends WorkerInterceptorBase {
88+
@Override
89+
public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {
90+
return new WorkflowInboundCallsInterceptorBase(next) {
91+
@Override
92+
public void init(WorkflowOutboundCallsInterceptor outboundCalls) {
93+
next.init(new StripsTqFromCanCmd(outboundCalls));
94+
}
95+
};
96+
}
97+
}
98+
99+
private static class StripsTqFromCanCmd extends WorkflowOutboundCallsInterceptorBase {
100+
101+
private final WorkflowOutboundCallsInterceptor next;
102+
103+
public StripsTqFromCanCmd(WorkflowOutboundCallsInterceptor next) {
104+
super(next);
105+
this.next = next;
106+
}
107+
108+
@Override
109+
public void continueAsNew(ContinueAsNewInput input) {
110+
next.continueAsNew(
111+
new ContinueAsNewInput(
112+
input.getWorkflowType(),
113+
ContinueAsNewOptions.newBuilder(input.getOptions()).setTaskQueue("").build(),
114+
input.getArgs(),
115+
input.getHeader()));
116+
}
117+
}
118+
}

temporal-test-server/src/test/java/io/temporal/testserver/functional/common/TestWorkflows.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public interface PrimitiveWorkflow {
3030
void execute();
3131
}
3232

33+
@WorkflowInterface
34+
public interface WorkflowTakesBool {
35+
@WorkflowMethod
36+
void execute(boolean arg);
37+
}
38+
3339
@WorkflowInterface
3440
public interface WorkflowReturnsString {
3541
@WorkflowMethod

0 commit comments

Comments
 (0)