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

Ludovic Poitou
30.06.2011 7fe759fe4f82098b60838626285d3ba3f2404ea3
opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
@@ -184,6 +184,11 @@
  private ExternalChangeLogSession eclSession;
  /**
   * A flag to know if the ECLControl has been requested.
   */
  private Boolean returnECLControl = false;
  /**
   * Creates a new operation that may be used to search for entries in a local
   * backend of the Directory Server.
   *
@@ -406,6 +411,7 @@
          ExternalChangelogRequestControl eclControl =
            getRequestControl(ExternalChangelogRequestControl.DECODER);
          MultiDomainServerState cookie = eclControl.getCookie();
          returnECLControl = true;
          if (cookie!=null)
          {
            startECLSessionMsg.setECLRequestType(
@@ -675,11 +681,16 @@
    final Entry entry = createEntryFromMsg(eclmsg);
    if (matchScopeAndFilter(entry))
    {
      List<Control> controls = new ArrayList<Control>(1);
      EntryChangelogNotificationControl clrc =
        new EntryChangelogNotificationControl(
            true, eclmsg.getCookie().toString());
      controls.add(clrc);
      List<Control> controls = null;
      if (returnECLControl)
      {
        controls = new ArrayList<Control>(1);
        EntryChangelogNotificationControl clrc =
            new EntryChangelogNotificationControl(
                true, eclmsg.getCookie().toString());
        controls.add(clrc);
      }
      return returnEntry(entry, controls);
    }
    return true;
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
@@ -262,6 +262,8 @@
    sleep(500); // Wait for draftCNDb to be purged also
    int ts = ECLCompatWriteReadAllOps(1);
    ECLCompatNoControl(1);
    // Write additional changes and read ECL from a provided draft change number
    ts = ECLCompatWriteReadAllOps(5);replicationServer.clearDb();
@@ -351,6 +353,10 @@
    // Test request from a provided change number - read 6
    ECLCompatReadFrom(6);
    // Test request from change number 1, just check that Cookie controls
    // are not returned with entries, when not requested.
    ECLCompatNoControl(1);
    // Test request from a provided change number interval - read 5-7
    ECLCompatReadFromTo(5,7);
@@ -2888,7 +2894,7 @@
          +  stackTraceToSingleLineString(e));
    }
  }
  private int ECLCompatWriteReadAllOps(int firstDraftChangeNumber)
  {
    String tn = "ECLCompatWriteReadAllOps/" + String.valueOf(firstDraftChangeNumber);
@@ -3232,6 +3238,68 @@
    debugInfo(tn, "Ending test with success");
  }
  // Process similar search as  but only check that there's no control
  // returned as part of the entry.
  private void ECLCompatNoControl(int firstDraftChangeNumber)
  {
    String tn = "ECLCompatNoControl/" + String.valueOf(firstDraftChangeNumber);
    debugInfo(tn, "Starting test\n\n");
    try
    {
      // Creates broker on o=test
      ReplicationBroker server01 = openReplicationSession(
          DN.decode(TEST_ROOT_DN_STRING),  1201,
          100, replicationServerPort,
          brokerSessionTimeout, true);
      String user1entryUUID = "11111111-1112-1113-1114-111111111115";
      LinkedHashSet<String> attributes = new LinkedHashSet<String>();
      attributes.add("+");
      attributes.add("*");
      String filter = "(changenumber="+firstDraftChangeNumber+")";
      debugInfo(tn, " Search: " + filter);
      InternalSearchOperation searchOp =
        connection.processSearch(
            ByteString.valueOf("cn=changelog"),
            SearchScope.WHOLE_SUBTREE,
            DereferencePolicy.NEVER_DEREF_ALIASES,
            0, // Size limit
            0, // Time limit
            false, // Types only
            LDAPFilter.decode(filter),
            attributes,
            NO_CONTROL,
            null);
      waitOpResult(searchOp, ResultCode.SUCCESS);
      LinkedList<SearchResultEntry> entries = searchOp.getSearchEntries();
      assertEquals(searchOp.getSearchEntries().size(), 1);
      if (entries != null)
      {
        int i=0;
        for (SearchResultEntry resultEntry : entries)
        {
          i++;
          // Just verify that no entry contains the ChangeLogCookie control
          List<Control> controls = resultEntry.getControls();
          assertTrue(controls.isEmpty());
        }
      }
      server01.stop();
    }
    catch(Exception e)
    {
      fail("Ending test " + tn + " with exception:\n"
          +  stackTraceToSingleLineString(e));
    }
    debugInfo(tn, "Ending test with success");
  }
  /**
   * Read the ECL in compat mode from firstDraftChangeNumber and to
   * lastDraftChangeNumber.