Skip to content

Commit 5d6feeb

Browse files
authored
Fix: Propagate WorkflowOptions.priority through signalWithStart (#2966)
1 parent d664c37 commit 5d6feeb

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

temporal-sdk/src/main/java/io/temporal/internal/client/WorkflowClientRequestFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ SignalWithStartWorkflowExecutionRequest.Builder newSignalWithStartWorkflowExecut
210210
request.setVersioningOverride(startParameters.getVersioningOverride());
211211
}
212212

213+
if (startParameters.hasPriority()) {
214+
request.setPriority(startParameters.getPriority());
215+
}
213216
return request;
214217
}
215218

temporal-sdk/src/test/java/io/temporal/workflow/PriorityInfoTest.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import io.temporal.activity.ActivityInterface;
77
import io.temporal.activity.ActivityOptions;
88
import io.temporal.client.WorkflowOptions;
9+
import io.temporal.client.WorkflowStub;
910
import io.temporal.common.Priority;
1011
import io.temporal.testing.internal.SDKTestWorkflowRule;
1112
import io.temporal.workflow.shared.TestWorkflows;
1213
import io.temporal.workflow.shared.TestWorkflows.TestWorkflow1;
1314
import java.time.Duration;
15+
import java.util.UUID;
1416
import org.junit.Assert;
1517
import org.junit.Rule;
1618
import org.junit.Test;
@@ -20,7 +22,10 @@ public class PriorityInfoTest {
2022
@Rule
2123
public SDKTestWorkflowRule testWorkflowRule =
2224
SDKTestWorkflowRule.newBuilder()
23-
.setWorkflowTypes(TestPriority.class, TestPriorityChildWorkflow.class)
25+
.setWorkflowTypes(
26+
TestPriority.class,
27+
TestPriorityChildWorkflow.class,
28+
TestSignalWithStartPriorityWorkflowImpl.class)
2429
.setActivityImplementations(new PriorityActivitiesImpl())
2530
.build();
2631

@@ -44,6 +49,24 @@ public void testPriority() {
4449
assertEquals("5:tenant-123:2.5", result);
4550
}
4651

52+
@Test
53+
public void testPriorityWithSignalWithStart() {
54+
WorkflowStub stub =
55+
testWorkflowRule
56+
.getWorkflowClient()
57+
.newUntypedWorkflowStub(
58+
"TestSignalWithStartPriorityWorkflow",
59+
WorkflowOptions.newBuilder()
60+
.setWorkflowId("test-signal-with-start-priority-" + UUID.randomUUID())
61+
.setTaskQueue(testWorkflowRule.getTaskQueue())
62+
.setPriority(Priority.newBuilder().setPriorityKey(2).build())
63+
.build());
64+
stub.signalWithStart(
65+
"mySignal", new Object[] {"signalArg"}, new Object[] {testWorkflowRule.getTaskQueue()});
66+
String result = stub.getResult(String.class);
67+
assertEquals("2:null:0.0", result);
68+
}
69+
4770
@ActivityInterface
4871
public interface PriorityActivities {
4972
String activity1(String a1);
@@ -131,4 +154,32 @@ public String execute(String taskQueue) {
131154
+ workflowPriority.getFairnessWeight();
132155
}
133156
}
157+
158+
@WorkflowInterface
159+
public interface TestSignalWithStartPriorityWorkflow {
160+
@WorkflowMethod
161+
String execute(String taskQueue);
162+
163+
@SignalMethod
164+
void mySignal(String arg);
165+
}
166+
167+
public static class TestSignalWithStartPriorityWorkflowImpl
168+
implements TestSignalWithStartPriorityWorkflow {
169+
170+
private boolean received = false;
171+
172+
@Override
173+
public String execute(String taskQueue) {
174+
Workflow.await(() -> received);
175+
Priority priority = Workflow.getInfo().getPriority();
176+
String key = priority.getFairnessKey() != null ? priority.getFairnessKey() : "null";
177+
return priority.getPriorityKey() + ":" + key + ":" + priority.getFairnessWeight();
178+
}
179+
180+
@Override
181+
public void mySignal(String arg) {
182+
received = true;
183+
}
184+
}
134185
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,9 @@ public void signalWithStartWorkflowExecution(
16571657
if (!r.getLinksList().isEmpty()) {
16581658
startRequest.addAllLinks(r.getLinksList());
16591659
}
1660+
if (r.hasPriority()) {
1661+
startRequest.setPriority(r.getPriority());
1662+
}
16601663

16611664
StartWorkflowExecutionResponse startResult =
16621665
startWorkflowExecutionImpl(

0 commit comments

Comments
 (0)