Search in sources :

Example 6 with Checker

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

the class TestSanityLegacy method test999Shutdown.

@Test
public void test999Shutdown() throws Exception {
    taskManager.shutdown();
    waitFor("waiting for task manager shutdown", new Checker() {

        @Override
        public boolean check() throws CommonException {
            try {
                return taskManager.getLocallyRunningTasks(new OperationResult("dummy")).isEmpty();
            } catch (TaskManagerException e) {
                throw new SystemException(e);
            }
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 10000);
    AssertJUnit.assertEquals("Some tasks left running after shutdown", new HashSet<Task>(), taskManager.getLocallyRunningTasks(new OperationResult("dummy")));
}
Also used : Checker(com.evolveum.midpoint.test.Checker) ObjectChecker(com.evolveum.midpoint.test.ObjectChecker) Task(com.evolveum.midpoint.task.api.Task) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 7 with Checker

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

the class ConsistencyTest method test999Shutdown.

@Test
public void test999Shutdown() throws Exception {
    taskManager.shutdown();
    waitFor("waiting for task manager shutdown", new Checker() {

        @Override
        public boolean check() throws CommonException {
            try {
                return taskManager.getLocallyRunningTasks(new OperationResult("dummy")).isEmpty();
            } catch (TaskManagerException e) {
                throw new SystemException(e);
            }
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 10000);
    AssertJUnit.assertEquals("Some tasks left running after shutdown", new HashSet<Task>(), taskManager.getLocallyRunningTasks(new OperationResult("dummy")));
}
Also used : Checker(com.evolveum.midpoint.test.Checker) Task(com.evolveum.midpoint.task.api.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) CommonException(com.evolveum.midpoint.util.exception.CommonException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 8 with Checker

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

the class TestQuartzTaskManagerContract method test008MoreHandlers.

/*
     * Single-run task with more handlers.
     */
@Test(enabled = true)
public void test008MoreHandlers() throws Exception {
    final String test = "008MoreHandlers";
    final OperationResult result = createResult(test);
    // reset 'has run' flag on handlers
    singleHandler1.resetHasRun();
    singleHandler2.resetHasRun();
    singleHandler3.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 released
    //        AssertJUnit.assertEquals(TaskExclusivityStatus.RELEASED, task.getExclusivityStatus());
    // .. 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 more than 0 as the task has run at least once
    AssertJUnit.assertTrue("Task reported no progress", task.getProgress() > 0);
    // 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("Handler1 has not run", singleHandler1.hasRun());
    AssertJUnit.assertTrue("Handler2 has not run", singleHandler2.hasRun());
    AssertJUnit.assertTrue("Handler3 has not run", singleHandler3.hasRun());
}
Also used : Checker(com.evolveum.midpoint.test.Checker) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 9 with Checker

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

the class TestQuartzTaskManagerContract method test012Suspend.

/*
    * Suspends a running task.
    */
@Test(enabled = true)
public void test012Suspend() throws Exception {
    final String test = "012Suspend";
    final OperationResult result = createResult(test);
    addObjectFromFile(taskFilename(test));
    // check if we can read the extension (xsi:type issue)
    Task taskTemp = taskManager.getTask(taskOid(test), result);
    PrismProperty delay = taskTemp.getExtensionProperty(SchemaConstants.NOOP_DELAY_QNAME);
    AssertJUnit.assertEquals("Delay was not read correctly", 2000, delay.getRealValue());
    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);
    // Check task status (task is running 5 iterations where each takes 2000 ms)
    Task task = taskManager.getTask(taskOid(test), result);
    AssertJUnit.assertNotNull(task);
    System.out.println(task.debugDump());
    AssertJUnit.assertEquals("Task is not running", TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
    // Now suspend the task
    boolean stopped = taskManager.suspendTask(task, 0, result);
    task.refresh(result);
    System.out.println("After suspend and refresh: " + task.debugDump());
    AssertJUnit.assertTrue("Task is not stopped", stopped);
    AssertJUnit.assertEquals("Task is not suspended", TaskExecutionStatus.SUSPENDED, task.getExecutionStatus());
    AssertJUnit.assertNotNull("Task last start time is null", task.getLastRunStartTimestamp());
    assertFalse("Task last start time is 0", task.getLastRunStartTimestamp().longValue() == 0);
    // The progress should be more than 0
    AssertJUnit.assertTrue("Task has not reported any progress", 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 10 with Checker

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

the class TestQuartzTaskManagerContract method test010CycleCronLoose.

@Test(enabled = true)
public void test010CycleCronLoose() throws Exception {
    final String test = "010CycleCronLoose";
    final OperationResult result = createResult(test);
    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.getProgress() >= 2;
        }

        @Override
        public void timeout() {
        }
    }, 15000, 2000);
    // Check task status
    Task task = taskManager.getTask(taskOid(test), result);
    AssertJUnit.assertNotNull(task);
    System.out.println(task.debugDump());
    TaskType t = repositoryService.getObject(TaskType.class, taskOid(test), null, result).getValue().getValue();
    System.out.println(ObjectTypeUtil.dump(t));
    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 at least 2 as the task has run at least twice
    AssertJUnit.assertTrue("Task has not been executed at least twice", 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());
    // Suspend the task (in order to keep logs clean), without much waiting
    taskManager.suspendTask(task, 100, result);
}
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