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.");
}
}
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) {
}
}
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;
}
}
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
}
}
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
}
}
Aggregations