use of com.evolveum.midpoint.task.api.RunningLightweightTask in project midpoint by Evolveum.
the class ProcessingCoordinator method createWorkerThreads.
public void createWorkerThreads() {
if (threadsCount == 0) {
return;
}
assert workerSpecificResults != null;
// remove subtasks that could have been created previously
coordinatorTask.deleteLightweightAsynchronousSubtasks();
for (int i = 0; i < threadsCount; i++) {
// we intentionally do not put worker specific result under main operation result until the handler is done
// (because of concurrency issues - adding subresults vs e.g. putting main result into the task)
OperationResult workerSpecificResult = new OperationResult(OP_HANDLE_ASYNCHRONOUSLY);
workerSpecificResult.addContext("subtaskIndex", i + 1);
workerSpecificResults.add(workerSpecificResult);
RunningLightweightTask subtask = coordinatorTask.createSubtask(new WorkerHandler(workerSpecificResult));
subtask.setCategory(coordinatorTask.getCategory());
subtask.setResult(new OperationResult(OP_EXECUTE_WORKER, OperationResultStatus.IN_PROGRESS, (String) null));
subtask.setName("Worker thread " + (i + 1) + " of " + threadsCount);
subtask.setExecutionEnvironment(CloneUtil.clone(coordinatorTask.getExecutionEnvironment()));
subtask.startLightweightHandler();
LOGGER.trace("Worker subtask {} created", subtask);
}
}
use of com.evolveum.midpoint.task.api.RunningLightweightTask in project midpoint by Evolveum.
the class TestTaskManagerBasic method test260LightweightSubtasksSuspension.
@Test
public void test260LightweightSubtasksSuspension() throws Exception {
given();
OperationResult result = createOperationResult();
when();
add(TASK_WITH_THREADS_TO_SUSPEND, result);
waitForTaskStart(TASK_WITH_THREADS_TO_SUSPEND.oid, result, 15000, 500);
TaskQuartzImpl task = getTaskWithResult(TASK_WITH_THREADS_TO_SUSPEND.oid, result);
displayDumpable("taskAfterStart", task);
// assertEquals(TaskExecutionStateType.RUNNING, task.getExecutionState()); // todo
assertEquals(TaskSchedulingStateType.READY, task.getSchedulingState());
// check the thread
JobExecutionContext found = findJobForTask(task);
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);
then();
task.refresh(result);
assertTrue("Task is not stopped", stopped);
assertSuspended(task);
Collection<? extends RunningLightweightTask> subtasks = mockParallelTaskHandler.getLastTaskExecuted().getLightweightAsynchronousSubtasks();
assertEquals("Wrong number of subtasks", MockParallelTaskHandler.NUM_SUBTASKS, subtasks.size());
for (RunningLightweightTask subtask : subtasks) {
assertEquals("Wrong subtask state", TaskExecutionStateType.CLOSED, subtask.getExecutionState());
MockParallelTaskHandler.MyLightweightTaskHandler handler = (MockParallelTaskHandler.MyLightweightTaskHandler) subtask.getLightweightTaskHandler();
assertTrue("Handler has not run", handler.hasRun());
assertTrue("Handler has not exited", handler.hasExited());
}
}
use of com.evolveum.midpoint.task.api.RunningLightweightTask in project midpoint by Evolveum.
the class TestTaskManagerBasic method test250TaskWithThreads.
/**
* Tests task with lightweight subtasks.
*/
@Test
public void test250TaskWithThreads() throws Exception {
given();
OperationResult result = createOperationResult();
when();
add(TASK_WITH_THREADS, result);
checkTreadSafety(TASK_WITH_THREADS.oid, 1000L, result);
waitUntilDone(TASK_WITH_THREADS.oid, result, 15000, 100);
waitForTaskClose(TASK_WITH_THREADS.oid, result, 15000, 100);
then();
Task task = getTaskWithResult(TASK_WITH_THREADS.oid, result);
displayDumpable("Task after", task);
Collection<? extends RunningLightweightTask> subtasks = mockParallelTaskHandler.getLastTaskExecuted().getLightweightAsynchronousSubtasks();
assertEquals("Wrong number of subtasks", MockParallelTaskHandler.NUM_SUBTASKS, subtasks.size());
for (RunningLightweightTask subtask : subtasks) {
assertEquals("Wrong subtask state", TaskExecutionStateType.CLOSED, subtask.getExecutionState());
MockParallelTaskHandler.MyLightweightTaskHandler handler = (MockParallelTaskHandler.MyLightweightTaskHandler) subtask.getLightweightTaskHandler();
assertTrue("Handler has not run in " + subtask, handler.hasRun());
assertTrue("Handler has not exited in " + subtask, handler.hasExited());
}
}
Aggregations