mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
17.50.2013 ab7ae2fd06d636915199bf9ca5804f2a0a41fa66
Fixed GenerationIdTest.generationIdTest(): test was failing precisely because the directory server's broker was not connected to a replication domain, hence it was impossible to add the changes to the changelogDB and then find them when querying the changelogDB.


GenerationIdTest.java:
Renamed assertConnectedToReplicationDomain() to waitConnectionToReplicationDomain().

LDAPReplicationDomain.java:
Removed uses of StringBuilder, relied on *Operation.toString() to do it for us.

ReplicationBroker.java:
Improved toString().

ReplicationTestCase.java:
Removed a wrong comment.
Used Assertions.assertThat().

ReplicationServerTest.java:
Removed a useless call to DirectoryServer.getSynchronizationProviders().
5 files modified
72 ■■■■■ changed files
opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java 19 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/service/ReplicationBroker.java 22 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java 26 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java 4 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java 1 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -1778,10 +1778,8 @@
         */
        if (fractionalFilterOperation(addOperation, false))
        {
          StringBuilder sb = new StringBuilder();
          addOperation.toString(sb);
          Message msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(
            getBaseDNString(), sb.toString());
            getBaseDNString(), addOperation.toString());
          return new SynchronizationProviderResult.StopProcessing(
            ResultCode.UNWILLING_TO_PERFORM, msg);
        }
@@ -1907,10 +1905,8 @@
         */
        if (fractionalFilterOperation(modifyDNOperation, false))
        {
          StringBuilder sb = new StringBuilder();
          modifyDNOperation.toString(sb);
          Message msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(
            getBaseDNString(), sb.toString());
            getBaseDNString(), modifyDNOperation.toString());
          return new SynchronizationProviderResult.StopProcessing(
            ResultCode.UNWILLING_TO_PERFORM, msg);
        }
@@ -2042,10 +2038,8 @@
          case FRACTIONAL_HAS_FRACTIONAL_FILTERED_ATTRIBUTES:
            // Some attributes not compliant with fractional configuration :
            // forbid the operation
            StringBuilder sb = new StringBuilder();
            modifyOperation.toString(sb);
            Message msg = NOTE_ERR_FRACTIONAL_FORBIDDEN_OPERATION.get(
              getBaseDNString(), sb.toString());
              getBaseDNString(), modifyOperation.toString());
            return new SynchronizationProviderResult.StopProcessing(
              ResultCode.UNWILLING_TO_PERFORM, msg);
        }
