use of org.alfresco.repo.lock.mem.LockStore in project alfresco-repository by Alfresco.
the class LockServiceImplTest method testEphemeralLock.
public void testEphemeralLock() {
TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, this.authenticationService);
// Check that the node is not currently locked
assertEquals(LockStatus.NO_LOCK, lockService.getLockStatus(noAspectNode));
assertFalse(lockService.isLocked(noAspectNode));
// Check that there really is no lockable aspect
assertEquals(false, nodeService.hasAspect(noAspectNode, ContentModel.ASPECT_LOCKABLE));
// Lock the node
lockService.lock(noAspectNode, LockType.WRITE_LOCK, 86400, Lifetime.EPHEMERAL, "some extra data");
// Check additionalInfo has been stored
assertEquals("some extra data", lockService.getAdditionalInfo(noAspectNode));
// Check that we can retrieve LockState
LockState lockState = lockService.getLockState(noAspectNode);
assertEquals(noAspectNode, lockState.getNodeRef());
assertEquals(LockType.WRITE_LOCK, lockState.getLockType());
assertEquals(GOOD_USER_NAME, lockState.getOwner());
assertEquals(Lifetime.EPHEMERAL, lockState.getLifetime());
assertNotNull(lockState.getExpires());
assertEquals("some extra data", lockState.getAdditionalInfo());
// The node should be locked
assertEquals(LockStatus.LOCK_OWNER, lockService.getLockStatus(noAspectNode));
assertTrue(lockService.isLocked(noAspectNode));
// The node must still not have the lockable aspect applied
assertEquals(false, nodeService.hasAspect(noAspectNode, ContentModel.ASPECT_LOCKABLE));
// ...though the full node service should report that it is present
NodeService fullNodeService = (NodeService) applicationContext.getBean("nodeService");
assertEquals(true, fullNodeService.hasAspect(noAspectNode, ContentModel.ASPECT_LOCKABLE));
TestWithUserUtils.authenticateUser(BAD_USER_NAME, PWD, rootNodeRef, this.authenticationService);
assertEquals(LockStatus.LOCKED, lockService.getLockStatus(noAspectNode));
assertTrue(lockService.isLocked(noAspectNode));
// Test lock when already locked
try {
lockService.lock(noAspectNode, LockType.WRITE_LOCK);
fail("The user should not be able to lock the node since it is already locked by another user.");
} catch (UnableToAquireLockException exception) {
System.out.println(exception.getMessage());
}
TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, this.authenticationService);
assertEquals(LockStatus.LOCK_OWNER, lockService.getLockStatus(noAspectNode));
assertTrue(lockService.isLocked(noAspectNode));
// Test already locked by this user - relock
try {
lockService.lock(noAspectNode, LockType.WRITE_LOCK, 0, Lifetime.EPHEMERAL);
} catch (Exception exception) {
fail("No error should be thrown when a node is re-locked by the current lock owner.");
}
// The node should be locked
assertEquals(LockStatus.LOCK_OWNER, lockService.getLockStatus(noAspectNode));
assertTrue(lockService.isLocked(noAspectNode));
// If we remove the lock info directly from the memory store then the node should no longer
// be reported as locked (as it is an ephemeral lock)
LockStore lockStore = (LockStore) applicationContext.getBean("lockStore");
lockStore.clear();
// The node must no longer be reported as locked
assertEquals(LockStatus.NO_LOCK, lockService.getLockStatus(noAspectNode));
assertFalse(lockService.isLocked(noAspectNode));
// Lock again, ready to test unlocking an ephemeral lock.
try {
lockService.lock(noAspectNode, LockType.WRITE_LOCK, 0, Lifetime.EPHEMERAL);
} catch (Exception exception) {
fail("No error should be thrown when a node is re-locked by the current lock owner.");
}
assertEquals(LockStatus.LOCK_OWNER, lockService.getLockStatus(noAspectNode));
assertTrue(lockService.isLocked(noAspectNode));
lockService.unlock(noAspectNode);
assertEquals(LockStatus.NO_LOCK, lockService.getLockStatus(noAspectNode));
assertFalse(lockService.isLocked(noAspectNode));
}
use of org.alfresco.repo.lock.mem.LockStore in project alfresco-repository by Alfresco.
the class LockServiceImplTest method testGetLockStatus.
/**
* Test getLockStatus
*/
public void testGetLockStatus() {
TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, this.authenticationService);
// Check an unlocked node
LockStatus lockStatus1 = this.lockService.getLockStatus(this.parentNode);
assertEquals(LockStatus.NO_LOCK, lockStatus1);
this.lockService.lock(this.parentNode, LockType.WRITE_LOCK);
TestWithUserUtils.authenticateUser(BAD_USER_NAME, PWD, rootNodeRef, this.authenticationService);
// Check for locked status
LockStatus lockStatus2 = this.lockService.getLockStatus(this.parentNode);
assertEquals(LockStatus.LOCKED, lockStatus2);
// Check lockstore is not used for persistent locks
// Previously LockStore was doubling up as a cache - the change in requirements means a test
// is necessary to ensure the work has been implemented correctly (despite being an odd test)
LockStore lockStore = (LockStore) applicationContext.getBean("lockStore");
lockStore.clear();
LockState lockState = lockStore.get(parentNode);
// Nothing stored against node ref
assertNull(lockState);
lockService.getLockStatus(parentNode);
// In-memory store still empty - only used for ephemeral locks
lockState = lockStore.get(parentNode);
assertNull(lockState);
TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, this.authenticationService);
// Check for lock owner status
LockStatus lockStatus3 = this.lockService.getLockStatus(this.parentNode);
assertEquals(LockStatus.LOCK_OWNER, lockStatus3);
// Test with no apect node
this.lockService.getLockStatus(this.noAspectNode);
// Test method overload
LockStatus lockStatus4 = this.lockService.getLockStatus(this.parentNode);
assertEquals(LockStatus.LOCK_OWNER, lockStatus4);
}
Aggregations