mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ACS-2850: fix for intermittent failure on expiryLock test (#1083)
* ACS-2850: fix for intermittent failure on expiryLock test First issue was int rounding of '(expirationDate - new Date())/1000', which for really close values of timeout set and passed through lockInfo could be rounded down to 0. Replaced by a rounding up formula. Second issue was treating timeout == 0 as timeout.infinite. WebDav Infinite timeout has it's own marker "-1", in case of 0, lock was automatically turned into infinite time lock, while it should be an exception instead as creating a lock for 0s timeout is a programming error - the lock would immediatelly be expired upon creation (perhaps even with a date in the past, seeing as the expiryDate is filled). Changes made clarify the intent behind calling the method instead of obfuscating it by passing the int value through date operations
This commit is contained in:
committed by
GitHub
parent
cd8b3594aa
commit
f5c1e26a9b
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -321,7 +321,7 @@ public class LockServiceImpl implements LockService,
|
||||
public void lock(NodeRef nodeRef, LockType lockType)
|
||||
{
|
||||
// Lock with no expiration
|
||||
lock(nodeRef, lockType, 0);
|
||||
lock(nodeRef, lockType, TIMEOUT_INFINITY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,16 +371,8 @@ public class LockServiceImpl implements LockService,
|
||||
public void lock(NodeRef nodeRef, LockType lockType, int timeToExpire, Lifetime lifetime, String additionalInfo)
|
||||
{
|
||||
invokeBeforeLock(nodeRef, lockType);
|
||||
if (lifetime.equals(Lifetime.EPHEMERAL) && (timeToExpire > MAX_EPHEMERAL_LOCK_SECONDS))
|
||||
{
|
||||
throw new IllegalArgumentException("Attempt to create ephemeral lock for " +
|
||||
timeToExpire + " seconds - exceeds maximum allowed time.");
|
||||
}
|
||||
if (lifetime.equals(Lifetime.EPHEMERAL) && (timeToExpire > ephemeralExpiryThreshold))
|
||||
{
|
||||
lifetime = Lifetime.PERSISTENT;
|
||||
}
|
||||
|
||||
validateTimeToExpire(timeToExpire, lifetime);
|
||||
lifetime = switchLifetimeMode(timeToExpire, lifetime);
|
||||
|
||||
nodeRef = tenantService.getName(nodeRef);
|
||||
|
||||
@@ -442,6 +434,22 @@ public class LockServiceImpl implements LockService,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateTimeToExpire(int timeToExpire, Lifetime lifetime) {
|
||||
if (lifetime.equals(Lifetime.EPHEMERAL) && (timeToExpire > MAX_EPHEMERAL_LOCK_SECONDS))
|
||||
{
|
||||
throw new IllegalArgumentException("Attempt to create ephemeral lock for " +
|
||||
timeToExpire + " seconds - exceeds maximum allowed time.");
|
||||
}
|
||||
}
|
||||
|
||||
private Lifetime switchLifetimeMode(int timeToExpire, Lifetime lifetime) {
|
||||
if (lifetime.equals(Lifetime.EPHEMERAL) && (timeToExpire > ephemeralExpiryThreshold))
|
||||
{
|
||||
return Lifetime.PERSISTENT;
|
||||
}
|
||||
return lifetime;
|
||||
}
|
||||
|
||||
private void persistLockProps(NodeRef nodeRef, LockType lockType, Lifetime lifetime, String userName, Date expiryDate, String additionalInfo)
|
||||
{
|
||||
@@ -468,16 +476,16 @@ public class LockServiceImpl implements LockService,
|
||||
*/
|
||||
private Date makeExpiryDate(int timeToExpire)
|
||||
{
|
||||
// Set the expiry date
|
||||
Date expiryDate = null;
|
||||
if (timeToExpire > 0)
|
||||
{
|
||||
expiryDate = new Date();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(expiryDate);
|
||||
calendar.add(Calendar.SECOND, timeToExpire);
|
||||
expiryDate = calendar.getTime();
|
||||
boolean permanent = timeToExpire <= TIMEOUT_INFINITY;
|
||||
if (permanent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.SECOND, timeToExpire);
|
||||
Date expiryDate = calendar.getTime();
|
||||
|
||||
return expiryDate;
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -42,6 +42,8 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@AlfrescoPublicApi
|
||||
public interface LockService
|
||||
{
|
||||
int TIMEOUT_INFINITY = 0;
|
||||
|
||||
/**
|
||||
* Places a lock on a node.
|
||||
* <p>
|
||||
|
Reference in New Issue
Block a user