use of com.evolveum.midpoint.task.quartzimpl.execution.JobExecutor in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test105LightweightSubtasksSuspension.
@Test(enabled = true)
public void test105LightweightSubtasksSuspension() throws Exception {
final String test = "105LightweightSubtasksSuspension";
final OperationResult result = createResult(test);
addObjectFromFile(taskFilename(test));
Task task = taskManager.getTask(taskOid(test), result);
System.out.println("After setup: " + task.debugDump());
waitFor("Waiting for task manager to start the task", new Checker() {
public boolean check() throws ObjectNotFoundException, SchemaException {
Task task = taskManager.getTask(taskOid(test), result);
IntegrationTestTools.display("Task while waiting for task manager to execute the task", task);
return task.getLastRunStartTimestamp() != null && task.getLastRunStartTimestamp() != 0L;
}
@Override
public void timeout() {
}
}, 15000, 500);
task.refresh(result);
System.out.println("After refresh (task was started; and it should run now): " + task.debugDump());
AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
// check the thread
List<JobExecutionContext> jobExecutionContexts = taskManager.getExecutionManager().getQuartzScheduler().getCurrentlyExecutingJobs();
JobExecutionContext found = null;
for (JobExecutionContext jobExecutionContext : jobExecutionContexts) {
if (task.getOid().equals(jobExecutionContext.getJobDetail().getKey().getName())) {
found = jobExecutionContext;
break;
}
}
assertNotNull("Job for the task was not found", found);
JobExecutor executor = (JobExecutor) found.getJobInstance();
assertNotNull("No job executor", executor);
Thread thread = executor.getExecutingThread();
assertNotNull("No executing thread", thread);
// now let us suspend it - the handler should stop, as well as the subtasks
boolean stopped = taskManager.suspendTask(task, 10000L, result);
task.refresh(result);
AssertJUnit.assertTrue("Task is not stopped", stopped);
AssertJUnit.assertEquals("Task is not suspended", TaskExecutionStatus.SUSPENDED, task.getExecutionStatus());
Collection<? extends Task> subtasks = parallelTaskHandler.getLastTaskExecuted().getLightweightAsynchronousSubtasks();
assertEquals("Wrong number of subtasks", MockParallelTaskHandler.NUM_SUBTASKS, subtasks.size());
for (Task subtask : subtasks) {
assertEquals("Wrong subtask state", TaskExecutionStatus.CLOSED, subtask.getExecutionStatus());
MockParallelTaskHandler.MyLightweightTaskHandler handler = (MockParallelTaskHandler.MyLightweightTaskHandler) subtask.getLightweightTaskHandler();
assertTrue("Handler has not run", handler.hasRun());
assertTrue("Handler has not exited", handler.hasExited());
}
}
Aggregations