jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r783278 - in /jackrabbit/trunk: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/ jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/
Date Wed, 10 Jun 2009 10:08:19 GMT
Author: angela
Date: Wed Jun 10 10:08:17 2009
New Revision: 783278

URL: http://svn.apache.org/viewvc?rev=783278&view=rev
Log:
JCR-1874: Move generic tests from jcr2spi to jackrabbit-jcr-tests (work in progress)

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/SessionScopedLockTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/SessionScopedLockTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java?rev=783278&r1=783277&r2=783278&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/AbstractLockTest.java
Wed Jun 10 10:08:17 2009
@@ -75,6 +75,13 @@
     protected abstract boolean isSessionScoped();
     protected abstract boolean isDeep();
 
+    protected void assertLockable(Node n) throws RepositoryException {
+        if (!n.isNodeType(mixLockable)) {
+            n.addMixin(mixLockable);
+            n.getSession().save();
+        }
+    }
+
     protected long getTimeoutHint() throws RepositoryException {
         String timoutStr = getProperty(RepositoryStub.PROP_LOCK_TIMEOUT);
         long hint = Long.MAX_VALUE;
@@ -96,7 +103,7 @@
         return ownerStr;
     }
 
-    private static LockManager getLockManager(Session session) throws RepositoryException
{
+    protected static LockManager getLockManager(Session session) throws RepositoryException
{
         return session.getWorkspace().getLockManager();
     }
 
@@ -108,6 +115,42 @@
     }
 
     /**
+     * Test {@link javax.jcr.lock.Lock#isLive()}.
+     */
+    public void testIsLive() throws RepositoryException {
+        assertTrue("Lock.isLive must be true.", lock.isLive());
+    }
+
+    /**
+     * Test {@link javax.jcr.lock.Lock#refresh()} on a released lock.
+     *
+     * @throws Exception
+     */
+    public void testRefresh() throws RepositoryException {
+        // refresh must succeed
+        lock.refresh();
+    }
+
+    // TODO: test if timeout gets reset upon Lock.refresh()
+    
+    /**
+     * Test {@link javax.jcr.lock.Lock#refresh()} on a released lock.
+     *
+     * @throws Exception
+     */
+    public void testRefreshNotLive() throws Exception {
+        // release the lock
+        lockMgr.unlock(lockedNode.getPath());
+        // refresh
+        try {
+            lock.refresh();
+            fail("Refresh on a lock that is not alive must fail");
+        } catch (LockException e) {
+            // success
+        }
+    }
+
+    /**
      * Test {@link javax.jcr.lock.Lock#getNode()}.
      *
      * @throws RepositoryException If an execption occurs.
@@ -135,7 +178,23 @@
         assertTrue("Node must hold lock after lock creation.", lockedNode.holdsLock());
         assertTrue("Node must hold lock after lock creation.", lockMgr.holdsLock(lockedNode.getPath()));
     }
-    
+
+
+    /**
+     * A locked node must also be locked if accessed by some other session.
+     */
+    public void testLockVisibility() throws RepositoryException {
+        Session otherSession = helper.getReadWriteSession();
+        try {
+            Node ln = (Node) otherSession.getItem(lockedNode.getPath());
+            assertTrue("Locked node must also be locked for another session", ln.isLocked());
+            assertTrue("Locked node must also be locked for another session", ln.holdsLock());
+            assertTrue("Locked node must also be locked for another session", getLockManager(otherSession).holdsLock(ln.getPath()));
+        } finally {
+            otherSession.logout();
+        }
+    }
+
     /**
      * Test {@link javax.jcr.lock.Lock#isSessionScoped()}
      */
@@ -234,6 +293,20 @@
             obsMgr.removeEventListener(listener);
         }
     }
