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);
}
}
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();
}
}
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
}
}
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
}
}
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();
}
}
Aggregations