Search in sources :

Example 36 with LockException

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

the class LockManagerTest method testRemoveLockTokenTwice.

public void testRemoveLockTokenTwice() throws Exception {
    assertLockable(testNode);
    boolean sessionScoped = false;
    Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
    String ltoken = l.getLockToken();
    lockMgr.removeLockToken(ltoken);
    try {
        // remove token a second time
        lockMgr.removeLockToken(ltoken);
        fail("Removing a lock token twice must fail.");
    } catch (LockException e) {
    // success
    } 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 37 with LockException

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

the class LockManagerTest method testAddLockTokenToAnotherSession.

public void testAddLockTokenToAnotherSession() throws RepositoryException, NotExecutableException {
    assertLockable(testNode);
    boolean sessionScoped = false;
    Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
    String ltoken = l.getLockToken();
    Session other = getHelper().getReadWriteSession();
    try {
        LockManager otherLockMgr = getLockManager(other);
        assertFalse(containsLockToken(otherLockMgr, ltoken));
        try {
            otherLockMgr.addLockToken(ltoken);
            if (!openScopedLockMultiple) {
                fail("Adding token to another session must fail (see config property " + RepositoryStub.PROP_OPEN_SCOPED_LOCK_MULTIPLE + ".");
            }
        } catch (LockException e) {
            if (openScopedLockMultiple) {
                fail("Adding token to another session must not fail (see config property " + RepositoryStub.PROP_OPEN_SCOPED_LOCK_MULTIPLE + ".");
            }
        }
    } finally {
        other.logout();
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) LockException(javax.jcr.lock.LockException) Lock(javax.jcr.lock.Lock) Session(javax.jcr.Session)

Example 38 with LockException

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

the class DeepLockTest method testDeepLockAboveLockedChild.

public void testDeepLockAboveLockedChild() throws RepositoryException, NotExecutableException {
    Node parent = lockedNode.getParent();
    if (!parent.isNodeType(mixLockable)) {
        try {
            ensureMixinType(parent, mixLockable);
            parent.save();
        } catch (RepositoryException e) {
            throw new NotExecutableException();
        }
    }
    try {
        parent.lock(true, true);
        fail("Creating a deep lock on a parent of a locked node must fail.");
    } catch (LockException e) {
    // expected
    }
    try {
        lockMgr.lock(parent.getPath(), true, true, getTimeoutHint(), getLockOwner());
        fail("Creating a deep lock on a parent of a locked node must fail.");
    } catch (LockException e) {
    // expected
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 39 with LockException

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

the class LockTest method testRefreshNotLive.

/**
     * Test refresh
     */
public void testRefreshNotLive() throws Exception {
    // create new node
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    ensureMixinType(n, mixLockable);
    testRootNode.getSession().save();
    // lock node and get lock token
    Lock lock = n.lock(false, true);
    // assert: lock must be alive
    assertTrue("lock must be alive", lock.isLive());
    // unlock node
    n.unlock();
    // assert: lock must not be alive
    assertFalse("lock must not be alive", lock.isLive());
    // refresh
    try {
        lock.refresh();
        fail("Refresh on a lock that is not alive must fail");
    } catch (LockException e) {
    // success
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock)

Example 40 with LockException

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

the class LockTest method testNodeLocked.

/**
     * Test session scope: other session may not access nodes that are
     * locked.
     */
public void testNodeLocked() throws Exception {
    // create new node and lock it
    Node n1 = testRootNode.addNode(nodeName1, testNodeType);
    ensureMixinType(n1, mixLockable);
    testRootNode.getSession().save();
    // lock node
    Lock lock = n1.lock(false, true);
    // assert: isLive must return true
    assertTrue("Lock must be live", lock.isLive());
    // create new session
    Session otherSuperuser = getHelper().getSuperuserSession();
    try {
        // get same node
        Node n2 = (Node) otherSuperuser.getItem(n1.getPath());
        // assert: lock token must be null for other session
        assertNull("Lock token must be null for other session", n2.getLock().getLockToken());
        // assert: modifying same node in other session must fail
        try {
            n2.addNode(nodeName2, testNodeType);
            fail("modifying same node in other session must fail");
        } catch (LockException e) {
        // expected
        }
    } finally {
        otherSuperuser.logout();
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Lock(javax.jcr.lock.Lock) Session(javax.jcr.Session)

Aggregations

LockException (javax.jcr.lock.LockException)61 Node (javax.jcr.Node)33 Session (javax.jcr.Session)24 Lock (javax.jcr.lock.Lock)13 RepositoryException (javax.jcr.RepositoryException)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)7 LockManager (javax.jcr.lock.LockManager)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 RetentionManager (javax.jcr.retention.RetentionManager)4 SessionImpl (org.apache.jackrabbit.core.SessionImpl)4 Value (javax.jcr.Value)3 Path (org.apache.jackrabbit.spi.Path)3 IOException (java.io.IOException)2 InvalidItemStateException (javax.jcr.InvalidItemStateException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 Property (javax.jcr.Property)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2