| | |
| | | } |
| | | |
| | | /** |
| | | * Add a task to the configuration of the current running DS. |
| | | * @param taskEntry The task to add. |
| | | * @param expectedResult The expected result code for the ADD. |
| | | * @param errorMessage The expected error messageID when the expected |
| | | * result code is not SUCCESS |
| | | */ |
| | | private void addTask(Entry taskEntry, ResultCode expectedResult, |
| | | Message errorMessage) |
| | | { |
| | | try |
| | | { |
| | | log("AddTask/" + taskEntry); |
| | | |
| | | // Change config of DS to launch the total update task |
| | | InternalClientConnection connection = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | // Add the task. |
| | | |
| | | AddOperation addOperation = |
| | | connection.processAdd(taskEntry.getDN(), |
| | | taskEntry.getObjectClasses(), |
| | | taskEntry.getUserAttributes(), |
| | | taskEntry.getOperationalAttributes()); |
| | | |
| | | assertEquals(addOperation.getResultCode(), expectedResult, |
| | | "Result of ADD operation of the task is: " |
| | | + addOperation.getResultCode() |
| | | + " Expected:" |
| | | + expectedResult + " Details:" + addOperation.getErrorMessage() |
| | | + addOperation.getAdditionalLogMessage()); |
| | | |
| | | if (expectedResult != ResultCode.SUCCESS) |
| | | { |
| | | assertTrue(addOperation.getErrorMessage().toString(). |
| | | startsWith(errorMessage.toString()), |
| | | "Error MsgID of the task <" |
| | | + addOperation.getErrorMessage() |
| | | + "> equals <" |
| | | + errorMessage + ">"); |
| | | log("Create config task: <"+ errorMessage.getDescriptor().getId() |
| | | + addOperation.getErrorMessage() + ">"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | waitTaskState(taskEntry, TaskState.RUNNING, null); |
| | | } |
| | | |
| | | // Entry will be removed at the end of the test |
| | | entryList.addLast(taskEntry.getDN()); |
| | | |
| | | log("AddedTask/" + taskEntry.getDN()); |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | fail("Exception when adding task:"+ e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Wait a task to be completed and check the expected state and expected |
| | | * stats. |
| | | * @param taskEntry The task to process. |
| | |
| | | } |
| | | } |
| | | |
| | | private void waitTaskState(Entry taskEntry, TaskState expectedTaskState, |
| | | Message expectedMessage) |
| | | { |
| | | TaskState taskState = null; |
| | | try |
| | | { |
| | | |
| | | SearchFilter filter = |
| | | SearchFilter.createFilterFromString("(objectclass=*)"); |
| | | Entry resultEntry = null; |
| | | do |
| | | { |
| | | InternalSearchOperation searchOperation = |
| | | connection.processSearch(taskEntry.getDN(), |
| | | SearchScope.BASE_OBJECT, |
| | | filter); |
| | | try |
| | | { |
| | | resultEntry = searchOperation.getSearchEntries().getFirst(); |
| | | } catch (Exception e) |
| | | { |
| | | // FIXME How is this possible? Must be issue 858. |
| | | fail("Task entry was not returned from the search."); |
| | | continue; |
| | | } |
| | | |
| | | try |
| | | { |
| | | // Check that the task state is as expected. |
| | | AttributeType taskStateType = |
| | | DirectoryServer.getAttributeType(ATTR_TASK_STATE.toLowerCase()); |
| | | String stateString = |
| | | resultEntry.getAttributeValue(taskStateType, |
| | | DirectoryStringSyntax.DECODER); |
| | | taskState = TaskState.fromString(stateString); |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | fail("Exception"+ e.getMessage()+e.getStackTrace()); |
| | | } |
| | | |
| | | try |
| | | { |
| | | // Check that the left counter. |
| | | AttributeType taskStateType = |
| | | DirectoryServer.getAttributeType(ATTR_TASK_INITIALIZE_LEFT, true); |
| | | resultEntry.getAttributeValue(taskStateType, |
| | | DirectoryStringSyntax.DECODER); |
| | | |
| | | // Check that the total counter. |
| | | taskStateType = |
| | | DirectoryServer.getAttributeType(ATTR_TASK_INITIALIZE_DONE, true); |
| | | resultEntry.getAttributeValue(taskStateType, |
| | | DirectoryStringSyntax.DECODER); |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | fail("Exception"+ e.getMessage()+e.getStackTrace()); |
| | | } |
| | | |
| | | Thread.sleep(2000); |
| | | } |
| | | while ((taskState != expectedTaskState) && |
| | | (taskState != TaskState.STOPPED_BY_ERROR)); |
| | | |
| | | // Check that the task contains some log messages. |
| | | AttributeType logMessagesType = DirectoryServer.getAttributeType( |
| | | ATTR_TASK_LOG_MESSAGES.toLowerCase()); |
| | | ArrayList<String> logMessages = new ArrayList<String>(); |
| | | resultEntry.getAttributeValues(logMessagesType, |
| | | DirectoryStringSyntax.DECODER, |
| | | logMessages); |
| | | |
| | | if ((taskState != TaskState.COMPLETED_SUCCESSFULLY) |
| | | && (taskState != TaskState.RUNNING)) |
| | | { |
| | | if (logMessages.size() == 0) |
| | | { |
| | | fail("No log messages were written to the task entry on a failed task"); |
| | | } |
| | | else |
| | | { |
| | | if (expectedMessage != null) |
| | | { |
| | | log(logMessages.get(0)); |
| | | log(expectedMessage.toString()); |
| | | assertTrue(logMessages.get(0).indexOf( |
| | | expectedMessage.toString())>=0); |
| | | } |
| | | } |
| | | } |
| | | |
| | | assertEquals(taskState, expectedTaskState, "Task State:" + taskState + |
| | | " Expected task state:" + expectedTaskState); |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | fail("waitTaskState Exception:"+ e.getMessage() + " " + stackTraceToSingleLineString(e)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Add to the current DB the entries necessary to the test |
| | | */ |