From c5944e80a5372760dc1b4b59edc6eca202b2861d Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Wed, 01 May 2013 14:23:11 +0000
Subject: [PATCH] Add two missing test cases
---
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 154 insertions(+), 1 deletions(-)
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java
index d2d9b4d..db751f0 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java
@@ -23,7 +23,7 @@
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2012 ForgeRock AS
+ * Portions Copyright 2011-2013 ForgeRock AS
*/
package org.opends.server.replication.plugin;
@@ -1809,6 +1809,159 @@
}
/**
+ * Test we can del an existing value and add a new one, and then replay
+ * a del of the same existing value and add of a different new one.
+ */
+ @Test()
+ public void replayDelAddDifferent() throws Exception
+ {
+ Entry entry = initializeEntry();
+
+ //
+ // Create description with values value1 and value2 and add
+ // this attribute to the entry.
+ //
+ AttributeBuilder builder = new AttributeBuilder(DESCRIPTION);
+ builder.add("value1");
+ builder.add("value2");
+
+ List<AttributeValue> duplicateValues = new LinkedList<AttributeValue>();
+ entry.addAttribute(builder.toAttribute(), duplicateValues);
+
+ // load historical from the entry
+ EntryHistorical hist = EntryHistorical.newInstanceFromEntry(entry);
+
+ /*
+ * simulate a delete of same value in the same operation done at time
+ * t1
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.DELETE, "value1", 1,
+ true);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:del:value1");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /*
+ * simulate an add of new value in the same operation done at time
+ * t1
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.ADD, "value3", 1,
+ true);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:add:value3");
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:del:value1");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /*
+ * simulate a delete of same value in the same operation done at time
+ * t2
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.DELETE, "value1", 2,
+ false);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:add:value3");
+ builder.add(DESCRIPTION + ":0000000000000002000000000000:del:value1");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /*
+ * simulate an add of new value in the same operation done at time
+ * t2
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.ADD, "value4", 2,
+ true);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:add:value3");
+ builder.add(DESCRIPTION + ":0000000000000002000000000000:del:value1");
+ builder.add(DESCRIPTION + ":0000000000000002000000000000:add:value4");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /* The entry should have no value */
+ List<Attribute> attrs = entry.getAttribute(DESCRIPTION);
+ builder = new AttributeBuilder(DESCRIPTION);
+ builder.add("value2");
+ builder.add("value3");
+ builder.add("value4");
+ assertEquals(attrs.get(0), builder.toAttribute());
+ }
+
+ /**
+ * Test we can del an existing value and add a new one, and then replay
+ * a del of another existing value and add of the same one.
+ */
+ @Test()
+ public void replayDelAddSame() throws Exception
+ {
+ Entry entry = initializeEntry();
+
+ //
+ // Create description with values value1 and value2 and add
+ // this attribute to the entry.
+ //
+ AttributeBuilder builder = new AttributeBuilder(DESCRIPTION);
+ builder.add("value1");
+ builder.add("value2");
+ builder.add("value3");
+
+ List<AttributeValue> duplicateValues = new LinkedList<AttributeValue>();
+ entry.addAttribute(builder.toAttribute(), duplicateValues);
+
+ // load historical from the entry
+ EntryHistorical hist = EntryHistorical.newInstanceFromEntry(entry);
+
+ /*
+ * simulate a delete of a value in the same operation done at time
+ * t1
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.DELETE, "value1", 1,
+ true);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:del:value1");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /*
+ * simulate an add of new value in the same operation done at time
+ * t1
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.ADD, "value4", 1,
+ true);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:add:value4");
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:del:value1");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /*
+ * simulate a delete of another value in the same operation done at time
+ * t2
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.DELETE, "value2", 2,
+ true);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:del:value1");
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:add:value4");
+ builder.add(DESCRIPTION + ":0000000000000002000000000000:del:value2");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /*
+ * simulate an add of already added value in the same operation done at time
+ * t2
+ */
+ testModify(entry, hist, DESCRIPTION, ModificationType.ADD, "value4", 2,
+ false);
+ builder = new AttributeBuilder(SYNCHIST);
+ builder.add(DESCRIPTION + ":0000000000000001000000000000:del:value1");
+ builder.add(DESCRIPTION + ":0000000000000002000000000000:del:value2");
+ builder.add(DESCRIPTION + ":0000000000000002000000000000:add:value4");
+ assertEquals(hist.encodeAndPurge(), builder.toAttribute());
+
+ /* The entry should have no value */
+ List<Attribute> attrs = entry.getAttribute(DESCRIPTION);
+ builder = new AttributeBuilder(DESCRIPTION);
+ builder.add("value3");
+ builder.add("value4");
+ assertEquals(attrs.get(0), builder.toAttribute());
+ }
+
+ /**
* Test that the replay of a single replicated modify operation,
* that contains a modify-add of a value followed by modify-delete
* of the attribute is handled properly.
--
Gitblit v1.10.0