Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

91057: Merged V4.2-BUG-FIX (4.2.5) to HEAD-BUG-FIX (5.0/Cloud)
      90986: MNT-11732: ephemeral locks have configurable threshold over which locks will be automatically made persistent instead.
      By setting the new property, administrators may control how ephemeral locks are created, for example:
      property alfresco.ephemeralLock.expiryThresh=30
      This will mean that when a LockService client requests that an ephemeral lock is created with a timeout of greater than 30 seconds, the lock will be created as a persistent lock instead (the ephemeral lifetime request is vetoed).
      By setting this property to -1, ALL locks will be created as persistent locks (giving the old, pre-ephemeral locking behaviour). By leaving this at the default (48 hours) the newer locking behaviour is completely unaffected, e.g. ephemeral locks may be created with up to 48 hour expiry time and over this limit an exception is thrown (and the lock is not created).
      By setting the value to something in between these settings it is possible to have quite a nice balance of behaviour. Using the example of 30 seconds, as above, will mean that using Share's "Edit Online" to edit a document in MS Word will result in a persistent lock (as MS Word requests approx 1 hour for its locks). After Solr has performed its next incremental index, then the Word document may be seen in the "Document's I'm Editing" filter in Share, since this is a persistent (in-DB) lock.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94765 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-01-31 11:11:51 +00:00
parent 11ee1f618d
commit 68f7ce770e
7 changed files with 106 additions and 19 deletions

View File

@@ -18,6 +18,8 @@
*/
package org.alfresco.repo.lock;
import static org.junit.Assert.assertNotEquals;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
@@ -257,17 +259,12 @@ public class LockServiceImplTest extends BaseSpringTest
this.lockService.lock(this.noAspectNode, LockType.WRITE_LOCK);
}
public void testPersistentLockDisallowsAdditionalInfo()
public void testPersistentLockMayStoreAdditionalInfo()
{
try
{
lockService.lock(noAspectNode, LockType.NODE_LOCK, 0, Lifetime.PERSISTENT, "additional info");
fail("additionalInfo must be null for persistent lock, expected IllegalArgumentException.");
}
catch (IllegalArgumentException e)
{
// Good, exception was thrown.
}
lockService.lock(noAspectNode, LockType.NODE_LOCK, 0, Lifetime.PERSISTENT, "additional info");
LockState lockState = lockService.getLockState(noAspectNode);
assertEquals("additional info", lockState.getAdditionalInfo());
}
public void testEphemeralLock()
@@ -818,6 +815,59 @@ public class LockServiceImplTest extends BaseSpringTest
assertEquals(LockStatus.LOCK_EXPIRED, this.lockService.getLockStatus(this.parentNode));
}
public void testEphemeralExpiryThreshold()
{
TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, this.authenticationService);
final int origThresh = ((LockServiceImpl)lockService).getEphemeralExpiryThreshold();
// Check the default situation is that the threshold does not apply.
assertEquals(LockServiceImpl.MAX_EPHEMERAL_LOCK_SECONDS, origThresh);
try
{
// Set the ephemeral expiry threshold to a much smaller value than the default
// so that it takes effect.
lockService.setEphemeralExpiryThreshold(300);
// Check for an expiry time that should be unaffected by the threshold.
checkLifetimeForExpiry(Lifetime.EPHEMERAL, 0, Lifetime.EPHEMERAL);
checkLifetimeForExpiry(Lifetime.EPHEMERAL, 150, Lifetime.EPHEMERAL);
// Check the largest allowed ephemeral expiry time.
checkLifetimeForExpiry(Lifetime.EPHEMERAL, 300, Lifetime.EPHEMERAL);
// When the expiry is greater than the threshold, then the lock should be
// applied as a persistent lock.
checkLifetimeForExpiry(Lifetime.PERSISTENT, 301, Lifetime.EPHEMERAL);
// Switch off ephemeral locks entirely
lockService.setEphemeralExpiryThreshold(-1);
// Always persistent...
checkLifetimeForExpiry(Lifetime.PERSISTENT, 0, Lifetime.EPHEMERAL);
checkLifetimeForExpiry(Lifetime.PERSISTENT, 150, Lifetime.EPHEMERAL);
checkLifetimeForExpiry(Lifetime.PERSISTENT, 300, Lifetime.EPHEMERAL);
checkLifetimeForExpiry(Lifetime.PERSISTENT, 301, Lifetime.EPHEMERAL);
}
finally
{
lockService.setEphemeralExpiryThreshold(origThresh);
}
}
private void checkLifetimeForExpiry(Lifetime expectedLifetime, int expirySecs, Lifetime requestedLifetime)
{
lockService.unlock(parentNode);
assertNotEquals(LockStatus.LOCKED ,lockService.getLockStatus(parentNode));
lockService.lock(parentNode, LockType.WRITE_LOCK, expirySecs, requestedLifetime);
LockState lock = lockService.getLockState(parentNode);
assertEquals(expectedLifetime, lock.getLifetime());
// Check that for any timeouts we test, a request for a persistent lock always yields a persistent lock.
lockService.unlock(parentNode);
assertNotEquals(LockStatus.LOCKED ,lockService.getLockStatus(parentNode));
lockService.lock(parentNode, LockType.WRITE_LOCK, expirySecs, Lifetime.PERSISTENT);
lock = lockService.getLockState(parentNode);
assertEquals(Lifetime.PERSISTENT, lock.getLifetime());
}
/**
* Unit test to validate the behaviour of creating children of locked nodes.
* No lock - can create children