}
}
@Test
public void testJobSubmissionAndCanceling() {
JobManager jobManager = null;
TaskManager tm = null;
try {
jobManager = getJobManagerMockBase();
tm = createTaskManager(jobManager);
JobID jid1 = new JobID();
JobID jid2 = new JobID();
JobVertexID vid1 = new JobVertexID();
JobVertexID vid2 = new JobVertexID();
ExecutionAttemptID eid1 = new ExecutionAttemptID();
ExecutionAttemptID eid2 = new ExecutionAttemptID();
TaskDeploymentDescriptor tdd1 = new TaskDeploymentDescriptor(jid1, vid1, eid1, "TestTask1", 1, 5,
new Configuration(), new Configuration(), TestInvokableBlockingCancelable.class.getName(),
Collections.<GateDeploymentDescriptor>emptyList(),
Collections.<GateDeploymentDescriptor>emptyList(),
new ArrayList<BlobKey>(), 0);
TaskDeploymentDescriptor tdd2 = new TaskDeploymentDescriptor(jid2, vid2, eid2, "TestTask2", 2, 7,
new Configuration(), new Configuration(), TestInvokableBlockingCancelable.class.getName(),
Collections.<GateDeploymentDescriptor>emptyList(),
Collections.<GateDeploymentDescriptor>emptyList(),
new ArrayList<BlobKey>(), 0);
TaskOperationResult result1 = tm.submitTask(tdd1);
TaskOperationResult result2 = tm.submitTask(tdd2);
assertTrue(result1.getDescription(), result1.isSuccess());
assertTrue(result2.getDescription(), result2.isSuccess());
assertEquals(eid1, result1.getExecutionId());
assertEquals(eid2, result2.getExecutionId());
Map<ExecutionAttemptID, Task> tasks = tm.getAllRunningTasks();
assertEquals(2, tasks.size());
Task t1 = tasks.get(eid1);
Task t2 = tasks.get(eid2);
assertNotNull(t1);
assertNotNull(t2);
assertEquals(ExecutionState.RUNNING, t1.getExecutionState());
assertEquals(ExecutionState.RUNNING, t2.getExecutionState());
// cancel one task
assertTrue(tm.cancelTask(eid1).isSuccess());
t1.getEnvironment().getExecutingThread().join();
assertEquals(ExecutionState.CANCELED, t1.getExecutionState());
tasks = tm.getAllRunningTasks();
assertEquals(1, tasks.size());
// try to cancel a non existing task
assertFalse(tm.cancelTask(eid1).isSuccess());
// cancel the second task
assertTrue(tm.cancelTask(eid2).isSuccess());
t2.getEnvironment().getExecutingThread().join();
assertEquals(ExecutionState.CANCELED, t2.getExecutionState());
tasks = tm.getAllRunningTasks();
assertEquals(0, tasks.size());
assertNetworkResourcesReleased(tm);
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}finally{
if(jobManager != null){
jobManager.shutdown();
}
if(tm != null){
tm.shutdown();
}