Search in sources :

Example 1 with LockException

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

the class SerializationTest method doTestLockException.

// ----------------< locking exceptions tests >----------------------------
/**
     * Tests whether importing a tree respects locking.
     */
public void doTestLockException(boolean useWorkspace, boolean useHandler) throws Exception {
    exportRepository(SKIPBINARY, RECURSE);
    if (isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        //A LockException is thrown if a lock prevents the addition of the subtree.
        Node lNode = testRootNode.addNode(nodeName1);
        ensureMixinType(lNode, mixLockable);
        testRootNode.getSession().save();
        Lock lock = lNode.lock(true, true);
        //remove the token, so the lock is for me, too
        session.removeLockToken(lock.getLockToken());
        FileInputStream in = new FileInputStream(file);
        try {
            doImport(lNode.getPath(), in, useWorkspace, useHandler);
        } catch (LockException e) {
        // success
        } finally {
            try {
                in.close();
            } catch (IOException ignore) {
            }
        }
    } else {
        log.println("Locking not supported.");
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Lock(javax.jcr.lock.Lock)

Example 2 with LockException

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

the class VersionHistoryTest method testLockJcr2.

/**
     * Tests if <code>VersionHistory.lock(boolean, boolean)</code> throws a
     * {@link javax.jcr.lock.LockException}
     */
public void testLockJcr2() throws Exception {
    LockManager lockManager = vHistory.getSession().getWorkspace().getLockManager();
    String path = vHistory.getPath();
    try {
        lockManager.lock(path, true, true, 60, "");
        fail("VersionHistory should not be lockable: VersionHistory.lock(true,true) did not throw a LockException");
    } catch (LockException success) {
    }
    try {
        lockManager.lock(path, true, false, 60, "");
        fail("VersionHistory should not be lockable: VersionHistory.lock(true,false) did not throw a LockException");
    } catch (LockException success) {
    }
    try {
        lockManager.lock(path, false, true, 60, "");
        fail("VersionHistory should not be lockable: VersionHistory.lock(false,true) did not throw a LockException");
    } catch (LockException success) {
    }
    try {
        lockManager.lock(path, false, false, 60, "");
        fail("VersionHistory should not be lockable: VersionHistory.lock(false,false) did not throw a UnsupportedRepositoryOperationException");
    } catch (LockException success) {
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) LockException(javax.jcr.lock.LockException)

Example 3 with LockException

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

the class OpenScopedLockTest method testUnlockAfterTokenTransfer3.

/**
     * Test if a Lock created by one session gets properly invalidated
     * if the lock token has been transfered to another session, which
     * unlocks the Node.
     */
public void testUnlockAfterTokenTransfer3() throws Exception {
    String lockToken = lock.getLockToken();
    try {
        superuser.removeLockToken(lockToken);
        otherSession.addLockToken(lockToken);
        // otherSession is now lockHolder -> unlock must succeed.
        Node n2 = (Node) otherSession.getItem(lockedNode.getPath());
        n2.unlock();
        assertFalse("Lock has been release by another session.", lockedNode.holdsLock());
        assertFalse("Lock has been release by another session.", lock.isLive());
        assertFalse("Lock has been release by another session.", lock.getNode().isLocked());
        try {
            lockedNode.getLock();
            fail("Lock has been release by another session.");
        } catch (LockException e) {
        // ok
        }
    } catch (RepositoryException e) {
        // only in case of failure:
        // move lock token back in order to have lock removed properly
        // if test succeeds, moving back tokens is not necessary.
        otherSession.removeLockToken(lockToken);
        superuser.addLockToken(lockToken);
        // and rethrow
        throw e;
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 4 with LockException

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

the class AbstractLockTest method testUnlockByOtherSession2.

/**
     * 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.
     */
public void testUnlockByOtherSession2() throws RepositoryException {
    Node ln2 = (Node) otherSession.getItem(lockedNode.getPath());
    lockedNode.unlock();
    assertFalse("Node is not locked any more", ln2.isLocked());
    assertFalse("Node is not locked any more", ln2.holdsLock());
    try {
        ln2.getLock();
        fail("Node is not locked any more");
    } catch (LockException e) {
    // OK
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node)

Example 5 with LockException

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

the class DeepLockTest method testDeepLockAboveLockedChild.

public void testDeepLockAboveLockedChild() throws RepositoryException, NotExecutableException {
    try {
        Node parent = lockedNode.getParent();
        if (!parent.isNodeType(mixLockable)) {
            try {
                parent.addMixin(mixLockable);
                parent.save();
            } catch (RepositoryException e) {
                throw new NotExecutableException();
            }
        }
        parent.lock(true, isSessionScoped);
        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)

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