Search in sources :

Example 11 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestQuartzTaskManagerContract method test022ExecuteRecurringOnDemand.

@Test(enabled = true)
public void test022ExecuteRecurringOnDemand() throws Exception {
    final String test = "022ExecuteRecurringOnDemand";
    final OperationResult result = createResult(test);
    addObjectFromFile(taskFilename(test));
    Task task = taskManager.getTask(taskOid(test), result);
    System.out.println("After setup: " + task.debugDump());
    System.out.println("Waiting to see if the task would not start...");
    Thread.sleep(5000L);
    // check the task HAS NOT started
    task.refresh(result);
    System.out.println("After initial wait: " + task.debugDump());
    assertEquals("task is not RUNNABLE", TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    assertNull("task was started", task.getLastRunStartTimestamp());
    assertEquals("task was achieved some progress", 0L, task.getProgress());
    // now let's start the task
    taskManager.scheduleRunnableTaskNow(task, result);
    // task is executing for 1000 ms, so we need to wait slightly longer, in order for the execution to be done
    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() {
        }
    }, 10000, 2000);
    task.refresh(result);
    System.out.println("After refresh: " + task.debugDump());
    AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    AssertJUnit.assertNotNull("LastRunStartTimestamp is null", task.getLastRunStartTimestamp());
    assertFalse("LastRunStartTimestamp is 0", task.getLastRunStartTimestamp().longValue() == 0);
    AssertJUnit.assertNotNull(task.getLastRunFinishTimestamp());
    assertFalse(task.getLastRunFinishTimestamp().longValue() == 0);
    AssertJUnit.assertTrue("no progress", task.getProgress() > 0);
    // now let us suspend it (occurs during wait cycle, so we can put short timeout here)
    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());
}
Also used : Checker(com.evolveum.midpoint.test.Checker) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 12 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestQuartzTaskManagerContract method test017WaitForSubtasksEmpty.

@Test(enabled = true)
public void test017WaitForSubtasksEmpty() throws Exception {
    final String test = "017WaitForSubtasksEmpty";
    final OperationResult result = createResult(test);
    taskManager.getClusterManager().startClusterManagerThread();
    try {
        Task rootTask = taskManager.createTaskInstance((PrismObject<TaskType>) (PrismObject) addObjectFromFile(taskFilename(test)), result);
        display("root task", rootTask);
        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() {
            }
        }, 40000, 3000);
    } finally {
        taskManager.getClusterManager().stopClusterManagerThread(10000L, result);
    }
}
Also used : Checker(com.evolveum.midpoint.test.Checker) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 13 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestQuartzTaskManagerContract method test015DeleteTaskFromRepo.

@Test(enabled = true)
public void test015DeleteTaskFromRepo() throws Exception {
    final String test = "015DeleteTaskFromRepo";
    final OperationResult result = createResult(test);
    PrismObject<? extends ObjectType> object = addObjectFromFile(taskFilename(test));
    String oid = taskOid(test);
    // is the task in Quartz?
    final JobKey key = TaskQuartzImplUtil.createJobKeyForTaskOid(oid);
    AssertJUnit.assertTrue("Job in Quartz does not exist", taskManager.getExecutionManager().getQuartzScheduler().checkExists(key));
    // Remove task from repo
    repositoryService.deleteObject(TaskType.class, taskOid(test), result);
    // We need to wait for a sync interval, so the task scanner has a chance
    // to pick up this task
    waitFor("Waiting for the job to disappear from Quartz Job Store", new Checker() {

        public boolean check() throws ObjectNotFoundException, SchemaException {
            try {
                return !taskManager.getExecutionManager().getQuartzScheduler().checkExists(key);
            } catch (SchedulerException e) {
                throw new SystemException(e);
            }
        }

        @Override
        public void timeout() {
        }
    }, 10000, 2000);
}
Also used : JobKey(org.quartz.JobKey) Checker(com.evolveum.midpoint.test.Checker) SchedulerException(org.quartz.SchedulerException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 14 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestQuartzTaskManagerContract method test013ReleaseAndSuspendLooselyBound.

@Test(enabled = true)
public void test013ReleaseAndSuspendLooselyBound() throws Exception {
    final String test = "013ReleaseAndSuspendLooselyBound";
    final OperationResult result = createResult(test);
    addObjectFromFile(taskFilename(test));
    Task task = taskManager.getTask(taskOid(test), result);
    System.out.println("After setup: " + task.debugDump());
    // check if we can read the extension (xsi:type issue)
    PrismProperty delay = task.getExtensionProperty(SchemaConstants.NOOP_DELAY_QNAME);
    AssertJUnit.assertEquals("Delay was not read correctly", 1000, delay.getRealValue());
    // let us resume (i.e. start the task)
    taskManager.resumeTask(task, result);
    // task is executing for 1000 ms, so we need to wait slightly longer, in order for the execution to be done
    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() {
        }
    }, 10000, 2000);
    task.refresh(result);
    System.out.println("After refresh: " + task.debugDump());
    AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.RELEASED, task.getExclusivityStatus());		// task cycle is 1000 ms, so it should be released now
    AssertJUnit.assertNotNull("LastRunStartTimestamp is null", task.getLastRunStartTimestamp());
    assertFalse("LastRunStartTimestamp is 0", task.getLastRunStartTimestamp().longValue() == 0);
    AssertJUnit.assertNotNull(task.getLastRunFinishTimestamp());
    assertFalse(task.getLastRunFinishTimestamp().longValue() == 0);
    AssertJUnit.assertTrue(task.getProgress() > 0);
    // now let us suspend it (occurs during wait cycle, so we can put short timeout here)
    boolean stopped = taskManager.suspendTask(task, 300, result);
    task.refresh(result);
    AssertJUnit.assertTrue("Task is not stopped", stopped);
    AssertJUnit.assertEquals(TaskExecutionStatus.SUSPENDED, task.getExecutionStatus());
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.RELEASED, task.getExclusivityStatus());
    AssertJUnit.assertNotNull(task.getLastRunStartTimestamp());
    assertFalse(task.getLastRunStartTimestamp().longValue() == 0);
    AssertJUnit.assertNotNull(task.getLastRunFinishTimestamp());
    assertFalse(task.getLastRunFinishTimestamp().longValue() == 0);
    AssertJUnit.assertTrue(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());
}
Also used : Checker(com.evolveum.midpoint.test.Checker) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 15 with Checker

use of com.evolveum.midpoint.test.Checker in project midpoint by Evolveum.

the class TestQuartzTaskManagerContract method test100LightweightSubtasks.

@Test(enabled = true)
public void test100LightweightSubtasks() throws Exception {
    final String test = "100LightweightSubtasks";
    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 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, 500);
    task.refresh(result);
    System.out.println("After refresh (task was executed): " + task.debugDump());
    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());
    }
}
Also used : Checker(com.evolveum.midpoint.test.Checker) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)35 Checker (com.evolveum.midpoint.test.Checker)35 Test (org.testng.annotations.Test)27 Task (com.evolveum.midpoint.task.api.Task)15 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)11 ObjectChecker (com.evolveum.midpoint.test.ObjectChecker)10 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)8 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)8 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)7 QName (javax.xml.namespace.QName)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)6 TaskManagerException (com.evolveum.midpoint.task.api.TaskManagerException)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)2 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)2