+
+    /**
+     * Test if Lock is properly released.
+     * 
+     * @throws RepositoryException
+     */
+    public void testUnlock() throws RepositoryException {
+        // release the lock
+        lockMgr.unlock(lockedNode.getPath());
+        
+        // assert: lock must not be alive
+        assertFalse("lock must not be alive", lock.isLive());
+    }
+
     /**
      * Test {@link LockManager#unlock(String)} for a session that is not
      * lock owner.

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/SessionScopedLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/SessionScopedLockTest.java?rev=783278&r1=783277&r2=783278&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/SessionScopedLockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/lock/SessionScopedLockTest.java
Wed Jun 10 10:08:17 2009
@@ -19,6 +19,13 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+import javax.jcr.lock.LockManager;
+
 /** <code>SessionScopedLockTest</code>... */
 public class SessionScopedLockTest extends AbstractLockTest {
 
@@ -39,4 +46,65 @@
     public void testGetLockToken() {
         assertNull("A session scoped lock may never expose the token.", lock.getLockToken());
     }
+
+    /**
+     * Test locks are released when session logs out
+     */
+    public void testImplicitUnlock() throws RepositoryException {
+        Session other = helper.getReadWriteSession();
+        try {
+            Node testNode = (Node) other.getItem(testRootNode.getPath());
+            Node lockedNode = testNode.addNode(nodeName1, testNodeType);
+            other.save();
+
+            assertLockable(lockedNode);
+
+            Lock lock = getLockManager(other).lock(lockedNode.getPath(), isDeep(), isSessionScoped(),
getTimeoutHint(), getLockOwner());
+            other.logout();
+
+            assertFalse(lock.isLive());
+        } finally {
+            if (other.isLive()) {
+                other.logout();
+            }
+        }
+    }
+
+    /**
+     * Test locks are released when session logs out
+     */
+    public void testImplicitUnlock2() throws RepositoryException {
+        Session other = helper.getReadWriteSession();
+        try {
+            Node testNode = (Node) other.getItem(testRootNode.getPath());
+            Node lockedNode = testNode.addNode(nodeName1, testNodeType);
+            other.save();
+
+            assertLockable(lockedNode);
+
+            LockManager lMgr = getLockManager(other);
+            Lock lock = lMgr.lock(lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(),
getLockOwner());
+
+            // access the locked noded added by another session
+            testRootNode.refresh(false);
+            Node n = (Node) superuser.getItem(lockedNode.getPath());
+
+            // remove lock implicit by logout lock-holding session
+            other.logout();
+
+            // check if superuser session is properly informed about the unlock
+            assertFalse(n.isLocked());
+            assertFalse(n.holdsLock());
+            try {
+                n.getLock();
+                fail("Upon logout of the session a session-scoped lock must be gone.");
+            } catch (LockException e) {
+                // ok
+            }
+        } finally {
+            if (other.isLive()) {
+                other.logout();
+            }
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java?rev=783278&r1=783277&r2=783278&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java
Wed Jun 10 10:08:17 2009
@@ -25,11 +25,8 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
 import javax.jcr.Repository;
-import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
-import java.util.List;
-import java.util.Arrays;
 
 /**
  * <code>AbstractLockTest</code>...
@@ -104,53 +101,6 @@
     }
 
     /**
-     * Test Lock.isDeep()
-     */
-    public void testNotIsDeep() throws RepositoryException {
-        assertFalse("Lock.isDeep() must be false if the lock has not been set as not deep",
lock.isDeep());
-    }
-
-    /**
-     * Test Lock.isSessionScoped()
-     */
-    public void testIsSessionScoped() throws RepositoryException {
-        if (isSessionScoped()) {
-            assertTrue("Lock.isSessionScoped() must be true.", lock.isSessionScoped());
-        } else {
-            assertFalse("Lock.isSessionScoped() must be false. ", lock.isSessionScoped());
-        }
-    }
-
-    public void testLockIsLive() throws RepositoryException {
-        // assert: lock must be alive
-        assertTrue("lock must be alive", lock.isLive());
-    }
-
-    public void testRefresh() throws RepositoryException {
-        // assert: refresh must succeed
-        lock.refresh();
-    }
-
-    public void testUnlock() throws RepositoryException {
-        // unlock node
-        lockedNode.unlock();
-        // assert: lock must not be alive
-        assertFalse("lock must not be alive", lock.isLive());
-    }
-
-    public void testRefreshNotLive() throws Exception {
-        // unlock node
-        lockedNode.unlock();
-        // refresh
-        try {
-            lock.refresh();
-            fail("Refresh on a lock that is not alive must fail");
-        } catch (LockException e) {
-            // success
-        }
-    }
-
-    /**
      * Tests if a locked, checked-in node can be unlocked
      */
     public void testCheckedInUnlock() throws Exception {
@@ -275,15 +225,6 @@
     }
 
     /**
-     * A locked node must also be locked if accessed by some other session.
-     */
-    public void testLockVisibility() throws RepositoryException {
-        Node ln2 = (Node) otherSession.getItem(lockedNode.getPath());
-        assertTrue("Locked node must also be locked for another session", ln2.isLocked());
-        assertTrue("Locked node must also be locked for another session", ln2.holdsLock());
-    }
-
-    /**
      * If a locked nodes is unlocked again, any Lock instance retrieved by
      * another session must change the lock-status. Similarly, the previously
      * locked node must not be marked locked any more.
@@ -325,43 +266,4 @@
         n.remove();
         otherSession.save();
     }
-
-    public void testRemoveMixLockableFromLockedNode() throws RepositoryException {
-        try {
-            lockedNode.removeMixin(mixLockable);
-            lockedNode.save();
-
-            // the mixin got removed -> the lock should implicitely be released
-            // as well in order not to have inconsistencies
-            String msg = "Lock should have been released.";
-            assertFalse(msg, lock.isLive());
-            assertFalse(msg, lockedNode.isLocked());
-            if (!isSessionScoped()) {
-                List tokens = Arrays.asList(superuser.getLockTokens());
-                assertFalse(msg, tokens.contains(lock.getLockToken()));
-            }
-
-            assertFalse(msg, lockedNode.hasProperty(jcrLockOwner));
-            assertFalse(msg, lockedNode.hasProperty(jcrlockIsDeep));
-
-        } catch (ConstraintViolationException e) {
-            // cannot remove the mixin -> ok
-            // consequently the node must still be locked, the lock still live...
-            String msg = "Lock must still be live.";
-            assertTrue(msg, lock.isLive());
-            assertTrue(msg, lockedNode.isLocked());
-            if (!isSessionScoped()) {
-                List tokens = Arrays.asList(superuser.getLockTokens());
-                assertTrue(tokens.contains(lock.getLockToken()));
-            }
-            assertTrue(msg, lockedNode.hasProperty(jcrLockOwner));
-            assertTrue(msg, lockedNode.hasProperty(jcrlockIsDeep));
-        } finally {
-            // ev. re-add the mixin in order to be able to unlock the node
-            if (lockedNode.isLocked() && !lockedNode.isNodeType(mixLockable)) {
-                lockedNode.addMixin(mixLockable);
-                lockedNode.save();
-            }
-        }
-    }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/SessionScopedLockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/SessionScopedLockTest.java?rev=783278&r1=783277&r2=783278&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/SessionScopedLockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/lock/SessionScopedLockTest.java
Wed Jun 10 10:08:17 2009
@@ -19,11 +19,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.lock.LockException;
-import javax.jcr.lock.Lock;
-
 /**
  * <code>SessionScopedLockTest</code>...
  */
@@ -34,48 +29,4 @@
     boolean isSessionScoped() {
         return true;
     }
-
-    /**
-     * Test locks are released when session logs out
-     */
-    public void testLockNotLiveAfterLogout() throws RepositoryException {
-        Node testRoot2 = (Node) otherSession.getItem(testRootNode.getPath());
-
-        Node lockedNode2 = testRoot2.addNode(nodeName2, testNodeType);
-        lockedNode2.addMixin(mixLockable);
-        testRoot2.save();
-
-        Lock lock2 = lockedNode2.lock(false, isSessionScoped());
-        otherSession.logout();
-
-        assertFalse(lock2.isLive());
-    }
-
-    /**
-     * Test locks are released when session logs out
-     */
-    public void testNotLockedAfterLogout() throws RepositoryException {
-        Node testRoot2 = (Node) otherSession.getItem(testRootNode.getPath());
-
-        Node lockedNode2 = testRoot2.addNode(nodeName2, testNodeType);
-        lockedNode2.addMixin(mixLockable);
-        testRoot2.save();
-
-        // force reloading of the testroot in order to be aware of the
-        // locked noded added by another session
-        testRootNode.refresh(false);
-        Node n2 = (Node) superuser.getItem(lockedNode2.getPath());
-
-        // remove lock implicit by logout lock-holding session
-        otherSession.logout();
-
-        assertFalse(n2.isLocked());
-        assertFalse(n2.holdsLock());
-        try {
-            n2.getLock();
-            fail("Upon logout of the session a session-scoped lock must be gone.");
-        } catch (LockException e) {
-            // ok
-        }
-    }
 }
\ No newline at end of file



Mime
View raw message