19
19
import org .junit .Test ;
20
20
21
21
import com .netflix .conductor .common .metadata .workflow .WorkflowTask ;
22
+ import com .netflix .conductor .core .config .ConductorProperties ;
22
23
import com .netflix .conductor .core .execution .WorkflowExecutor ;
23
24
import com .netflix .conductor .model .TaskModel ;
24
25
import com .netflix .conductor .model .WorkflowModel ;
27
28
import static org .mockito .Mockito .mock ;
28
29
29
30
public class TestJoin {
31
+
32
+ private final ConductorProperties properties = new ConductorProperties ();
33
+
30
34
private final WorkflowExecutor executor = mock (WorkflowExecutor .class );
31
35
32
36
private TaskModel createTask (
@@ -65,7 +69,7 @@ public void testShouldNotMarkJoinAsCompletedWithErrorsWhenNotDone() {
65
69
// task2 is not scheduled yet, so the join is not completed
66
70
var wfJoinPair = createJoinWorkflow (List .of (task1 ), "task2" );
67
71
68
- var join = new Join ();
72
+ var join = new Join (properties );
69
73
var result = join .execute (wfJoinPair .getLeft (), wfJoinPair .getRight (), executor );
70
74
assertFalse (result );
71
75
}
@@ -77,7 +81,7 @@ public void testJoinCompletesSuccessfullyWhenAllTasksSucceed() {
77
81
78
82
var wfJoinPair = createJoinWorkflow (List .of (task1 , task2 ));
79
83
80
- var join = new Join ();
84
+ var join = new Join (properties );
81
85
var result = join .execute (wfJoinPair .getLeft (), wfJoinPair .getRight (), executor );
82
86
assertTrue ("Join task should execute successfully when all tasks succeed" , result );
83
87
assertEquals (
@@ -93,7 +97,7 @@ public void testJoinWaitsWhenAnyTaskIsNotTerminal() {
93
97
94
98
var wfJoinPair = createJoinWorkflow (List .of (task1 , task2 ));
95
99
96
- var join = new Join ();
100
+ var join = new Join (properties );
97
101
var result = join .execute (wfJoinPair .getLeft (), wfJoinPair .getRight (), executor );
98
102
assertFalse ("Join task should wait when any task is not in terminal state" , result );
99
103
}
@@ -107,7 +111,7 @@ public void testJoinFailsWhenMandatoryTaskFails() {
107
111
108
112
var wfJoinPair = createJoinWorkflow (List .of (task1 , task2 ));
109
113
110
- var join = new Join ();
114
+ var join = new Join (properties );
111
115
var result = join .execute (wfJoinPair .getLeft (), wfJoinPair .getRight (), executor );
112
116
assertTrue ("Join task should be executed when a mandatory task fails" , result );
113
117
assertEquals (
@@ -125,7 +129,7 @@ public void testJoinCompletesWithErrorsWhenOnlyOptionalTasksFail() {
125
129
126
130
var wfJoinPair = createJoinWorkflow (List .of (task1 , task2 ));
127
131
128
- var join = new Join ();
132
+ var join = new Join (properties );
129
133
var result = join .execute (wfJoinPair .getLeft (), wfJoinPair .getRight (), executor );
130
134
assertTrue ("Join task should be executed when only optional tasks fail" , result );
131
135
assertEquals (
@@ -143,7 +147,7 @@ public void testJoinAggregatesFailureReasonsCorrectly() {
143
147
144
148
var wfJoinPair = createJoinWorkflow (List .of (task1 , task2 ));
145
149
146
- var join = new Join ();
150
+ var join = new Join (properties );
147
151
var result = join .execute (wfJoinPair .getLeft (), wfJoinPair .getRight (), executor );
148
152
assertTrue ("Join task should be executed when tasks fail" , result );
149
153
assertEquals (
@@ -174,7 +178,7 @@ public void testJoinWaitsForAllTasksBeforeFailingDueToPermissiveTaskFailure() {
174
178
var wfJoinPair = createJoinWorkflow (List .of (task1 , task2 ));
175
179
176
180
// First execution: Task 2 is not yet terminal.
177
- var join = new Join ();
181
+ var join = new Join (properties );
178
182
boolean result = join .execute (wfJoinPair .getLeft (), wfJoinPair .getRight (), executor );
179
183
assertFalse ("Join task should wait as not all tasks are terminal" , result );
180
184
@@ -189,4 +193,33 @@ public void testJoinWaitsForAllTasksBeforeFailingDueToPermissiveTaskFailure() {
189
193
TaskModel .Status .FAILED ,
190
194
wfJoinPair .getRight ().getStatus ());
191
195
}
196
+
197
+ @ Test
198
+ public void testEvaluationOffsetWhenPollCountIsBelowThreshold () {
199
+ var join = new Join (properties );
200
+ var taskModel = createTask ("join1" , TaskModel .Status .COMPLETED , false , false );
201
+ taskModel .setPollCount (properties .getSystemTaskPostponeThreshold () - 1 );
202
+ var opt = join .getEvaluationOffset (taskModel , 30L );
203
+ assertEquals (0L , (long ) opt .orElseThrow ());
204
+ }
205
+
206
+ @ Test
207
+ public void testEvaluationOffsetWhenPollCountIsAboveThreshold () {
208
+ final var maxOffset = 30L ;
209
+ var join = new Join (properties );
210
+ var taskModel = createTask ("join1" , TaskModel .Status .COMPLETED , false , false );
211
+
212
+ taskModel .setPollCount (properties .getSystemTaskPostponeThreshold () + 1 );
213
+ var opt = join .getEvaluationOffset (taskModel , maxOffset );
214
+ assertEquals (1L , (long ) opt .orElseThrow ());
215
+
216
+ taskModel .setPollCount (properties .getSystemTaskPostponeThreshold () + 10 );
217
+ opt = join .getEvaluationOffset (taskModel , maxOffset );
218
+ long expected = (long ) Math .pow (Join .EVALUATION_OFFSET_BASE , 10 );
219
+ assertEquals (expected , (long ) opt .orElseThrow ());
220
+
221
+ taskModel .setPollCount (properties .getSystemTaskPostponeThreshold () + 40 );
222
+ opt = join .getEvaluationOffset (taskModel , maxOffset );
223
+ assertEquals (maxOffset , (long ) opt .orElseThrow ());
224
+ }
192
225
}
0 commit comments