@@ -3811,10 +3805,10 @@
      }
      //  Release the shared lock on the backend.
      String lockFile = LockFileManager.getBackendLockFileName(backend);
      StringBuilder failureReason = new StringBuilder();
      try
      {
        String lockFile = LockFileManager.getBackendLockFileName(backend);
        StringBuilder failureReason = new StringBuilder();
        if (! LockFileManager.releaseLock(lockFile, failureReason))
        {
          Message message = WARN_LDIFEXPORT_CANNOT_UNLOCK_BACKEND.get(
@@ -3976,8 +3970,7 @@
   * @param backend The backend implied in the import.
   * @exception DirectoryException Thrown when an error occurs.
   */
  protected void closeBackendImport(Backend backend)
  throws DirectoryException
  protected void closeBackendImport(Backend backend) throws DirectoryException
  {
    String lockFile = LockFileManager.getBackendLockFileName(backend);
    StringBuilder failureReason = new StringBuilder();
opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
@@ -3042,9 +3042,23 @@
  @Override
  public String toString()
  {
    return getClass().getSimpleName() + " \"" + baseDN + " " + serverId + "\","
        + " groupId=" + groupId + ", genId=" + generationID
        + ", bestRS(serverId=" + rsServerId + ", serverUrl=" + rsServerUrl
        + ", groupId=" + rsGroupId + ")";
    final StringBuilder sb = new StringBuilder();
    sb.append(getClass().getSimpleName())
      .append(" \"").append(baseDN).append(" ").append(serverId).append("\",")
      .append(" groupId=").append(groupId)
      .append(", genId=").append(generationID)
      .append(", connected=").append(connected).append(", ");
    if (rsServerId == -1)
    {
      sb.append("no RS");
    }
    else
    {
      sb.append("bestRS(serverId=").append(rsServerId)
        .append(", serverUrl=").append(rsServerUrl)
        .append(", groupId=").append(rsGroupId)
        .append(")");
    }
    return sb.toString();
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java
@@ -660,7 +660,7 @@
      debugInfo(testCase + " ** TEST ** The part of the topology with the right gen ID should work well");
      // Now create a change that must be replicated
      assertConnectedToReplicationDomain();
      waitConnectionToReplicationDomain(baseDN, 1000);
      addTestEntriesToDB(createEntry(UUID.randomUUID()));
      // Verify that RS1 does contain the change related to this ADD.
@@ -766,7 +766,7 @@
          "Expecting that DS3 with old gen ID is in bad gen id from RS1");
      debugInfo("Add entries to DS1, update should not be sent to DS2 and DS3 that are in bad gen id");
      assertConnectedToReplicationDomain();
      waitConnectionToReplicationDomain(baseDN, 1000);
      addTestEntriesToDB(createEntry(UUID.randomUUID()));
      debugInfo("RS1 must have stored that update.");
@@ -861,11 +861,25 @@
    }
  }
  private void assertConnectedToReplicationDomain()
  /**
   * Waits for the connection from server1 to the replication domain to
   * establish itself up automagically.
   */
  private void waitConnectionToReplicationDomain(DN baseDN, int timeout)
  {
    long start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start <= timeout)
    {
      LDAPReplicationDomain domain = MultimasterReplication.findDomain(baseDN, null);
      if (domain != null && domain.isConnected())
      {
        break;
      }
    }
    assertTrue(MultimasterReplication.findDomain(baseDN, null).isConnected(),
        "The server should be connected to replication domain" + baseDN
            + " at this point");
        "After waiting " + (System.currentTimeMillis() - start)
            + " ms, server should have been connected to replication domain "
            + baseDN);
  }
  private Entry createSetGenerationIdTask(Long genId, String additionalAttribute) throws Exception
@@ -1065,7 +1079,7 @@
      assertEquals(readGenIdFromSuffixRootEntry(), -1,
          "genId attribute should not be retrievable since there are NO entry in the backend");
      assertConnectedToReplicationDomain();
      waitConnectionToReplicationDomain(baseDN, 1000);
      addTestEntriesToDB(updatedEntries);
      assertEquals(readGenIdFromSuffixRootEntry(), EMPTY_DN_GENID,
          "genId attribute should be retrievable since there IS one entry in the backend");
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
@@ -386,8 +386,7 @@
      "Found unexpected replication server config left");
    // Be sure that no replication server instance is left
    List<ReplicationServer> allRSInstances = ReplicationServer.getAllInstances();
    assertEquals(allRSInstances.size(), 0, "Some replication servers left: " + allRSInstances);
    Assertions.assertThat(ReplicationServer.getAllInstances()).isEmpty();
    // Check for config entries for replication domain
    assertNoConfigEntriesWithFilter("(objectclass=ds-cfg-replication-domain)",
@@ -834,7 +833,6 @@
   */
  protected void addTestEntriesToDB(String... ldifEntries) throws Exception
  {
    // Change config of DS to launch the total update task
    for (String ldifEntry : ldifEntries)
    {
      Entry entry = TestCaseUtils.entryFromLdifString(ldifEntry);
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
@@ -133,7 +133,6 @@
        "--set", "replication-port:" + replicationServerPort,
        "--set", "replication-server-id:71");
    DirectoryServer.getSynchronizationProviders();
    for (SynchronizationProvider<?> provider : DirectoryServer
        .getSynchronizationProviders()) {
      if (provider instanceof MultimasterReplication) {