/** Test expiration of the lock */ public synchronized void testLockExpiration() throws RepositoryException, NotExecutableException { lockedNode.unlock(); long hint = 1; lock = lockMgr.lock(lockedNode.getPath(), isDeep(), isSessionScoped(), hint, null); // only test if timeout hint was respected. long remaining = lock.getSecondsRemaining(); if (remaining <= hint) { try { wait(remaining * 2000); // wait twice as long to be safe } catch (InterruptedException ignore) { } assertTrue( "A released lock must return a negative number of seconds", lock.getSecondsRemaining() < 0); String message = "If the timeout hint is respected the lock" + " must be automatically released."; assertFalse(message, lock.isLive()); assertFalse(message, lockedNode.isLocked()); assertFalse(message, lockMgr.isLocked(lockedNode.getPath())); assertFalse(message, lockedNode.hasProperty(Property.JCR_LOCK_IS_DEEP)); assertFalse(message, lockedNode.hasProperty(Property.JCR_LOCK_OWNER)); } else { throw new NotExecutableException("timeout hint was ignored."); } }
@Test public void ferrari_can_be_locked() throws RepositoryException { Node ferrari = session.getNode("/cars/ferrari"); LockManager lm = session.getWorkspace().getLockManager(); assertThat(lm.isLocked(ferrari.getPath()), is(false)); lm.lock(ferrari.getPath(), true, true, 60, session.getUserID()); assertThat(lm.isLocked(ferrari.getPath()), is(true)); lm.unlock(ferrari.getPath()); assertThat(lm.isLocked(ferrari.getPath()), is(false)); }
protected void setUp() throws Exception { // check for lock support before creating the session in the super.setup checkSupportedOption(Repository.OPTION_LOCKING_SUPPORTED); super.setUp(); lockedNode = testRootNode.addNode(nodeName1, testNodeType); ensureMixinType(lockedNode, mixLockable); childNode = lockedNode.addNode(nodeName2, testNodeType); testRootNode.save(); lockMgr = getLockManager(testRootNode.getSession()); lock = lockMgr.lock( lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(), getLockOwner()); }
/** Test locks are released when session logs out */ public void testImplicitUnlock2() throws RepositoryException, NotExecutableException { Session other = getHelper().getReadWriteSession(); try { Node testNode = (Node) other.getItem(testRootNode.getPath()); Node lockedNode = testNode.addNode(nodeName1, testNodeType); other.save(); assertLockable(lockedNode); LockManager lMgr = getLockManager(other); Lock lock = lMgr.lock( lockedNode.getPath(), isDeep(), isSessionScoped(), getTimeoutHint(), getLockOwner()); // access the locked noded added by another session testRootNode.refresh(false); Node n = (Node) superuser.getItem(lockedNode.getPath()); // remove lock implicit by logout lock-holding session other.logout(); // check if superuser session is properly informed about the unlock assertFalse(n.isLocked()); assertFalse(n.holdsLock()); try { n.getLock(); fail("Upon logout of the session a session-scoped lock must be gone."); } catch (LockException e) { // ok } } finally { if (other.isLive()) { other.logout(); } } }