use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test011MoreHandlersAndSchedules.
@Test(enabled = true)
public void test011MoreHandlersAndSchedules() throws Exception {
final String test = "011MoreHandlersAndSchedules";
final OperationResult result = createResult(test);
// reset 'has run' flag on handlers
l1Handler.resetHasRun();
l2Handler.resetHasRun();
l3Handler.resetHasRun();
addObjectFromFile(taskFilename(test));
waitFor("Waiting for task manager to execute 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.getExecutionStatus() == TaskExecutionStatus.CLOSED;
}
@Override
public void timeout() {
}
}, 30000, 2000);
// Check task status
Task task = taskManager.getTask(taskOid(test), result);
AssertJUnit.assertNotNull(task);
System.out.println(task.debugDump());
PrismObject<TaskType> o = repositoryService.getObject(TaskType.class, taskOid(test), null, result);
System.out.println(ObjectTypeUtil.dump(o.getValue().getValue()));
// .. it should be closed
AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task.getExecutionStatus());
// .. and last run should not be zero
AssertJUnit.assertNotNull(task.getLastRunStartTimestamp());
assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
AssertJUnit.assertNotNull("Last run finish timestamp not set", task.getLastRunFinishTimestamp());
assertFalse("Last run finish timestamp is 0", task.getLastRunFinishTimestamp().longValue() == 0);
/*
* Here the execution should be as follows:
* progress: 0->1 on first execution of L1 handler
* progress: 1->2 on first execution of L2 handler (ASAP after finishing L1)
* progress: 2->3 on second execution of L2 handler (2 seconds later)
* progress: 3->4 on third execution of L2 handler (2 seconds later)
* progress: 4->5 on fourth execution of L2 handler (2 seconds later)
* progress: 5->6 on first (and therefore last) execution of L3 handler
* progress: 6->7 on last execution of L2 handler (2 seconds later, perhaps)
* progress: 7->8 on last execution of L1 handler
*/
AssertJUnit.assertEquals("Task reported wrong progress", 8, task.getProgress());
// Test for presence of a result. It should be there and it should
// indicate success
OperationResult taskResult = task.getResult();
AssertJUnit.assertNotNull("Task result is null", taskResult);
AssertJUnit.assertTrue("Task did not yield 'success' status", taskResult.isSuccess());
// Test for no presence of handlers
AssertJUnit.assertNotNull("Handler is gone", task.getHandlerUri());
AssertJUnit.assertTrue("Other handlers are still present", task.getOtherHandlersUriStack() == null || task.getOtherHandlersUriStack().getUriStackEntry().isEmpty());
// Test if all three handlers were run
AssertJUnit.assertTrue("L1 handler has not run", l1Handler.hasRun());
AssertJUnit.assertTrue("L2 handler has not run", l2Handler.hasRun());
AssertJUnit.assertTrue("L3 handler has not run", l3Handler.hasRun());
}
use of com.evolveum.midpoint.test.Checker 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());
}
}
use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test006Cycle.
/*
* Executes a cyclic task
*/
@Test(enabled = true)
public void test006Cycle() throws Exception {
final String test = "006Cycle";
final OperationResult result = createResult(test);
// But before that check sanity ... a known problem with xsi:type
PrismObject<? extends ObjectType> object = addObjectFromFile(taskFilename(test));
ObjectType objectType = object.asObjectable();
TaskType addedTask = (TaskType) objectType;
System.out.println("Added task");
System.out.println(object.debugDump());
PrismContainer<?> extensionContainer = object.getExtension();
PrismProperty<Object> deadProperty = extensionContainer.findProperty(new QName(NS_WHATEVER, "dead"));
assertEquals("Bad typed of 'dead' property (add result)", DOMUtil.XSD_INT, deadProperty.getDefinition().getTypeName());
// Read from repo
PrismObject<TaskType> repoTask = repositoryService.getObject(TaskType.class, addedTask.getOid(), null, result);
TaskType repoTaskType = repoTask.asObjectable();
extensionContainer = repoTask.getExtension();
deadProperty = extensionContainer.findProperty(new QName(NS_WHATEVER, "dead"));
assertEquals("Bad typed of 'dead' property (from repo)", DOMUtil.XSD_INT, deadProperty.getDefinition().getTypeName());
// We need to wait for a sync interval, so the task scanner has a chance
// to pick up this
// task
waitFor("Waiting for task manager to execute 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.getProgress() > 0;
}
@Override
public void timeout() {
}
}, 10000, 2000);
// Check task status
Task task = taskManager.getTask(taskOid(test), result);
AssertJUnit.assertNotNull(task);
System.out.println(task.debugDump());
PrismObject<TaskType> t = repositoryService.getObject(TaskType.class, taskOid(test), null, result);
System.out.println(t.debugDump());
// .. it should be running
AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
// .. and claimed
// AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());
// .. and last run should not be zero
AssertJUnit.assertNotNull("LastRunStartTimestamp is null", task.getLastRunStartTimestamp());
assertFalse("LastRunStartTimestamp is 0", task.getLastRunStartTimestamp().longValue() == 0);
AssertJUnit.assertNotNull("LastRunFinishTimestamp is null", task.getLastRunFinishTimestamp());
assertFalse("LastRunFinishTimestamp is 0", task.getLastRunFinishTimestamp().longValue() == 0);
// The progress should be more at least 1 - so small because of lazy testing machine ... (wait time before task runs is 2 seconds)
AssertJUnit.assertTrue("Task progress is too small (should be at least 1)", task.getProgress() >= 1);
// Test for presence of a result. It should be there and it should
// indicate success
OperationResult taskResult = task.getResult();
AssertJUnit.assertNotNull("Task result is null", taskResult);
AssertJUnit.assertTrue("Task did not yield 'success' status", taskResult.isSuccess());
// Suspend the task (in order to keep logs clean), without much waiting
taskManager.suspendTask(task, 100, result);
}
use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test005Single.
/*
* Execute a single-run task.
*/
@Test(enabled = true)
public void test005Single() throws Exception {
final String test = "005Single";
final OperationResult result = createResult(test);
// reset 'has run' flag on the handler
singleHandler1.resetHasRun();
// Add single task. This will get picked by task scanner and executed
addObjectFromFile(taskFilename(test));
logger.trace("Retrieving the task...");
TaskQuartzImpl task = (TaskQuartzImpl) taskManager.getTask(taskOid(test), result);
AssertJUnit.assertNotNull(task);
logger.trace("Task retrieval OK.");
// We need to wait for a sync interval, so the task scanner has a chance
// to pick up this
// task
waitFor("Waiting for task manager to execute 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.getExecutionStatus() == TaskExecutionStatus.CLOSED;
}
@Override
public void timeout() {
}
}, 10000, 1000);
logger.info("... done");
// Check task status
Task task1 = taskManager.getTask(taskOid(test), result);
AssertJUnit.assertNotNull(task1);
System.out.println("getTask returned: " + task1.debugDump());
PrismObject<TaskType> po = repositoryService.getObject(TaskType.class, taskOid(test), null, result);
System.out.println("getObject returned: " + po.debugDump());
// .. it should be closed
AssertJUnit.assertEquals(TaskExecutionStatus.CLOSED, task1.getExecutionStatus());
// .. and released
// AssertJUnit.assertEquals(TaskExclusivityStatus.RELEASED, task1.getExclusivityStatus());
// .. and last run should not be zero
AssertJUnit.assertNotNull("LastRunStartTimestamp is null", task1.getLastRunStartTimestamp());
assertFalse("LastRunStartTimestamp is 0", task1.getLastRunStartTimestamp().longValue() == 0);
AssertJUnit.assertNotNull("LastRunFinishTimestamp is null", task1.getLastRunFinishTimestamp());
assertFalse("LastRunFinishTimestamp is 0", task1.getLastRunFinishTimestamp().longValue() == 0);
// The progress should be more than 0 as the task has run at least once
AssertJUnit.assertTrue("Task reported no progress", task1.getProgress() > 0);
// Test for presence of a result. It should be there and it should
// indicate success
OperationResult taskResult = task1.getResult();
AssertJUnit.assertNotNull("Task result is null", taskResult);
AssertJUnit.assertTrue("Task did not yield 'success' status", taskResult.isSuccess());
// Test for no presence of handlers
//AssertJUnit.assertNull("Handler is still present", task1.getHandlerUri());
AssertJUnit.assertNotNull("Handler is gone", task1.getHandlerUri());
AssertJUnit.assertTrue("Other handlers are still present", task1.getOtherHandlersUriStack() == null || task1.getOtherHandlersUriStack().getUriStackEntry().isEmpty());
// Test whether handler has really run
AssertJUnit.assertTrue("Handler1 has not run", singleHandler1.hasRun());
}
use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test016WaitForSubtasks.
@Test(enabled = true)
public void test016WaitForSubtasks() throws Exception {
final String test = "016WaitForSubtasks";
final OperationResult result = createResult(test);
try {
Task rootTask = taskManager.createTaskInstance((PrismObject<TaskType>) (PrismObject) addObjectFromFile(taskFilename(test)), result);
Task firstChildTask = taskManager.createTaskInstance((PrismObject<TaskType>) (PrismObject) addObjectFromFile(taskFilename(test + "-child-1")), result);
Task firstReloaded = taskManager.getTaskByIdentifier(firstChildTask.getTaskIdentifier(), result);
assertEquals("Didn't get correct task by identifier", firstChildTask.getOid(), firstReloaded.getOid());
Task secondChildTask = rootTask.createSubtask();
secondChildTask.setName("Second child");
secondChildTask.setOwner(rootTask.getOwner());
secondChildTask.pushHandlerUri(SINGLE_TASK_HANDLER_URI, new ScheduleType(), null);
// will resume it after root starts waiting for tasks
secondChildTask.setInitialExecutionStatus(TaskExecutionStatus.SUSPENDED);
taskManager.switchToBackground(secondChildTask, result);
Task firstPrerequisiteTask = taskManager.createTaskInstance((PrismObject<TaskType>) (PrismObject) addObjectFromFile(taskFilename(test + "-prerequisite-1")), result);
List<Task> prerequisities = rootTask.listPrerequisiteTasks(result);
assertEquals("Wrong # of prerequisite tasks", 1, prerequisities.size());
assertEquals("Wrong OID of prerequisite task", firstPrerequisiteTask.getOid(), prerequisities.get(0).getOid());
Task secondPrerequisiteTask = taskManager.createTaskInstance();
secondPrerequisiteTask.setName("Second prerequisite");
secondPrerequisiteTask.setOwner(rootTask.getOwner());
secondPrerequisiteTask.addDependent(rootTask.getTaskIdentifier());
secondPrerequisiteTask.pushHandlerUri(NoOpTaskHandler.HANDLER_URI, new ScheduleType(), null);
secondPrerequisiteTask.setExtensionPropertyValue(SchemaConstants.NOOP_DELAY_QNAME, 1500);
secondPrerequisiteTask.setExtensionPropertyValue(SchemaConstants.NOOP_STEPS_QNAME, 1);
// will resume it after root starts waiting for tasks
secondPrerequisiteTask.setInitialExecutionStatus(TaskExecutionStatus.SUSPENDED);
secondPrerequisiteTask.addDependent(rootTask.getTaskIdentifier());
taskManager.switchToBackground(secondPrerequisiteTask, result);
LOGGER.info("Starting waiting for child/prerequisite tasks");
rootTask.startWaitingForTasksImmediate(result);
firstChildTask.refresh(result);
assertEquals("Parent is not set correctly on 1st child task", rootTask.getTaskIdentifier(), firstChildTask.getParent());
secondChildTask.refresh(result);
assertEquals("Parent is not set correctly on 2nd child task", rootTask.getTaskIdentifier(), secondChildTask.getParent());
firstPrerequisiteTask.refresh(result);
assertEquals("Dependents are not set correctly on 1st prerequisite task (count differs)", 1, firstPrerequisiteTask.getDependents().size());
assertEquals("Dependents are not set correctly on 1st prerequisite task (value differs)", rootTask.getTaskIdentifier(), firstPrerequisiteTask.getDependents().get(0));
List<Task> deps = firstPrerequisiteTask.listDependents(result);
assertEquals("Dependents are not set correctly on 1st prerequisite task - listDependents - (count differs)", 1, deps.size());
assertEquals("Dependents are not set correctly on 1st prerequisite task - listDependents - (value differs)", rootTask.getOid(), deps.get(0).getOid());
secondPrerequisiteTask.refresh(result);
assertEquals("Dependents are not set correctly on 2nd prerequisite task (count differs)", 1, secondPrerequisiteTask.getDependents().size());
assertEquals("Dependents are not set correctly on 2nd prerequisite task (value differs)", rootTask.getTaskIdentifier(), secondPrerequisiteTask.getDependents().get(0));
deps = secondPrerequisiteTask.listDependents(result);
assertEquals("Dependents are not set correctly on 2nd prerequisite task - listDependents - (count differs)", 1, deps.size());
assertEquals("Dependents are not set correctly on 2nd prerequisite task - listDependents - (value differs)", rootTask.getOid(), deps.get(0).getOid());
LOGGER.info("Resuming suspended child/prerequisite tasks");
taskManager.resumeTask(secondChildTask, result);
taskManager.resumeTask(secondPrerequisiteTask, result);
final String rootOid = taskOid(test);
waitFor("Waiting for task manager to execute the task", new Checker() {
public boolean check() throws ObjectNotFoundException, SchemaException {
Task task = taskManager.getTask(rootOid, result);
IntegrationTestTools.display("Task while waiting for task manager to execute the task", task);
return task.getExecutionStatus() == TaskExecutionStatus.CLOSED;
}
@Override
public void timeout() {
}
}, 60000, 3000);
firstChildTask.refresh(result);
secondChildTask.refresh(result);
firstPrerequisiteTask.refresh(result);
secondPrerequisiteTask.refresh(result);
assertEquals("1st child task should be closed", TaskExecutionStatus.CLOSED, firstChildTask.getExecutionStatus());
assertEquals("2nd child task should be closed", TaskExecutionStatus.CLOSED, secondChildTask.getExecutionStatus());
assertEquals("1st prerequisite task should be closed", TaskExecutionStatus.CLOSED, firstPrerequisiteTask.getExecutionStatus());
assertEquals("2nd prerequisite task should be closed", TaskExecutionStatus.CLOSED, secondPrerequisiteTask.getExecutionStatus());
} finally {
// taskManager.getClusterManager().stopClusterManagerThread(10000L, result);
}
}
Aggregations