use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test009CycleLoose.
@Test(enabled = true)
public void test009CycleLoose() throws Exception {
final String test = "009CycleLoose";
final OperationResult result = createResult(test);
PrismObject<? extends ObjectType> object = addObjectFromFile(taskFilename(test));
// 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() >= 1;
}
@Override
public void timeout() {
}
}, 15000, 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 last run should not be zero
AssertJUnit.assertNotNull(task.getLastRunStartTimestamp());
assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
AssertJUnit.assertNotNull(task.getLastRunFinishTimestamp());
assertFalse(task.getLastRunFinishTimestamp().longValue() == 0);
// The progress should be more at least 1 - lazy neptunus... (wait time before task runs is 2 seconds)
AssertJUnit.assertTrue("Progress is none or too small", task.getProgress() >= 1);
// The progress should not be too big (indicates fault in scheduling)
AssertJUnit.assertTrue("Progress is too big (fault in scheduling?)", task.getProgress() <= 7);
// 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 test014SuspendLongRunning.
@Test(enabled = true)
public void test014SuspendLongRunning() throws Exception {
final String test = "014SuspendLongRunning";
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 start the task", task);
return task.getLastRunStartTimestamp() != null;
}
@Override
public void timeout() {
}
}, 10000, 2000);
task.refresh(result);
System.out.println("After refresh: " + task.debugDump());
AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
// AssertJUnit.assertEquals(TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());
AssertJUnit.assertNotNull(task.getLastRunStartTimestamp());
assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
// now let us suspend it, without long waiting
boolean stopped = taskManager.suspendTask(task, 1000, result);
task.refresh(result);
assertFalse("Task is stopped (it should be running for now)", stopped);
AssertJUnit.assertEquals("Task is not suspended", TaskExecutionStatus.SUSPENDED, task.getExecutionStatus());
// AssertJUnit.assertEquals("Task should be still claimed, as it is not definitely stopped", TaskExclusivityStatus.CLAIMED, task.getExclusivityStatus());
AssertJUnit.assertNotNull(task.getLastRunStartTimestamp());
assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
AssertJUnit.assertNull(task.getLastRunFinishTimestamp());
AssertJUnit.assertEquals("There should be no progress reported", 0, task.getProgress());
// now let us wait for the finish
stopped = taskManager.suspendTask(task, 0, result);
task.refresh(result);
AssertJUnit.assertTrue("Task is not stopped", stopped);
AssertJUnit.assertEquals("Task is not suspended", TaskExecutionStatus.SUSPENDED, task.getExecutionStatus());
AssertJUnit.assertNotNull(task.getLastRunStartTimestamp());
assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
AssertJUnit.assertNotNull("Last run finish time is null", task.getLastRunStartTimestamp());
assertFalse("Last run finish time is zero", task.getLastRunStartTimestamp().longValue() == 0);
AssertJUnit.assertTrue("Progress is not reported", task.getProgress() > 0);
// Thread.sleep(200); // give the scheduler a chance to release the task
// task.refresh(result);
// AssertJUnit.assertEquals("Task is not released", TaskExclusivityStatus.RELEASED, task.getExclusivityStatus());
}
use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test019FinishedHandler.
/*
* Recurring task returning FINISHED_HANDLER code.
*/
@Test(enabled = true)
public void test019FinishedHandler() throws Exception {
final String test = "019FinishedHandler";
final OperationResult result = createResult(test);
// reset 'has run' flag on handlers
singleHandler1.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() {
}
}, 15000, 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);
// The progress should be at least 2 as the task has run at least twice (once in each handler)
AssertJUnit.assertTrue("Task reported progress lower than 2", task.getProgress() >= 2);
// 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 "outer" handler has run as well
AssertJUnit.assertTrue("Handler1 has not run", singleHandler1.hasRun());
}
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());
}
}
Aggregations