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(); } } }
@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)); }
/** 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."); } }
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())); }
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())); }
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(); }
/** * 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 {@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())); }