44package oracle .kubernetes .operator ;
55
66import java .math .BigInteger ;
7+ import java .util .ArrayList ;
8+ import java .util .Arrays ;
79import java .util .Collections ;
810import java .util .concurrent .atomic .AtomicBoolean ;
911import java .util .function .Function ;
@@ -128,6 +130,28 @@ public void whenJobConditionStatusFalse_reportNotComplete() {
128130 assertThat (JobWatcher .isComplete (cachedJob ), is (false ));
129131 }
130132
133+ @ Test
134+ public void whenJobConditionTypeFailedWithTrueStatus_reportFailed () {
135+ cachedJob .status (new V1JobStatus ().addConditionsItem (new V1JobCondition ().type ("Failed" ).status ("True" )));
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+
131155 @ Test
132156 public void whenJobRunningAndReadyConditionIsTrue_reportComplete () {
133157 markJobCompleted (cachedJob );
@@ -151,6 +175,10 @@ private V1Job markJobFailed(V1Job job) {
151175 return setFailedWithReason (job , null );
152176 }
153177
178+ private V1Job markJobConditionFailed (V1Job job ) {
179+ return setFailedConditionWithReason (job , null );
180+ }
181+
154182 private V1Job markJobTimedOut (V1Job job ) {
155183 return markJobTimedOut (job , "DeadlineExceeded" );
156184 }
@@ -163,11 +191,22 @@ private V1Job setFailedWithReason(V1Job job, String reason) {
163191 return job .status (new V1JobStatus ().failed (1 ).addConditionsItem (createCondition ("Failed" ).reason (reason )));
164192 }
165193
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+
166199 @ Test
167200 public void whenJobHasNoStatus_reportNotFailed () {
168201 assertThat (JobWatcher .isFailed (cachedJob ), is (false ));
169202 }
170203
204+ @ Test
205+ public void whenJobHasNoStatusAndFailedCondition_reportFailed () {
206+ markJobFailed (cachedJob );
207+ assertThat (JobWatcher .isFailed (cachedJob ), is (true ));
208+ }
209+
171210 @ Test
172211 public void whenJobHasFailedCount_reportFailed () {
173212 cachedJob .status (new V1JobStatus ().failed (1 ));
@@ -248,6 +287,13 @@ public void whenWaitForReadyAppliedToFailedJob_performNextStep() {
248287 assertThat (terminalStep .wasRun (), is (true ));
249288 }
250289
290+ @ Test
291+ public void whenWaitForReadyAppliedToJobWithFailedCondition_performNextStep () {
292+ startWaitForReady (this ::markJobConditionFailed );
293+
294+ assertThat (terminalStep .wasRun (), is (true ));
295+ }
296+
251297 // Starts the waitForReady step with job modified as needed
252298 private void startWaitForReady (Function <V1Job ,V1Job > jobFunction ) {
253299 AtomicBoolean stopping = new AtomicBoolean (false );
0 commit comments