Search in sources :

Example 31 with Checker

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

the class TestGeneralChangeProcessor method waitForTaskClose.

protected void waitForTaskClose(final Task task, final int timeout) throws Exception {
    final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class + ".waitForTaskClose");
    Checker checker = new Checker() {

        @Override
        public boolean check() throws CommonException {
            task.refresh(waitResult);
            OperationResult result = task.getResult();
            if (verbose)
                display("Check result", result);
            return task.getExecutionStatus() == TaskExecutionStatus.CLOSED;
        }

        @Override
        public void timeout() {
            try {
                task.refresh(waitResult);
            } catch (ObjectNotFoundException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            } catch (SchemaException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            }
            OperationResult result = task.getResult();
            LOGGER.debug("Result of timed-out task:\n{}", result.debugDump());
            assert false : "Timeout (" + timeout + ") while waiting for " + task + " to finish. Last result " + result;
        }
    };
    IntegrationTestTools.waitFor("Waiting for " + task + " finish", checker, timeout, 1000);
}
Also used : AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Checker(com.evolveum.midpoint.test.Checker) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 32 with Checker

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

the class AbstractModelIntegrationTest method waitForTaskFinish.

protected void waitForTaskFinish(final String taskOid, final boolean checkSubresult, final int timeout, final boolean errorOk) throws CommonException {
    final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class + ".waitForTaskFinish");
    Checker checker = new Checker() {

        @Override
        public boolean check() throws CommonException {
            Task freshTask = taskManager.getTask(taskOid, waitResult);
            OperationResult result = freshTask.getResult();
            if (verbose)
                display("Check result", result);
            if (isError(result, checkSubresult)) {
                if (errorOk) {
                    return true;
                } else {
                    AssertJUnit.fail("Error in " + freshTask + ": " + TestUtil.getErrorMessage(result));
                }
            }
            if (isUknown(result, checkSubresult)) {
                return false;
            }
            //				assert !isUknown(result, checkSubresult) : "Unknown result in "+freshTask+": "+IntegrationTestTools.getErrorMessage(result);
            return !isInProgress(result, checkSubresult);
        }

        @Override
        public void timeout() {
            try {
                Task freshTask = taskManager.getTask(taskOid, waitResult);
                OperationResult result = freshTask.getResult();
                LOGGER.debug("Result of timed-out task:\n{}", result.debugDump());
                assert false : "Timeout (" + timeout + ") while waiting for " + freshTask + " to finish. Last result " + result;
            } catch (ObjectNotFoundException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            } catch (SchemaException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            }
        }
    };
    IntegrationTestTools.waitFor("Waiting for task " + taskOid + " finish", checker, timeout, DEFAULT_TASK_SLEEP_TIME);
}
Also used : AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Checker(com.evolveum.midpoint.test.Checker) Task(com.evolveum.midpoint.task.api.Task) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 33 with Checker

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

the class AbstractModelIntegrationTest method waitForTaskNextRun.

