jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1208402 - /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Wed, 30 Nov 2011 12:14:01 GMT
Author: mduerig
Date: Wed Nov 30 12:14:00 2011
New Revision: 1208402

URL: http://svn.apache.org/viewvc?rev=1208402&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
- add test case documenting write skew caused by the snapshot isolation model of the microkernel

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1208402&r1=1208401&r2=1208402&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Wed Nov 30 12:14:00 2011
@@ -78,6 +78,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 public class RepositoryTest {
     private static final String BASE_URL = "fs:target/repository-test/repository";
@@ -1443,6 +1444,61 @@ public class RepositoryTest {
         assertTrue(failedEvents.isEmpty());
     }
 
+    /**
+     * Trans-session isolation differs from Jackrabbit 2. Snapshot isolation can
+     * result in write skew as this test demonstrates: the check method enforces
+     * an application logic constraint which says that the sum of the properties
+     * p1 and p2 must not be negative. While session1 and session2 each enforce
+     * this constraint before saving, the constraint might not hold globally as
+     * can be seen in session3.
+     * 
+     * @see <a href="http://wiki.apache.org/jackrabbit/Transactional%20model%20of%20the%20Microkernel%20based%20Jackrabbit%20prototype#preview">
+     *     Transactional model of the Microkernel based Jackrabbit prototype</a>
+     */
+    @Test
+    public void testSessionIsolation() throws RepositoryException {
+        Repository repository = getRepository();
+
+        Session session0 = repository.login();
+        Node testNode = session0.getNode("/").addNode("testNode");
+        testNode.setProperty("p1", 1);
+        testNode.setProperty("p2", 1);
+        session0.save();
+        check(getSession());
+
+        Session session1 = repository.login();
+        Session session2 = repository.login();
+
+        session1.getNode("/testNode").setProperty("p1", -1);
+        check(session1);
+        session1.save();
+
+        session2.getNode("/testNode").setProperty("p2", -1);
+        check(session2);
+        session2.save();
+
+        Session session3 = repository.login();
+        try {
+            check(session3);  // Never throws on JR2, throws on JR3
+            fail();
+        }
+        catch (AssertionError e) {
+            // expected
+        }
+
+        session0.logout();
+        session1.logout();
+        session2.logout();
+        session3.logout();
+    }
+
+    private static void check(Session session) throws RepositoryException {
+        if (session.getNode("/testNode").getProperty("p1").getLong() +
+            session.getNode("/testNode").getProperty("p2").getLong() < 0) {
+              fail("p1 + p2 < 0");
+      }
+    }
+
     //------------------------------------------< private >---
 
     private void addProperty(Node parentNode, String name, Value value) throws RepositoryException,
IOException {



Mime
View raw message