示例#1
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
      }
    }
  }
示例#2
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.");
    }
  }
示例#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();
      }
    }
  }
示例#4
0
 protected void tearDown() throws Exception {
   // release the lock created during setup
   if (lockMgr != null && lockedNode != null && lockMgr.isLocked(lockedNode.getPath())) {
     try {
       lockMgr.unlock(lockedNode.getPath());
     } catch (RepositoryException e) {
       // ignore
     }
   }
   super.tearDown();
 }
示例#5
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());
  }
示例#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();
    }
  }
示例#7
0
 public void testHoldsLockNewChild() throws RepositoryException {
   Node newChild = lockedNode.addNode(nodeName3, testNodeType);
   assertFalse("Child node below a locked node must never be lock holder", newChild.holdsLock());
   assertFalse(
       "Child node below a locked node must never be lock holder",
       lockMgr.holdsLock(newChild.getPath()));
 }
示例#8
0
 public void testIsLockedChild() throws RepositoryException {
   assertEquals(
       "Child node must be locked according to isDeep flag.", isDeep(), childNode.isLocked());
   assertEquals(
       "Child node must be locked according to isDeep flag.",
       isDeep(),
       lockMgr.isLocked(childNode.getPath()));
 }
示例#9
0
 public void testIsLockedNewChild() throws RepositoryException {
   Node newChild = lockedNode.addNode(nodeName3, testNodeType);
   assertEquals(
       "New child node must be locked according to isDeep flag.", isDeep(), newChild.isLocked());
   assertEquals(
       "New child node must be locked according to isDeep flag.",
       isDeep(),
       lockMgr.isLocked(newChild.getPath()));
 }
示例#10
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
   }
 }
  /** 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();
      }
    }
  }
示例#12
0
  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());
  }
示例#13
0
 /**
  * Test {@link LockManager#unlock(String)} for a session that is not lock owner.
  *
  * @throws RepositoryException
  * @throws NotExecutableException
  */
 public void testUnlockByOtherSession() throws RepositoryException, NotExecutableException {
   Session otherSession = getHelper().getReadWriteSession();
   try {
     getLockManager(otherSession).unlock(lockedNode.getPath());
     fail("Another session must not be allowed to unlock.");
   } catch (LockException e) {
     // success
     // make sure the node is still locked and the lock properties are
     // still present.
     assertTrue(lockMgr.isLocked(lockedNode.getPath()));
     assertTrue(lockedNode.hasProperty(jcrlockIsDeep));
     assertTrue(lockedNode.hasProperty(jcrLockOwner));
   } finally {
     otherSession.logout();
   }
 }
  @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));
  }
示例#15
0
 /**
  * Test {@link LockManager#holdsLock(String)} and {@link javax.jcr.Node#holdsLock()}.
  *
  * @throws RepositoryException If an execption occurs.
  */
 public void testNodeHoldsLocked() throws RepositoryException {
   assertTrue("Node must hold lock after lock creation.", lockedNode.holdsLock());
   assertTrue("Node must hold lock after lock creation.", lockMgr.holdsLock(lockedNode.getPath()));
 }
示例#16
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);
 }
示例#17
0
 /**
  * Test {@link LockManager#isLocked(String)} and {@link javax.jcr.Node#isLocked()}.
  *
  * @throws RepositoryException If an execption occurs.
  */
 public void testNodeIsLocked() throws RepositoryException {
   assertTrue("Node must be locked after lock creation.", lockedNode.isLocked());
   assertTrue("Node must be locked after lock creation.", lockMgr.isLocked(lockedNode.getPath()));
 }
示例#18
0
 public void testHoldsLockChild() throws RepositoryException {
   assertFalse("Child node below a locked node must never be lock holder", childNode.holdsLock());
   assertFalse(
       "Child node below a locked node must never be lock holder",
       lockMgr.holdsLock(childNode.getPath()));
 }