Perform update of single node in one remote call if possible
Refactor the testcase
@@ -2890,8 +2890,25 @@ public class DocumentNodeStoreTest {
@Ignore("OAK-5788")
@Test
public void commitRootSameAsModifiedPath() throws Exception{
- final AtomicInteger count = new AtomicInteger();
- DocumentStore ds = new MemoryDocumentStore(){
+ WriteCountingStore ws = new WriteCountingStore();
+
+ DocumentNodeStore ns = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(ws).getNodeStore();
+ NodeBuilder builder = ns.getRoot().builder();
+ builder.child("a").child("b");
+ merge(ns, builder);
+
+ ws.reset();
+
+ builder = ns.getRoot().builder();
+ builder.child("a").child("b").setProperty("foo", "bar");
+ merge(ns, builder);
+
+ assertEquals(1, ws.count);
+ }
+
+ private static class WriteCountingStore extends MemoryDocumentStore {
+ int count;
+
@Override
public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update) {
incrementCounter(collection);
@@ -2912,25 +2929,15 @@ public class DocumentNodeStoreTest {
return super.findAndUpdate(collection, update);
}
+ public void reset(){
+ count = 0;
+ }
+
private <T extends Document> void incrementCounter(Collection<T> collection) {
if (collection == Collection.NODES) {
- count.incrementAndGet();
+ count++;
}
}
- };
-
- DocumentNodeStore ns = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(ds).getNodeStore();
- NodeBuilder builder = ns.getRoot().builder();
- builder.child("a").child("b");
- merge(ns, builder);
-
- count.set(0);
-
- builder = ns.getRoot().builder();
- builder.child("a").child("b").setProperty("foo", "bar");
- merge(ns, builder);
-
- assertEquals(1, count.get());
}
private static class TestException extends RuntimeException {
