Author: mreutegg
Date: Mon Oct  5 08:44:58 2015
New Revision: 1706764

URL: http://svn.apache.org/viewvc?rev=1706764&view=rev
Log:
OAK-3455: Improve conflict exception message

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java?rev=1706764&r1=1706763&r2=1706764&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
 Mon Oct  5 08:44:58 2015
@@ -47,6 +47,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
 import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.COLLISIONS;
 import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.SPLIT_CANDIDATE_THRESHOLD;
+import static 
org.apache.jackrabbit.oak.plugins.document.util.Utils.isRevisionNewer;
 
 /**
  * A higher level object representing a commit.
@@ -533,11 +534,12 @@ public class Commit {
                 if (op.isNew() && isConflicting(before, op)) {
                     conflictMessage = "The node " +
                             op.getId() + " was already added in revision\n" +
-                            newestRev;
+                            formatConflictRevision(newestRev);
                 } else if (nodeStore.isRevisionNewer(newestRev, baseRevision)
                         && (op.isDelete() || isConflicting(before, op))) {
                     conflictMessage = "The node " +
-                            op.getId() + " was changed in revision\n" + 
newestRev +
+                            op.getId() + " was changed in revision\n" +
+                            formatConflictRevision(newestRev) +
                             ", which was applied after the base revision\n" +
                             baseRevision;
                 }
@@ -559,7 +561,8 @@ public class Commit {
                             } else {
                                 // fail immediately
                                 conflictMessage = "The node " +
-                                        op.getId() + " was changed in 
revision\n" + r +
+                                        op.getId() + " was changed in 
revision\n" +
+                                        formatConflictRevision(r) +
                                         ", which was applied after the base 
revision\n" +
                                         baseRevision;
                                 conflictRevision = r;
@@ -581,6 +584,14 @@ public class Commit {
         }
     }
 
+    private String formatConflictRevision(Revision r) {
+        if (isRevisionNewer(nodeStore, r, nodeStore.getHeadRevision())) {
+            return r + " (not yet visible)";
+        } else {
+            return r.toString();
+        }
+    }
+
     /**
      * Checks whether the given <code>UpdateOp</code> conflicts with the
      * existing content in <code>doc</code>. The check is done based on the

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1706764&r1=1706763&r2=1706764&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
 Mon Oct  5 08:44:58 2015
@@ -1593,6 +1593,31 @@ public class DocumentNodeStoreTest {
         assertEquals(3, 
b2.getChildNode("node").getProperty("p").getValue(Type.LONG).longValue());
     }
 
+    // OAK-3455
+    @Test
+    public void notYetVisibleExceptionMessage() throws Exception {
+        MemoryDocumentStore store = new MemoryDocumentStore();
+        DocumentNodeStore ns1 = builderProvider.newBuilder()
+                .setDocumentStore(store).setAsyncDelay(0).getNodeStore();
+        DocumentNodeStore ns2 = builderProvider.newBuilder()
+                .setDocumentStore(store).setAsyncDelay(0).getNodeStore();
+        ns2.setMaxBackOffMillis(0);
+
+        NodeBuilder b1 = ns1.getRoot().builder();
+        b1.child("test").setProperty("p", "v");
+        merge(ns1, b1);
+
+        NodeBuilder b2 = ns2.getRoot().builder();
+        b2.child("test").setProperty("q", "v");
+        try {
+            merge(ns2, b2);
+            fail("Must throw CommitFailedException");
+        } catch (CommitFailedException e) {
+            assertTrue(e.getMessage().contains("not yet visible"));
+        }
+
+    }
+
     /**
      * Utility class that eases creating single cluster id merge conflicts. 
The two methods:
      * <ul>


Reply via email to