@@ -33,10 +33,15 @@ public void testPriority() {
3333 TestWorkflow1 .class ,
3434 WorkflowOptions .newBuilder ()
3535 .setTaskQueue (testWorkflowRule .getTaskQueue ())
36- .setPriority (Priority .newBuilder ().setPriorityKey (5 ).build ())
36+ .setPriority (
37+ Priority .newBuilder ()
38+ .setPriorityKey (5 )
39+ .setFairnessKey ("tenant-123" )
40+ .setFairnessWeight (2.5f )
41+ .build ())
3742 .build ());
3843 String result = workflowStub .execute (testWorkflowRule .getTaskQueue ());
39- assertEquals ("5" , result );
44+ assertEquals ("5:tenant-123:2.5 " , result );
4045 }
4146
4247 @ ActivityInterface
@@ -47,15 +52,18 @@ public interface PriorityActivities {
4752 public static class PriorityActivitiesImpl implements PriorityActivities {
4853 @ Override
4954 public String activity1 (String a1 ) {
50- return String .valueOf (
51- Activity .getExecutionContext ().getInfo ().getPriority ().getPriorityKey ());
55+ Priority priority = Activity .getExecutionContext ().getInfo ().getPriority ();
56+ String key = priority .getFairnessKey () != null ? priority .getFairnessKey () : "null" ;
57+ return priority .getPriorityKey () + ":" + key + ":" + priority .getFairnessWeight ();
5258 }
5359 }
5460
5561 public static class TestPriorityChildWorkflow implements TestWorkflows .TestWorkflowReturnString {
5662 @ Override
5763 public String execute () {
58- return String .valueOf (Workflow .getInfo ().getPriority ().getPriorityKey ());
64+ Priority priority = Workflow .getInfo ().getPriority ();
65+ String key = priority .getFairnessKey () != null ? priority .getFairnessKey () : "null" ;
66+ return priority .getPriorityKey () + ":" + key + ":" + priority .getFairnessWeight ();
5967 }
6068 }
6169
@@ -70,12 +78,17 @@ public String execute(String taskQueue) {
7078 ActivityOptions .newBuilder ()
7179 .setTaskQueue (taskQueue )
7280 .setStartToCloseTimeout (Duration .ofSeconds (10 ))
73- .setPriority (Priority .newBuilder ().setPriorityKey (3 ).build ())
81+ .setPriority (
82+ Priority .newBuilder ()
83+ .setPriorityKey (3 )
84+ .setFairnessKey ("override" )
85+ .setFairnessWeight (1.5f )
86+ .build ())
7487 .setDisableEagerExecution (true )
7588 .build ())
7689 .activity1 ("1" );
77- Assert .assertEquals ("3" , priority );
78- // Test that of if no priority is set the workflows priority is used
90+ Assert .assertEquals ("3:override:1.5 " , priority );
91+ // Test that if no priority is set the workflow's priority is used
7992 priority =
8093 Workflow .newActivityStub (
8194 PriorityActivities .class ,
@@ -85,46 +98,37 @@ public String execute(String taskQueue) {
8598 .setDisableEagerExecution (true )
8699 .build ())
87100 .activity1 ("2" );
88- Assert .assertEquals ("5" , priority );
89- // Test that of if a default priority is set the workflows priority is used
90- priority =
91- Workflow .newActivityStub (
92- PriorityActivities .class ,
93- ActivityOptions .newBuilder ()
94- .setTaskQueue (taskQueue )
95- .setStartToCloseTimeout (Duration .ofSeconds (10 ))
96- .setPriority (Priority .newBuilder ().build ())
97- .setDisableEagerExecution (true )
98- .build ())
99- .activity1 ("2" );
100- Assert .assertEquals ("5" , priority );
101+ Assert .assertEquals ("5:tenant-123:2.5" , priority );
101102 // Test that the priority is passed to child workflows
102103 priority =
103104 Workflow .newChildWorkflowStub (
104105 TestWorkflows .TestWorkflowReturnString .class ,
105106 ChildWorkflowOptions .newBuilder ()
106- .setPriority (Priority .newBuilder ().setPriorityKey (1 ).build ())
107+ .setPriority (
108+ Priority .newBuilder ()
109+ .setPriorityKey (1 )
110+ .setFairnessKey ("child" )
111+ .setFairnessWeight (0.5f )
112+ .build ())
107113 .build ())
108114 .execute ();
109- Assert .assertEquals ("1" , priority );
110- // Test that of no priority is set the workflows priority is used
115+ Assert .assertEquals ("1:child:0.5 " , priority );
116+ // Test that if no priority is set the workflow's priority is used
111117 priority =
112118 Workflow .newChildWorkflowStub (
113119 TestWorkflows .TestWorkflowReturnString .class ,
114120 ChildWorkflowOptions .newBuilder ().build ())
115121 .execute ();
116- Assert .assertEquals ("5" , priority );
117- // Test that if a default priority is set the workflows priority is used
118- priority =
119- Workflow .newChildWorkflowStub (
120- TestWorkflows .TestWorkflowReturnString .class ,
121- ChildWorkflowOptions .newBuilder ()
122- .setPriority (Priority .newBuilder ().build ())
123- .build ())
124- .execute ();
125- Assert .assertEquals ("5" , priority );
126- // Return the workflows priority
127- return String .valueOf (Workflow .getInfo ().getPriority ().getPriorityKey ());
122+ Assert .assertEquals ("5:tenant-123:2.5" , priority );
123+ // Return the workflow's priority
124+ Priority workflowPriority = Workflow .getInfo ().getPriority ();
125+ String key =
126+ workflowPriority .getFairnessKey () != null ? workflowPriority .getFairnessKey () : "null" ;
127+ return workflowPriority .getPriorityKey ()
128+ + ":"
129+ + key
130+ + ":"
131+ + workflowPriority .getFairnessWeight ();
128132 }
129133 }
130134}
0 commit comments