Search in sources :

Example 26 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class LockManagerTest method testGetLockTokens.

public void testGetLockTokens() throws RepositoryException, NotExecutableException {
    assertLockable(testNode);
    boolean sessionScoped = false;
    Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
    String ltoken = l.getLockToken();
    assertTrue("Creating open scoped lock must add token to the lock manager.", containsLockToken(lockMgr, ltoken));
    assertTrue("Creating open scoped lock must add token to the lock manager.", containsLockToken(superuser.getLockTokens(), ltoken));
}
Also used : Lock(javax.jcr.lock.Lock)

Example 27 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class LockManagerTest method testGetLockTokensAfterUnlock.

public void testGetLockTokensAfterUnlock() throws RepositoryException, NotExecutableException {
    assertLockable(testNode);
    boolean sessionScoped = false;
    Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
    String ltoken = l.getLockToken();
    lockMgr.unlock(testPath);
    assertFalse("Removing an open scoped lock must remove the token from the lock manager.", containsLockToken(lockMgr, ltoken));
    assertFalse("Removing an open scoped lock must remove the token from the lock manager.", containsLockToken(superuser.getLockTokens(), ltoken));
}
Also used : Lock(javax.jcr.lock.Lock)

Example 28 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class LockManagerTest method testGetLockTokensSessionScoped.

public void testGetLockTokensSessionScoped() throws RepositoryException, NotExecutableException {
    assertLockable(testNode);
    List<String> tokensBefore = Arrays.asList(lockMgr.getLockTokens());
    boolean sessionScoped = true;
    Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
    assertEquals("Creating a session scoped lock must not change the lock tokens.", tokensBefore, Arrays.asList(lockMgr.getLockTokens()));
    assertEquals("Creating a session scoped lock must not change the lock tokens.", tokensBefore, Arrays.asList(superuser.getLockTokens()));
}
Also used : Lock(javax.jcr.lock.Lock)

Example 29 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class LockManagerTest method testRemoveLockToken3.

public void testRemoveLockToken3() throws Exception {
    assertLockable(testNode);
    boolean sessionScoped = false;
    Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
    String ltoken = l.getLockToken();
    try {
        lockMgr.removeLockToken(ltoken);
        // the locked node.
        try {
            testNode.addNode(nodeName2, testNodeType);
            fail("Session must not be allowed to modify node");
        } catch (LockException e) {
        // expected
        }
    } finally {
        // make sure lock token is added even if test fail
        lockMgr.addLockToken(ltoken);
    }
}
Also used : LockException(javax.jcr.lock.LockException) Lock(javax.jcr.lock.Lock)

Example 30 with Lock

use of javax.jcr.lock.Lock in project jackrabbit by apache.

the class LockTest method testOpenScopedLocks.

/**
     * Test open-scoped locks
     */
public void testOpenScopedLocks() throws Exception {
    // add node
    Node n1 = testRootNode.addNode(nodeName1, testNodeType);
    ensureMixinType(n1, mixLockable);
    testRootNode.getSession().save();
    // create new session
    Session otherSuperuser = getHelper().getSuperuserSession();
    try {
        // get node created above
        Node n2 = (Node) otherSuperuser.getItem(n1.getPath());
        // lock node
        Lock lock = n2.lock(false, false);
        // transfer to standard session
        String lockToken = lock.getLockToken();
        otherSuperuser.removeLockToken(lockToken);
        superuser.addLockToken(lockToken);
    } finally {
        // log out
        otherSuperuser.logout();
    }
    // assert: node still locked
    assertTrue(n1.isLocked());
}
Also used : Node(javax.jcr.Node) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Aggregations

Lock (javax.jcr.lock.Lock)67 Node (javax.jcr.Node)41 Session (javax.jcr.Session)20 LockException (javax.jcr.lock.LockException)13 UserTransaction (javax.transaction.UserTransaction)12 RepositoryException (javax.jcr.RepositoryException)8 LockManager (javax.jcr.lock.LockManager)7 JcrActiveLock (org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)5 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)4 UserTransactionImpl (org.apache.jackrabbit.core.UserTransactionImpl)3 DavException (org.apache.jackrabbit.webdav.DavException)3 EventIterator (javax.jcr.observation.EventIterator)2 EventListener (javax.jcr.observation.EventListener)2 ObservationManager (javax.jcr.observation.ObservationManager)2 StaleItemStateException (org.apache.jackrabbit.core.state.StaleItemStateException)2 LockInfo (org.apache.jackrabbit.spi.LockInfo)2 SupportedLock (org.apache.jackrabbit.webdav.lock.SupportedLock)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1