4
4
package oracle .kubernetes .operator ;
5
5
6
6
import java .math .BigInteger ;
7
+ import java .util .ArrayList ;
8
+ import java .util .Arrays ;
7
9
import java .util .Collections ;
8
10
import java .util .concurrent .atomic .AtomicBoolean ;
9
11
import java .util .function .Function ;
@@ -128,6 +130,28 @@ public void whenJobConditionStatusFalse_reportNotComplete() {
128
130
assertThat (JobWatcher .isComplete (cachedJob ), is (false ));
129
131
}
130
132
133
+ @ Test
134
+ public void whenJobConditionTypeFailedWithTrueStatus_reportFailed () {
135
+ markJobConditionFailed (cachedJob );
136
+
137
+ assertThat (JobWatcher .isFailed (cachedJob ), is (true ));
138
+ }
139
+
140
+ @ Test
141
+ public void whenJobConditionTypeFailedWithNoStatus_reportNotFailed () {
142
+ cachedJob .status (new V1JobStatus ().addConditionsItem (new V1JobCondition ().type ("Failed" ).status ("" )));
143
+
144
+ assertThat (JobWatcher .isFailed (cachedJob ), is (false ));
145
+ }
146
+
147
+ @ Test
148
+ public void whenJobHasStatusWithNoConditionsAndNotFailed_reportNotFailed () {
149
+ cachedJob .status (new V1JobStatus ().conditions (Collections .emptyList ()));
150
+
151
+ assertThat (JobWatcher .isFailed (cachedJob ), is (false ));
152
+ }
153
+
154
+
131
155
@ Test
132
156
public void whenJobRunningAndReadyConditionIsTrue_reportComplete () {
133
157
markJobCompleted (cachedJob );
@@ -151,6 +175,10 @@ private V1Job markJobFailed(V1Job job) {
151
175
return setFailedWithReason (job , null );
152
176
}
153
177
178
+ private V1Job markJobConditionFailed (V1Job job ) {
179
+ return setFailedConditionWithReason (job , null );
180
+ }
181
+
154
182
private V1Job markJobTimedOut (V1Job job ) {
155
183
return markJobTimedOut (job , "DeadlineExceeded" );
156
184
}
@@ -163,6 +191,11 @@ private V1Job setFailedWithReason(V1Job job, String reason) {
163
191
return job .status (new V1JobStatus ().failed (1 ).addConditionsItem (createCondition ("Failed" ).reason (reason )));
164
192
}
165
193
194
+ private V1Job setFailedConditionWithReason (V1Job job , String reason ) {
195
+ return job .status (new V1JobStatus ().conditions (
196
+ new ArrayList <>(Arrays .asList (new V1JobCondition ().type ("Failed" ).status ("True" ).reason (reason )))));
197
+ }
198
+
166
199
@ Test
167
200
public void whenJobHasNoStatus_reportNotFailed () {
168
201
assertThat (JobWatcher .isFailed (cachedJob ), is (false ));
@@ -248,6 +281,13 @@ public void whenWaitForReadyAppliedToFailedJob_performNextStep() {
248
281
assertThat (terminalStep .wasRun (), is (true ));
249
282
}
250
283
284
+ @ Test
285
+ public void whenWaitForReadyAppliedToJobWithFailedCondition_performNextStep () {
286
+ startWaitForReady (this ::markJobConditionFailed );
287
+
288
+ assertThat (terminalStep .wasRun (), is (true ));
289
+ }
290
+
251
291
// Starts the waitForReady step with job modified as needed
252
292
private void startWaitForReady (Function <V1Job ,V1Job > jobFunction ) {
253
293
AtomicBoolean stopping = new AtomicBoolean (false );
0 commit comments