From 491a78a88c413300af5593048826a7552b64af1d Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Mon, 30 May 2011 12:06:28 +0000
Subject: [PATCH] Fix issue OPENDJ-170 - External ChangeLog returns the Cookie Control even when not requested. Fix now check if the control is present in the search and returns it only if so. Tests have been added in unit-tests to verify this.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java | 70 ++++++++++++++++++++++++++++++++++
opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java | 21 ++++++++--
2 files changed, 85 insertions(+), 6 deletions(-)
diff --git a/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java b/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
index cf54c0b..c195824 100644
--- a/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
+++ b/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;
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
index 0a55d0b..6489aa5 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ExternalChangeLogTest.java
+++ b/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.
--
Gitblit v1.10.0