Fix DynamoDbLock.tryLock() for the real timeout

Since the contract of the `tryLock()` to wait as close to the provided
timeout as possible, then we should not wait for the `leasePeriod` as
minimum.
Also we should sleep in between attempts not more then provided timeout
This commit is contained in:
Artem Bilan
2018-06-28 12:43:35 -04:00
parent d192e17007
commit 662416cd7b

View File

@@ -466,10 +466,12 @@ public class DynamoDbLockRegistry implements ExpirableLockRegistry, Initializing
return false;
}
long timeToWaitForLock = System.currentTimeMillis() - start + TimeUnit.MILLISECONDS.convert(time, unit);
long refreshPeriod = System.currentTimeMillis() - start + TimeUnit.MILLISECONDS.convert(time, unit);
long timeToWaitForLock = refreshPeriod - DynamoDbLockRegistry.this.leaseDuration;
this.acquireLockOptionsBuilder
.withAdditionalTimeToWaitForLock(timeToWaitForLock)
.withRefreshPeriod(timeToWaitForLock);
.withRefreshPeriod(refreshPeriod);
boolean acquired = false;
try {