protected OperationResult waitForTaskNextRun(final Task origTask, final boolean checkSubresult, final int timeout, final OperationResult waitResult, boolean kickTheTask) throws Exception {
    final Long origLastRunStartTimestamp = origTask.getLastRunStartTimestamp();
    final Long origLastRunFinishTimestamp = origTask.getLastRunFinishTimestamp();
    if (kickTheTask) {
        taskManager.scheduleTaskNow(origTask, waitResult);
    }
    final Holder<OperationResult> taskResultHolder = new Holder<>();
    Checker checker = new Checker() {

        @Override
        public boolean check() throws CommonException {
            Task freshTask = taskManager.getTask(origTask.getOid(), waitResult);
            OperationResult taskResult = freshTask.getResult();
            //						+ " : " + longTimeToString(freshTask.getLastRunStartTimestamp()) + "-" + longTimeToString(freshTask.getLastRunFinishTimestamp()));
            if (verbose)
                display("Check result", taskResult);
            taskResultHolder.setValue(taskResult);
            if (isError(taskResult, checkSubresult)) {
                return true;
            }
            if (isUknown(taskResult, checkSubresult)) {
                return false;
            }
            if (freshTask.getLastRunFinishTimestamp() == null) {
                return false;
            }
            if (freshTask.getLastRunStartTimestamp() == null) {
                return false;
            }
            return !freshTask.getLastRunStartTimestamp().equals(origLastRunStartTimestamp) && !freshTask.getLastRunFinishTimestamp().equals(origLastRunFinishTimestamp) && freshTask.getLastRunStartTimestamp() < freshTask.getLastRunFinishTimestamp();
        }

        @Override
        public void timeout() {
            try {
                Task freshTask = taskManager.getTask(origTask.getOid(), waitResult);
                OperationResult result = freshTask.getResult();
                LOGGER.debug("Timed-out task:\n{}", freshTask.debugDump());
                display("Times", "origLastRunStartTimestamp=" + longTimeToString(origLastRunStartTimestamp) + ", origLastRunFinishTimestamp=" + longTimeToString(origLastRunFinishTimestamp) + ", freshTask.getLastRunStartTimestamp()=" + longTimeToString(freshTask.getLastRunStartTimestamp()) + ", freshTask.getLastRunFinishTimestamp()=" + longTimeToString(freshTask.getLastRunFinishTimestamp()));
                assert false : "Timeout (" + timeout + ") while waiting for " + freshTask + " next run. Last result " + result;
            } catch (ObjectNotFoundException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            } catch (SchemaException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            }
        }
    };
    IntegrationTestTools.waitFor("Waiting for task " + origTask + " next run", checker, timeout, DEFAULT_TASK_SLEEP_TIME);
    Task freshTask = taskManager.getTask(origTask.getOid(), waitResult);
    LOGGER.debug("Final task:\n{}", freshTask.debugDump());
    display("Times", "origLastRunStartTimestamp=" + longTimeToString(origLastRunStartTimestamp) + ", origLastRunFinishTimestamp=" + longTimeToString(origLastRunFinishTimestamp) + ", freshTask.getLastRunStartTimestamp()=" + longTimeToString(freshTask.getLastRunStartTimestamp()) + ", freshTask.getLastRunFinishTimestamp()=" + longTimeToString(freshTask.getLastRunFinishTimestamp()));
    return taskResultHolder.getValue();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Checker(com.evolveum.midpoint.test.Checker) Task(com.evolveum.midpoint.task.api.Task) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Holder(com.evolveum.midpoint.util.Holder) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 34 with Checker

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

the class AbstractModelIntegrationTest method waitForTaskStart.

protected void waitForTaskStart(final String taskOid, final boolean checkSubresult, final int timeout) throws Exception {
    final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class + ".waitForTaskStart");
    Checker checker = new Checker() {

        @Override
        public boolean check() throws CommonException {
            Task freshTask = taskManager.getTask(taskOid, waitResult);
            OperationResult result = freshTask.getResult();
            if (verbose)
                display("Check result", result);
            assert !isError(result, checkSubresult) : "Error in " + freshTask + ": " + TestUtil.getErrorMessage(result);
            if (isUknown(result, checkSubresult)) {
                return false;
            }
            return freshTask.getLastRunStartTimestamp() != null;
        }

        @Override
        public void timeout() {
            try {
                Task freshTask = taskManager.getTask(taskOid, waitResult);
                OperationResult result = freshTask.getResult();
                LOGGER.debug("Result of timed-out task:\n{}", result.debugDump());
                assert false : "Timeout (" + timeout + ") while waiting for " + freshTask + " to start. Last result " + result;
            } catch (ObjectNotFoundException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            } catch (SchemaException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            }
        }
    };
    IntegrationTestTools.waitFor("Waiting for task " + taskOid + " start", checker, timeout, DEFAULT_TASK_SLEEP_TIME);
}
Also used : AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Checker(com.evolveum.midpoint.test.Checker) Task(com.evolveum.midpoint.task.api.Task) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 35 with Checker

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

the class AbstractModelIntegrationTest method waitForTaskFinish.

protected void waitForTaskFinish(final Task task, final boolean checkSubresult, final int timeout, long sleepTime) throws Exception {
    final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class + ".waitForTaskFinish");
    Checker checker = new Checker() {

        @Override
        public boolean check() throws CommonException {
            task.refresh(waitResult);
            waitResult.summarize();
            //				Task freshTask = taskManager.getTask(task.getOid(), waitResult);
            OperationResult result = task.getResult();
            if (verbose)
                display("Check result", result);
            assert !isError(result, checkSubresult) : "Error in " + task + ": " + TestUtil.getErrorMessage(result);
            assert !isUknown(result, checkSubresult) : "Unknown result in " + task + ": " + TestUtil.getErrorMessage(result);
            return !isInProgress(result, checkSubresult);
        }

        @Override
        public void timeout() {
            try {
                task.refresh(waitResult);
            } catch (ObjectNotFoundException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            } catch (SchemaException e) {
                LOGGER.error("Exception during task refresh: {}", e, e);
            }
            OperationResult result = task.getResult();
            LOGGER.debug("Result of timed-out task:\n{}", result.debugDump());
            assert false : "Timeout (" + timeout + ") while waiting for " + task + " to finish. Last result " + result;
        }
    };
    IntegrationTestTools.waitFor("Waiting for " + task + " finish", checker, timeout, sleepTime);
}
Also used : AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Checker(com.evolveum.midpoint.test.Checker) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

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