@Test public void testRenewLeaseTimesOut() throws Exception { setupUpdateItemTest(); verifyCancel(mockUpdateFuture, () ->leaseRefresher.renewLease(lease)); }
@Override public boolean renewLease(@NonNull final Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { log.debug("Renewing lease with key {}", lease.leaseKey()); UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease)) .expected(serializer.getDynamoLeaseCounterExpectation(lease)) .attributeUpdates(serializer.getDynamoLeaseCounterUpdate(lease)).build(); final AWSExceptionManager exceptionManager = createExceptionManager(); exceptionManager.add(ConditionalCheckFailedException.class, t -> t); try { try { FutureUtils.resolveOrCancelFuture(dynamoDBClient.updateItem(request), dynamoDbRequestTimeout); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { throw new DependencyException(e); } } catch (ConditionalCheckFailedException e) { log.debug("Lease renewal failed for lease with key {} because the lease counter was not {}", lease.leaseKey(), lease.leaseCounter()); String expectedOwner = lease.leaseOwner(); Long expectedCounter = lease.leaseCounter() + 1; final Lease updatedLease = getLease(lease.leaseKey()); if (updatedLease == null || !expectedOwner.equals(updatedLease.leaseOwner()) || !expectedCounter.equals(updatedLease.leaseCounter())) { return false; } log.info("Detected spurious renewal failure for lease with key {}, but recovered", lease.leaseKey()); } catch (DynamoDbException | TimeoutException e) { throw new DependencyException(e); } lease.leaseCounter(lease.leaseCounter() + 1); return true; }
DynamoDBLeaseRefresher implements LeaseRefresher { @Override public boolean renewLease(@NonNull final Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { log.debug("Renewing lease with key {}", lease.leaseKey()); UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease)) .expected(serializer.getDynamoLeaseCounterExpectation(lease)) .attributeUpdates(serializer.getDynamoLeaseCounterUpdate(lease)).build(); final AWSExceptionManager exceptionManager = createExceptionManager(); exceptionManager.add(ConditionalCheckFailedException.class, t -> t); try { try { FutureUtils.resolveOrCancelFuture(dynamoDBClient.updateItem(request), dynamoDbRequestTimeout); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { throw new DependencyException(e); } } catch (ConditionalCheckFailedException e) { log.debug("Lease renewal failed for lease with key {} because the lease counter was not {}", lease.leaseKey(), lease.leaseCounter()); String expectedOwner = lease.leaseOwner(); Long expectedCounter = lease.leaseCounter() + 1; final Lease updatedLease = getLease(lease.leaseKey()); if (updatedLease == null || !expectedOwner.equals(updatedLease.leaseOwner()) || !expectedCounter.equals(updatedLease.leaseCounter())) { return false; } log.info("Detected spurious renewal failure for lease with key {}, but recovered", lease.leaseKey()); } catch (DynamoDbException | TimeoutException e) { throw new DependencyException(e); } lease.leaseCounter(lease.leaseCounter() + 1); return true; } }
DynamoDBLeaseRefresher implements LeaseRefresher { @Override public boolean renewLease(@NonNull final Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { log.debug("Renewing lease with key {}", lease.leaseKey()); UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease)) .expected(serializer.getDynamoLeaseCounterExpectation(lease)) .attributeUpdates(serializer.getDynamoLeaseCounterUpdate(lease)).build(); final AWSExceptionManager exceptionManager = createExceptionManager(); exceptionManager.add(ConditionalCheckFailedException.class, t -> t); try { try { FutureUtils.resolveOrCancelFuture(dynamoDBClient.updateItem(request), dynamoDbRequestTimeout); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { throw new DependencyException(e); } } catch (ConditionalCheckFailedException e) { log.debug("Lease renewal failed for lease with key {} because the lease counter was not {}", lease.leaseKey(), lease.leaseCounter()); String expectedOwner = lease.leaseOwner(); Long expectedCounter = lease.leaseCounter() + 1; final Lease updatedLease = getLease(lease.leaseKey()); if (updatedLease == null || !expectedOwner.equals(updatedLease.leaseOwner()) || !expectedCounter.equals(updatedLease.leaseCounter())) { return false; } log.info("Detected spurious renewal failure for lease with key {}, but recovered", lease.leaseKey()); } catch (DynamoDbException | TimeoutException e) { throw new DependencyException(e); } lease.leaseCounter(lease.leaseCounter() + 1); return true; } @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
            final LeaseSerializer serializer, final boolean consistentReads); @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback); @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout);  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
                                  final BillingMode billingMode); }
