AwsRepositoryLock implements RepositoryLock { public AwsRepositoryLock lock() throws IOException { try { Optional<LockItem> lockItemOptional = lockClient.tryAcquireLock(AcquireLockOptions.builder(lockName) .withTimeUnit(TimeUnit.SECONDS).withAdditionalTimeToWaitForLock(timeoutSec) .build()); if (lockItemOptional.isPresent()) { lockItem = lockItemOptional.get(); return this; } else { log.error("Can't acquire the lease in {}s.", timeoutSec); throw new IOException("Can't acquire the lease in " + timeoutSec + "s."); } } catch (InterruptedException e) { throw new IOException(e); } } AwsRepositoryLock(DynamoDBClient dynamoDBClient, String lockName);  AwsRepositoryLock(DynamoDBClient dynamoDBClient, String lockName, int timeoutSec); AwsRepositoryLock lock(); @Override void unlock();  }
@Test public void testFailingLock() throws IOException { new AwsRepositoryLock(dynamoDBClient, lockName, 0).lock(); try { new AwsRepositoryLock(dynamoDBClient, lockName, 0).lock(); fail("The second lock should fail."); } catch (IOException e) { } }