From 03ba030dba4149fed59185f23611b35354ff2419 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Tue, 27 Feb 2024 12:49:17 +0100 Subject: [PATCH] OAK-10673: DocumentStore: add test for checking of removal on non-existing map entries (#1330) --- .../document/BasicDocumentStoreTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java index b21504df57b..c34ad7ff54e 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BasicDocumentStoreTest.java @@ -908,6 +908,66 @@ public void testCreatePartialFailure() { } } + // see OAK-10673 + @SuppressWarnings("unchecked") + @Test + public void testDeleteNonExistingMapEntry() { + String id = this.getClass().getName() + ".testDeleteNonExistingMapEntry-" + UUID.randomUUID(); + String propname = ":childOrder"; + + UpdateOp up = new UpdateOp(id, true); + assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(up))); + removeMe.add(id); + + long ts = System.currentTimeMillis(); + Revision r1 = new Revision(ts, 0, 1); + + // set initial value of :childOrder + UpdateOp op1 = new UpdateOp(id, false); + op1.setMapEntry(propname, r1, "foo"); + Document d0 = super.ds.findAndUpdate(Collection.NODES, op1); + assertNotNull(d0); + assertNull(d0.get(propname)); + + // set new value, remove previous one + Revision r2 = new Revision(ts, 2, 1); + UpdateOp op2 = new UpdateOp(id, false); + op2.removeMapEntry(propname, r1); + op2.setMapEntry(propname, r2, "bar"); + Document d1 = super.ds.findAndUpdate(Collection.NODES, op2); + + // check previous state, map should only contain entry for r1 -> "foo" + assertNotNull(d1); + assertNotNull(d1.get(propname)); + Map mresulting1 = (Map)d1.get(propname); + assertEquals(propname + " + map should contain one entry", 1, mresulting1.size()); + assertEquals("foo", mresulting1.get(r1)); + + // set new value, remove all previous + Revision r3 = new Revision(ts, 3, 1); + UpdateOp op3 = new UpdateOp(id, false); + // attempts to remove non-existing revision (r1) should not fail + op3.removeMapEntry(propname, r1); + op3.removeMapEntry(propname, r2); + op3.setMapEntry(propname, r3, "qux"); + Document d2 = super.ds.findAndUpdate(Collection.NODES, op3); + + // check previous state, map should only contain entry for r2 -> "bar" + assertNotNull(d2); + assertNotNull(d2.get(propname)); + Map mresulting2 = (Map)d2.get(propname); + assertEquals(propname + " + map should contain one entry", 1, mresulting2.size()); + assertEquals("bar", mresulting2.get(r2)); + + // get final state, map should only contain entry for r3 -> "qux" + Document d3 = ds.find(Collection.NODES, id, -1); + assertNotNull(d3); + assertNotNull(d3.get(propname)); + Map mresulting3 = (Map)d3.get(propname); + assertEquals(propname + " + map should contain one entry", 1, mresulting3.size()); + assertEquals("on " + super.dsname + ", got: " + mresulting3, "qux", mresulting3.get(r3)); + } + @Test public void testDeleteNonExisting() { String id = this.getClass().getName() + ".testDeleteNonExisting-" + UUID.randomUUID();