Skip to content

Commit 540b676

Browse files
vathsalaRdplyukhin
authored andcommitted
Test for setPriority
1 parent ad27a01 commit 540b676

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

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
}

0 commit comments

Comments
 (0)