@@ -33,10 +33,15 @@ public void testPriority() {
33
33
TestWorkflow1 .class ,
34
34
WorkflowOptions .newBuilder ()
35
35
.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 ())
37
42
.build ());
38
43
String result = workflowStub .execute (testWorkflowRule .getTaskQueue ());
39
- assertEquals ("5" , result );
44
+ assertEquals ("5:tenant-123:2.5 " , result );
40
45
}
41
46
42
47
@ ActivityInterface
@@ -47,15 +52,18 @@ public interface PriorityActivities {
47
52
public static class PriorityActivitiesImpl implements PriorityActivities {
48
53
@ Override
49
54
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 ();
52
58
}
53
59
}
54
60
55
61
public static class TestPriorityChildWorkflow implements TestWorkflows .TestWorkflowReturnString {
56
62
@ Override
57
63
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 ();
59
67
}
60
68
}
61
69
@@ -70,12 +78,17 @@ public String execute(String taskQueue) {
70
78
ActivityOptions .newBuilder ()
71
79
.setTaskQueue (taskQueue )
72
80
.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 ())
74
87
.setDisableEagerExecution (true )
75
88
.build ())
76
89
.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
79
92
priority =
80
93
Workflow .newActivityStub (
81
94
PriorityActivities .class ,
@@ -85,46 +98,37 @@ public String execute(String taskQueue) {
85
98
.setDisableEagerExecution (true )
86
99
.build ())
87
100
.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 );
101
102
// Test that the priority is passed to child workflows
102
103
priority =
103
104
Workflow .newChildWorkflowStub (
104
105
TestWorkflows .TestWorkflowReturnString .class ,
105
106
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 ())
107
113
.build ())
108
114
.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
111
117
priority =
112
118
Workflow .newChildWorkflowStub (
113
119
TestWorkflows .TestWorkflowReturnString .class ,
114
120
ChildWorkflowOptions .newBuilder ().build ())
115
121
.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 ();
128
132
}
129
133
}
130
134
}
0 commit comments