final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, testHost());
awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
undeployJob(jobId, testHost());
awaitTaskGone(client, testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
final TaskStatusEvents events = Polling.await(
WAIT_TIMEOUT_SECONDS, SECONDS, new Callable<TaskStatusEvents>() {
@Override
public TaskStatusEvents call() throws Exception {
final TaskStatusEvents events = client.jobHistory(jobId).get();
final int size = events.getEvents().size();
if (size == 0) {
return null;
}
// We sometimes get more than one PULLING_IMAGE in the history if a pull tempfails.
int requiredEventCount = -1;
for (int i = 0; i < size; i++) {
if (events.getEvents().get(i).getStatus().getState() != State.PULLING_IMAGE) {
requiredEventCount = i + 4;
break;
}
}
if (requiredEventCount == -1) {
return null;
}
if (size < requiredEventCount) {
return null;
}
return events;
}
});
final List<TaskStatusEvent> eventsList = events.getEvents();
int n = 0;
while (true) {
final TaskStatusEvent event = eventsList.get(n);
if (event.getStatus().getState() != State.PULLING_IMAGE) {