final JobGraph jobGraph = new JobGraph("Test Job", vertex);
final JobManager jm = startJobManager(NUM_TASKS);
final GlobalBufferPool bp = ((LocalInstanceManager) jm.getInstanceManager())
.getTaskManagers()[0].getChannelManager().getGlobalBufferPool();
try {
assertEquals(NUM_TASKS, jm.getTotalNumberOfRegisteredSlots());
JobSubmissionResult result = jm.submitJob(jobGraph);
if (result.getReturnCode() != AbstractJobResult.ReturnCode.SUCCESS) {
System.out.println(result.getDescription());
}
assertEquals(AbstractJobResult.ReturnCode.SUCCESS, result.getReturnCode());
// monitor the execution
ExecutionGraph eg = jm.getCurrentJobs().get(jobGraph.getJobID());
if (eg != null) {
long deadline = System.currentTimeMillis() + 60*1000;
boolean success = false;
while (System.currentTimeMillis() < deadline) {
JobStatus state = eg.getState();
if (state == JobStatus.FINISHED) {
success = true;
break;
}
else if (state == JobStatus.FAILED || state == JobStatus.CANCELED) {
break;
}
else {
Thread.sleep(200);
}
}
assertTrue("The job did not finish successfully.", success);
// assertEquals(0, eg.getRegisteredExecutions().size());
}
else {
// already done, that was fast;
}
// make sure that in any case, the network buffers are all returned
waitForTaskThreadsToBeTerminated();
assertEquals(bp.numBuffers(), bp.numAvailableBuffers());
}
finally {
jm.shutdown();
}
}