DynamoDBLeaseRefresher implements LeaseRefresher { @Override public boolean renewLease(@NonNull final Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { log.debug("Renewing lease with key {}", lease.leaseKey()); UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease)) .expected(serializer.getDynamoLeaseCounterExpectation(lease)) .attributeUpdates(serializer.getDynamoLeaseCounterUpdate(lease)).build(); final AWSExceptionManager exceptionManager = createExceptionManager(); exceptionManager.add(ConditionalCheckFailedException.class, t -> t); try { try { FutureUtils.resolveOrCancelFuture(dynamoDBClient.updateItem(request), dynamoDbRequestTimeout); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { throw new DependencyException(e); } } catch (ConditionalCheckFailedException e) { log.debug("Lease renewal failed for lease with key {} because the lease counter was not {}", lease.leaseKey(), lease.leaseCounter()); String expectedOwner = lease.leaseOwner(); Long expectedCounter = lease.leaseCounter() + 1; final Lease updatedLease = getLease(lease.leaseKey()); if (updatedLease == null || !expectedOwner.equals(updatedLease.leaseOwner()) || !expectedCounter.equals(updatedLease.leaseCounter())) { return false; } log.info("Detected spurious renewal failure for lease with key {}, but recovered", lease.leaseKey()); } catch (DynamoDbException | TimeoutException e) { throw new DependencyException(e); } lease.leaseCounter(lease.leaseCounter() + 1); return true; } @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
            final LeaseSerializer serializer, final boolean consistentReads); @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback); @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout);  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
                                  final BillingMode billingMode); @Override boolean createLeaseTableIfNotExists(@NonNull final Long readCapacity, @NonNull final Long writeCapacity); @Override boolean leaseTableExists(); @Override boolean waitUntilLeaseTableExists(long secondsBetweenPolls, long timeoutSeconds); @Override List<Lease> listLeasesForStream(StreamIdentifier streamIdentifier); @Override List<Lease> listLeases(); @Override boolean isLeaseTableEmpty(); @Override boolean createLeaseIfNotExists(@NonNull final Lease lease); @Override Lease getLease(@NonNull final String leaseKey); @Override boolean renewLease(@NonNull final Lease lease); @Override boolean takeLease(@NonNull final Lease lease, @NonNull final String owner); @Override boolean evictLease(@NonNull final Lease lease); void deleteAll(); @Override void deleteLease(@NonNull final Lease lease); @Override boolean updateLease(@NonNull final Lease lease); @Override void updateLeaseWithMetaInfo(Lease lease, UpdateField updateField); @Override ExtendedSequenceNumber getCheckpoint(String leaseKey); }
DynamoDBLeaseRefresher implements LeaseRefresher { @Override public boolean renewLease(@NonNull final Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { log.debug("Renewing lease with key {}", lease.leaseKey()); UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease)) .expected(serializer.getDynamoLeaseCounterExpectation(lease)) .attributeUpdates(serializer.getDynamoLeaseCounterUpdate(lease)).build(); final AWSExceptionManager exceptionManager = createExceptionManager(); exceptionManager.add(ConditionalCheckFailedException.class, t -> t); try { try { FutureUtils.resolveOrCancelFuture(dynamoDBClient.updateItem(request), dynamoDbRequestTimeout); } catch (ExecutionException e) { throw exceptionManager.apply(e.getCause()); } catch (InterruptedException e) { throw new DependencyException(e); } } catch (ConditionalCheckFailedException e) { log.debug("Lease renewal failed for lease with key {} because the lease counter was not {}", lease.leaseKey(), lease.leaseCounter()); String expectedOwner = lease.leaseOwner(); Long expectedCounter = lease.leaseCounter() + 1; final Lease updatedLease = getLease(lease.leaseKey()); if (updatedLease == null || !expectedOwner.equals(updatedLease.leaseOwner()) || !expectedCounter.equals(updatedLease.leaseCounter())) { return false; } log.info("Detected spurious renewal failure for lease with key {}, but recovered", lease.leaseKey()); } catch (DynamoDbException | TimeoutException e) { throw new DependencyException(e); } lease.leaseCounter(lease.leaseCounter() + 1); return true; } @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
            final LeaseSerializer serializer, final boolean consistentReads); @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback); @Deprecated  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout);  DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
                                  final LeaseSerializer serializer, final boolean consistentReads,
                                  @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
                                  final BillingMode billingMode); @Override boolean createLeaseTableIfNotExists(@NonNull final Long readCapacity, @NonNull final Long writeCapacity); @Override boolean leaseTableExists(); @Override boolean waitUntilLeaseTableExists(long secondsBetweenPolls, long timeoutSeconds); @Override List<Lease> listLeasesForStream(StreamIdentifier streamIdentifier); @Override List<Lease> listLeases(); @Override boolean isLeaseTableEmpty(); @Override boolean createLeaseIfNotExists(@NonNull final Lease lease); @Override Lease getLease(@NonNull final String leaseKey); @Override boolean renewLease(@NonNull final Lease lease); @Override boolean takeLease(@NonNull final Lease lease, @NonNull final String owner); @Override boolean evictLease(@NonNull final Lease lease); void deleteAll(); @Override void deleteLease(@NonNull final Lease lease); @Override boolean updateLease(@NonNull final Lease lease); @Override void updateLeaseWithMetaInfo(Lease lease, UpdateField updateField); @Override ExtendedSequenceNumber getCheckpoint(String leaseKey);  }