// task manager mock
TaskOperationProtocol taskManager = mock(TaskOperationProtocol.class);
when(taskManager.submitTask(Matchers.any(TaskDeploymentDescriptor.class))).thenReturn(new TaskOperationResult(execId, true));
// first return NOT SUCCESS (task not found, cancel call overtook deploy call), then success (cancel call after deploy call)
when(taskManager.cancelTask(execId)).thenReturn(new TaskOperationResult(execId, false), new TaskOperationResult(execId, true));
Instance instance = getInstance(taskManager);
AllocatedSlot slot = instance.allocateSlot(new JobID());
vertex.deployToSlot(slot);