Ejemplo n.º 1
0
  /** 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.");
    }
  }
Ejemplo n.º 2
0
 /** 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);
   }
 }
Ejemplo n.º 3
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);
 }