Exemplo n.º 1
0
  /** Test locks are released when session logs out */
  public void testImplicitUnlock() 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);

      Lock lock =
          getLockManager(other)
              .lock(
                  lockedNode.getPath(),
                  isDeep(),
                  isSessionScoped(),
                  getTimeoutHint(),
                  getLockOwner());
      other.logout();

      assertFalse(lock.isLive());
    } finally {
      if (other.isLive()) {
        other.logout();
      }
    }
  }
Exemplo n.º 2
0
  public void testGetLockOnNewChild() throws RepositoryException {
    Node newChild = lockedNode.addNode(nodeName3, testNodeType);
    if (isDeep()) {
      // get lock must succeed even if child is not lockable.
      Lock lock = newChild.getLock();
      assertNotNull(lock);
      assertTrue(
          "Lock.getNode() must return the lock holding node", lockedNode.isSame(lock.getNode()));

      Lock lock2 = lockMgr.getLock(newChild.getPath());
      assertNotNull(lock2);
      assertTrue(
          "Lock.getNode() must return the lock holding node", lockedNode.isSame(lock2.getNode()));
    } else {
      try {
        newChild.getLock();
        fail("Node.getLock() must throw if node is not locked.");
      } catch (LockException e) {
        // success
      }
      try {
        lockMgr.getLock(newChild.getPath());
        fail("LockManager.getLock(String) must throw if node is not locked.");
      } catch (LockException e) {
        // success
      }
    }
  }
Exemplo n.º 3
0
  public void testRemoveMixLockableFromLockedNode()
      throws RepositoryException, NotExecutableException {
    try {
      lockedNode.removeMixin(mixLockable);
      lockedNode.save();

      // the mixin got removed -> the lock should implicitely be released
      // as well in order not to have inconsistencies
      String msg = "Lock should have been released.";
      assertFalse(msg, lock.isLive());
      assertFalse(msg, lockedNode.isLocked());
      assertFalse(msg, lockMgr.isLocked(lockedNode.getPath()));

      assertFalse(msg, lockedNode.hasProperty(jcrLockOwner));
      assertFalse(msg, lockedNode.hasProperty(jcrlockIsDeep));

    } catch (ConstraintViolationException e) {
      // cannot remove the mixin -> ok
      // consequently the node must still be locked, the lock still live...
      String msg = "Lock must still be live.";
      assertTrue(msg, lock.isLive());
      assertTrue(msg, lockedNode.isLocked());
      assertTrue(msg, lockMgr.isLocked(lockedNode.getPath()));

      assertTrue(msg, lockedNode.hasProperty(jcrLockOwner));
      assertTrue(msg, lockedNode.hasProperty(jcrlockIsDeep));
    } finally {
      // ev. re-add the mixin in order to be able to unlock the node
      if (lockedNode.isLocked()) {
        ensureMixinType(lockedNode, mixLockable);
        lockedNode.save();
      }
    }
  }
Exemplo n.º 4
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.");
    }
  }
Exemplo n.º 5
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);
   }
 }
Exemplo n.º 6
0
  /**
   * Test {@link javax.jcr.lock.Lock#isLockOwningSession()}
   *
   * @throws RepositoryException If an execption occurs.
   */
  public void testIsLockOwningSession() throws RepositoryException {
    assertTrue("Session must be lock owner", lock.isLockOwningSession());
    assertTrue("Session must be lock owner", lockedNode.getLock().isLockOwningSession());
    assertTrue(
        "Session must be lock owner", lockMgr.getLock(lockedNode.getPath()).isLockOwningSession());

    Session otherSession = getHelper().getReadOnlySession();
    try {
      Lock lck = otherSession.getNode(lockedNode.getPath()).getLock();
      assertFalse("Session must not be lock owner", lck.isLockOwningSession());

      Lock lck2 = getLockManager(otherSession).getLock(lockedNode.getPath());
      assertFalse("Session must not be lock owner", lck2.isLockOwningSession());
    } finally {
      otherSession.logout();
    }

    Session otherAdmin = getHelper().getSuperuserSession();
    try {
      Lock lck = otherAdmin.getNode(lockedNode.getPath()).getLock();
      assertFalse(
          "Other Session for the same userID must not be lock owner", lck.isLockOwningSession());

      Lock lck2 = getLockManager(otherAdmin).getLock(lockedNode.getPath());
      assertFalse(
          "Other Session for the same userID must not be lock owner", lck2.isLockOwningSession());

    } finally {
      otherAdmin.logout();
    }
  }
Exemplo n.º 7
0
  /**
   * Test if Lock is properly released.
   *
   * @throws RepositoryException
   */
  public void testUnlock() throws RepositoryException {
    // release the lock
    lockMgr.unlock(lockedNode.getPath());

    // assert: lock must not be alive
    assertFalse("lock must not be alive", lock.isLive());
  }
Exemplo n.º 8
0
 /**
  * Test {@link javax.jcr.lock.Lock#refresh()} on a released lock.
  *
  * @throws Exception
  */
 public void testRefreshNotLive() throws Exception {
   // release the lock
   lockMgr.unlock(lockedNode.getPath());
   // refresh
   try {
     lock.refresh();
     fail("Refresh on a lock that is not alive must fail");
   } catch (LockException e) {
     // success
   }
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
 /** Test {@link javax.jcr.lock.Lock#isSessionScoped()} */
 public void testIsSessionScoped() {
   assertEquals(
       "Lock.isSessionScoped must be consistent with lock call.",
       isSessionScoped(),
       lock.isSessionScoped());
 }
Exemplo n.º 11
0
 /**
  * Test {@link javax.jcr.lock.Lock#getNode()}.
  *
  * @throws RepositoryException If an execption occurs.
  */
 public void testLockHoldingNode() throws RepositoryException {
   assertTrue("Lock.getNode() must be lockholding node.", lock.getNode().isSame(lockedNode));
 }
Exemplo n.º 12
0
 /**
  * Test {@link javax.jcr.lock.Lock#refresh()} on a released lock.
  *
  * @throws Exception
  */
 public void testRefresh() throws RepositoryException {
   // refresh must succeed
   lock.refresh();
 }
Exemplo n.º 13
0
 /** Test {@link javax.jcr.lock.Lock#isLive()}. */
 public void testIsLive() throws RepositoryException {
   assertTrue("Lock.isLive must be true.", lock.isLive());
 }
Exemplo n.º 14
0
 /** Test {@link javax.jcr.lock.Lock#isDeep()}. */
 public void testIsDeep() {
   assertEquals("Lock.isDeep must be consistent with lock call.", isDeep(), lock.isDeep());
 }