| | |
| | | return found; |
| | | } |
| | | |
| | | /** |
| | | * 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 errorMessageID The expected error messageID when the expected |
| | | * result code is not SUCCESS |
| | | */ |
| | | private void addTask(Entry taskEntry, ResultCode expectedResult, |
| | | Message errorMessage) |
| | | { |
| | | try |
| | | { |
| | | debugInfo("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 + ">"); |
| | | debugInfo("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()); |
| | | |
| | | debugInfo("AddedTask/" + taskEntry.getDN()); |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | fail("Exception when adding task:"+ e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | 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()); |
| | | } |
| | | Thread.sleep(500); |
| | | } |
| | | 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) |
| | | { |
| | | debugInfo(logMessages.get(0)); |
| | | debugInfo(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 |
| | | */ |
| | | private void addTestEntriesToDB(String[] ldifEntries) |
| | | { |
| | | try |
| | | { |
| | | // Change config of DS to launch the total update task |
| | | InternalClientConnection connection = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | for (String ldifEntry : ldifEntries) |
| | | { |
| | | Entry entry = TestCaseUtils.entryFromLdifString(ldifEntry); |
| | | AddOperationBasis addOp = new AddOperationBasis( |
| | | connection, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | null, |
| | | entry.getDN(), |
| | | entry.getObjectClasses(), |
| | | entry.getUserAttributes(), |
| | | entry.getOperationalAttributes()); |
| | | addOp.setInternalOperation(true); |
| | | addOp.run(); |
| | | if (addOp.getResultCode() != ResultCode.SUCCESS) |
| | | { |
| | | debugInfo("addEntry: Failed" + addOp.getResultCode()); |
| | | } |
| | | // They will be removed at the end of the test |
| | | entryList.addLast(entry.getDN()); |
| | | } |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | fail("addEntries Exception:"+ e.getMessage() + " " + stackTraceToSingleLineString(e)); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | * Creates entries necessary to the test. |
| | | */ |
| | |
| | | broker3 = null; |
| | | |
| | | if (replServer1 != null) |
| | | replServer1.shutdown(); |
| | | replServer1.remove(); |
| | | if (replServer2 != null) |
| | | replServer2.shutdown(); |
| | | if (replServer2 != null) |
| | | replServer2.shutdown(); |
| | | replServer2.remove(); |
| | | if (replServer3 != null) |
| | | replServer3.remove(); |
| | | replServer1 = null; |
| | | replServer2 = null; |
| | | replServer3 = null; |