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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations