/** 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 {@link javax.jcr.lock.Lock#getSecondsRemaining()} */ public void testGetSecondsRemaining() throws RepositoryException { if (lock.isLive()) { assertTrue("Seconds remaining must be a positive long.", lock.getSecondsRemaining() > 0); } else { assertTrue("Seconds remaining must be a negative long.", lock.getSecondsRemaining() < 0); } }
/** Test {@link javax.jcr.lock.Lock#getSecondsRemaining()} */ public void testGetSecondsRemainingAfterUnlock() throws RepositoryException { lockMgr.unlock(lockedNode.getPath()); assertTrue( "Lock has been released: seconds remaining must be a negative long.", lock.getSecondsRemaining() < 0); }