Open
Description
Greetings gentlemen,
we are facing problem with acquiring lock with 'shouldSkipBlockingWait' set to true;
Find reproducible test bellow.
To reproduce this manually, just kill process while owning lock, start another one and try to acquire it with options as in junit...
Is this bug or just bad usage ?
Version being used is 1.1.0
Thanks
@Test
void notExpectedBehaviour() throws Exception{
final long leaseDuration = 1_000;
final long heartBeatPeriod = 200;
final String partition = "super_key_LOCK";
AcquireLockOptions lockOptions = AcquireLockOptions
.builder(partition)
.withAcquireReleasedLocksConsistently(true)
.withShouldSkipBlockingWait(true)
.build();
AmazonDynamoDBLockClient lockClientOne = new AmazonDynamoDBLockClient(
AmazonDynamoDBLockClientOptions
.builder(amazonDynamoDB, "table")
.withPartitionKeyName(Constants.HASH_KEY)
.withTimeUnit(TimeUnit.MILLISECONDS)
.withLeaseDuration(leaseDuration)
.withHeartbeatPeriod(heartBeatPeriod)
.withCreateHeartbeatBackgroundThread(true)
.build());
LockItem lockItem = lockClientOne.acquireLock(lockOptions);
Assertions.assertNotNull(lockItem, "lock acquired");
// create new lock client which should not be able to acquire lock
AmazonDynamoDBLockClient lockClientTwo = new AmazonDynamoDBLockClient(
AmazonDynamoDBLockClientOptions
.builder(amazonDynamoDB, "table")
.withPartitionKeyName(Constants.HASH_KEY)
.withTimeUnit(TimeUnit.MILLISECONDS)
.withLeaseDuration(leaseDuration)
.withHeartbeatPeriod(heartBeatPeriod)
.withCreateHeartbeatBackgroundThread(true)
.build());
Thread.sleep(leaseDuration);
boolean wasThrown = false;
try {
lockClientTwo.acquireLock(lockOptions);
} catch (LockCurrentlyUnavailableException e) {
wasThrown = true;
}
Assertions.assertTrue(wasThrown, "exception - expected behavior");
// force shutdown
Field shuttingDown = lockClientOne.getClass().getDeclaredField("shuttingDown");
shuttingDown.setAccessible(true);
shuttingDown.set(lockClientOne, true);
// wait so item gets old
Thread.sleep(leaseDuration * 3L);
// we would expect that lock can be acquired as nobody is sending heartbeats - but this throws exception LockCurrentlyNotAvailable
lockItem = lockClientTwo.acquireLock(lockOptions);
}
Metadata
Metadata
Assignees
Labels
No labels