From 3d6800874cdc5e4c18df6ea0197f607f6298cab7 Mon Sep 17 00:00:00 2001 From: stair <123031771+stair-aws@users.noreply.github.com> Date: Fri, 23 Jun 2023 14:58:10 -0400 Subject: [PATCH 1/9] Code cleanup to faciliate Checkstyle enforcement. (#1148) No functional change. --- .../ShardRecordProcessorCheckpointer.java | 6 ++-- .../dynamodb/DynamoDBCheckpointer.java | 3 +- .../kinesis/common/HashKeyRangeForLease.java | 3 +- .../NoOpWorkerStateChangeListener.java | 16 +++++----- .../coordinator/PeriodicShardSyncManager.java | 7 +++-- .../amazon/kinesis/coordinator/Scheduler.java | 5 +-- .../WorkerStateChangeListener.java | 20 ++++++------ .../leases/HierarchicalShardSyncer.java | 31 +++++++++++-------- .../kinesis/leases/LeaseCleanupManager.java | 2 +- .../kinesis/leases/LeaseManagementConfig.java | 4 +-- .../amazon/kinesis/leases/ShardSyncTask.java | 2 +- .../dynamodb/DynamoDBLeaseRefresher.java | 4 +-- .../dynamodb/DynamoDBLeaseSerializer.java | 4 +-- .../CustomerApplicationException.java | 6 ++-- .../amazon/kinesis/lifecycle/ProcessTask.java | 6 ++-- .../lifecycle/ShardConsumerSubscriber.java | 3 +- .../kinesis/lifecycle/ShutdownTask.java | 2 +- .../kinesis/metrics/CloudWatchMetricKey.java | 13 ++++---- .../kinesis/metrics/MetricDatumWithKey.java | 10 +++--- .../fanout/FanOutRecordsPublisher.java | 23 +++++++++----- .../fanout/FanOutRetrievalFactory.java | 2 +- .../retrieval/polling/PollingConfig.java | 2 +- .../polling/PrefetchRecordsPublisher.java | 4 +-- 23 files changed, 101 insertions(+), 77 deletions(-) diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardRecordProcessorCheckpointer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardRecordProcessorCheckpointer.java index fd375264..5fbac1d7 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardRecordProcessorCheckpointer.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardRecordProcessorCheckpointer.java @@ -144,7 +144,8 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi * {@inheritDoc} */ @Override - public PreparedCheckpointer prepareCheckpoint(byte[] applicationState) throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { + public PreparedCheckpointer prepareCheckpoint(byte[] applicationState) + throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { return prepareCheckpoint(largestPermittedCheckpointValue.sequenceNumber(), applicationState); } @@ -152,7 +153,8 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi * {@inheritDoc} */ @Override - public PreparedCheckpointer prepareCheckpoint(Record record, byte[] applicationState) throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { + public PreparedCheckpointer prepareCheckpoint(Record record, byte[] applicationState) + throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { // // TODO: UserRecord Deprecation // diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointer.java index d9646351..1aa258bb 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointer.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointer.java @@ -103,7 +103,8 @@ public class DynamoDBCheckpointer implements Checkpointer { } @Override - public void prepareCheckpoint(String leaseKey, ExtendedSequenceNumber pendingCheckpoint, String concurrencyToken, byte[] pendingCheckpointState) throws KinesisClientLibException { + public void prepareCheckpoint(String leaseKey, ExtendedSequenceNumber pendingCheckpoint, String concurrencyToken, + byte[] pendingCheckpointState) throws KinesisClientLibException { try { boolean wasSuccessful = prepareCheckpoint(leaseKey, pendingCheckpoint, UUID.fromString(concurrencyToken), pendingCheckpointState); diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/HashKeyRangeForLease.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/HashKeyRangeForLease.java index d2540073..30f8963a 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/HashKeyRangeForLease.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/HashKeyRangeForLease.java @@ -23,10 +23,11 @@ import software.amazon.awssdk.services.kinesis.model.HashKeyRange; import java.math.BigInteger; -@Value @Accessors(fluent = true) /** * Lease POJO to hold the starting hashkey range and ending hashkey range of kinesis shards. */ +@Accessors(fluent = true) +@Value public class HashKeyRangeForLease { private final BigInteger startingHashKey; diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/NoOpWorkerStateChangeListener.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/NoOpWorkerStateChangeListener.java index 3e0432cb..ec21e4f6 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/NoOpWorkerStateChangeListener.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/NoOpWorkerStateChangeListener.java @@ -16,15 +16,15 @@ package software.amazon.kinesis.coordinator; public class NoOpWorkerStateChangeListener implements WorkerStateChangeListener { - /** - * Empty constructor for NoOp Worker State Change Listener - */ - public NoOpWorkerStateChangeListener() { + /** + * Empty constructor for NoOp Worker State Change Listener + */ + public NoOpWorkerStateChangeListener() { - } + } - @Override - public void onWorkerStateChange(WorkerState newState) { + @Override + public void onWorkerStateChange(WorkerState newState) { - } + } } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManager.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManager.java index dac77351..aecb1331 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManager.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManager.java @@ -348,7 +348,7 @@ class PeriodicShardSyncManager { ((MultiStreamLease) lease).shardId() : lease.leaseKey(); final Shard shard = kinesisShards.get(shardId); - if(shard == null) { + if (shard == null) { return lease; } lease.hashKeyRange(fromHashKeyRange(shard.hashKeyRange())); @@ -372,7 +372,7 @@ class PeriodicShardSyncManager { List leasesWithHashKeyRanges) { // Sort the hash ranges by starting hash key. List sortedLeasesWithHashKeyRanges = sortLeasesByHashRange(leasesWithHashKeyRanges); - if(sortedLeasesWithHashKeyRanges.isEmpty()) { + if (sortedLeasesWithHashKeyRanges.isEmpty()) { log.error("No leases with valid hashranges found for stream {}", streamIdentifier); return Optional.of(new HashRangeHole()); } @@ -417,8 +417,9 @@ class PeriodicShardSyncManager { @VisibleForTesting static List sortLeasesByHashRange(List leasesWithHashKeyRanges) { - if (leasesWithHashKeyRanges.size() == 0 || leasesWithHashKeyRanges.size() == 1) + if (leasesWithHashKeyRanges.size() == 0 || leasesWithHashKeyRanges.size() == 1) { return leasesWithHashKeyRanges; + } Collections.sort(leasesWithHashKeyRanges, new HashKeyRangeComparator()); return leasesWithHashKeyRanges; } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/Scheduler.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/Scheduler.java index 49d271b2..d67fff96 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/Scheduler.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/Scheduler.java @@ -544,7 +544,8 @@ public class Scheduler implements Runnable { final Map> staleStreamIdDeletionDecisionMap = staleStreamDeletionMap.keySet().stream().collect(Collectors .partitioningBy(newStreamConfigMap::containsKey, Collectors.toSet())); final Set staleStreamIdsToBeDeleted = staleStreamIdDeletionDecisionMap.get(false).stream().filter(streamIdentifier -> - Duration.between(staleStreamDeletionMap.get(streamIdentifier), Instant.now()).toMillis() >= waitPeriodToDeleteOldStreams.toMillis()).collect(Collectors.toSet()); + Duration.between(staleStreamDeletionMap.get(streamIdentifier), Instant.now()).toMillis() >= waitPeriodToDeleteOldStreams.toMillis()) + .collect(Collectors.toSet()); // These are the streams which are deleted in Kinesis and we encounter resource not found during // shardSyncTask. This is applicable in MultiStreamMode only, in case of SingleStreamMode, store will // not have any data. @@ -611,7 +612,7 @@ public class Scheduler implements Runnable { } private void removeStreamsFromStaleStreamsList(Set streamIdentifiers) { - for(StreamIdentifier streamIdentifier : streamIdentifiers) { + for (StreamIdentifier streamIdentifier : streamIdentifiers) { staleStreamDeletionMap.remove(streamIdentifier); } } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/WorkerStateChangeListener.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/WorkerStateChangeListener.java index ddce2a10..dd7162b3 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/WorkerStateChangeListener.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/WorkerStateChangeListener.java @@ -19,16 +19,16 @@ package software.amazon.kinesis.coordinator; */ @FunctionalInterface public interface WorkerStateChangeListener { - enum WorkerState { - CREATED, - INITIALIZING, - STARTED, - SHUT_DOWN_STARTED, - SHUT_DOWN - } + enum WorkerState { + CREATED, + INITIALIZING, + STARTED, + SHUT_DOWN_STARTED, + SHUT_DOWN + } - void onWorkerStateChange(WorkerState newState); + void onWorkerStateChange(WorkerState newState); - default void onAllInitializationAttemptsFailed(Throwable e) { - } + default void onAllInitializationAttemptsFailed(Throwable e) { + } } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/HierarchicalShardSyncer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/HierarchicalShardSyncer.java index b71796d3..534b5fd3 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/HierarchicalShardSyncer.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/HierarchicalShardSyncer.java @@ -80,7 +80,7 @@ public class HierarchicalShardSyncer { private static final String MIN_HASH_KEY = BigInteger.ZERO.toString(); private static final String MAX_HASH_KEY = new BigInteger("2").pow(128).subtract(BigInteger.ONE).toString(); - private static final int retriesForCompleteHashRange = 3; + private static final int RETRIES_FOR_COMPLETE_HASH_RANGE = 3; private static final long DELAY_BETWEEN_LIST_SHARDS_MILLIS = 1000; @@ -98,7 +98,7 @@ public class HierarchicalShardSyncer { this.deletedStreamListProvider = deletedStreamListProvider; } - private static final BiFunction shardIdFromLeaseDeducer = + private static final BiFunction SHARD_ID_FROM_LEASE_DEDUCER = (lease, multiStreamArgs) -> multiStreamArgs.isMultiStreamMode() ? ((MultiStreamLease) lease).shardId() : @@ -129,7 +129,9 @@ public class HierarchicalShardSyncer { isLeaseTableEmpty); } - //Provide a pre-collcted list of shards to avoid calling ListShards API + /** + * Provide a pre-collected list of shards to avoid calling ListShards API + */ public synchronized boolean checkAndCreateLeaseForNewShards(@NonNull final ShardDetector shardDetector, final LeaseRefresher leaseRefresher, final InitialPositionInStreamExtended initialPosition, List latestShards, final boolean ignoreUnexpectedChildShards, final MetricsScope scope, final boolean isLeaseTableEmpty) @@ -163,7 +165,7 @@ public class HierarchicalShardSyncer { final long startTime = System.currentTimeMillis(); boolean success = false; try { - if(leaseRefresher.createLeaseIfNotExists(lease)) { + if (leaseRefresher.createLeaseIfNotExists(lease)) { createdLeases.add(lease); } success = true; @@ -268,7 +270,7 @@ public class HierarchicalShardSyncer { List shards; - for (int i = 0; i < retriesForCompleteHashRange; i++) { + for (int i = 0; i < RETRIES_FOR_COMPLETE_HASH_RANGE; i++) { shards = shardDetector.listShardsWithFilter(shardFilter); if (shards == null) { @@ -284,7 +286,7 @@ public class HierarchicalShardSyncer { } throw new KinesisClientLibIOException("Hash range of shards returned for " + streamName + " was incomplete after " - + retriesForCompleteHashRange + " retries."); + + RETRIES_FOR_COMPLETE_HASH_RANGE + " retries."); } private List getShardList(@NonNull final ShardDetector shardDetector) throws KinesisClientLibIOException { @@ -365,7 +367,8 @@ public class HierarchicalShardSyncer { * @return List of new leases to create sorted by starting sequenceNumber of the corresponding shard */ static List determineNewLeasesToCreate(final LeaseSynchronizer leaseSynchronizer, final List shards, - final List currentLeases, final InitialPositionInStreamExtended initialPosition,final Set inconsistentShardIds) { + final List currentLeases, final InitialPositionInStreamExtended initialPosition, + final Set inconsistentShardIds) { return determineNewLeasesToCreate(leaseSynchronizer, shards, currentLeases, initialPosition, inconsistentShardIds, new MultiStreamArgs(false, null)); } @@ -499,11 +502,13 @@ public class HierarchicalShardSyncer { if (descendantParentShardIds.contains(parentShardId) && !initialPosition.getInitialPositionInStream() .equals(InitialPositionInStream.AT_TIMESTAMP)) { - log.info("Setting Lease '{}' checkpoint to 'TRIM_HORIZON'. Checkpoint was previously set to {}", lease.leaseKey(), lease.checkpoint()); + log.info("Setting Lease '{}' checkpoint to 'TRIM_HORIZON'. Checkpoint was previously set to {}", + lease.leaseKey(), lease.checkpoint()); lease.checkpoint(ExtendedSequenceNumber.TRIM_HORIZON); } else { final ExtendedSequenceNumber newCheckpoint = convertToCheckpoint(initialPosition); - log.info("Setting Lease '{}' checkpoint to '{}'. Checkpoint was previously set to {}", lease.leaseKey(), newCheckpoint, lease.checkpoint()); + log.info("Setting Lease '{}' checkpoint to '{}'. Checkpoint was previously set to {}", + lease.leaseKey(), newCheckpoint, lease.checkpoint()); lease.checkpoint(newCheckpoint); } } @@ -728,8 +733,8 @@ public class HierarchicalShardSyncer { @Override public int compare(final Lease lease1, final Lease lease2) { int result = 0; - final String shardId1 = shardIdFromLeaseDeducer.apply(lease1, multiStreamArgs); - final String shardId2 = shardIdFromLeaseDeducer.apply(lease2, multiStreamArgs); + final String shardId1 = SHARD_ID_FROM_LEASE_DEDUCER.apply(lease1, multiStreamArgs); + final String shardId2 = SHARD_ID_FROM_LEASE_DEDUCER.apply(lease2, multiStreamArgs); final Shard shard1 = shardIdToShardMap.get(shardId1); final Shard shard2 = shardIdToShardMap.get(shardId2); @@ -802,7 +807,7 @@ public class HierarchicalShardSyncer { final Map shardIdToShardMapOfAllKinesisShards = constructShardIdToShardMap(shards); currentLeases.stream().peek(lease -> log.debug("{} : Existing lease: {}", streamIdentifier, lease)) - .map(lease -> shardIdFromLeaseDeducer.apply(lease, multiStreamArgs)) + .map(lease -> SHARD_ID_FROM_LEASE_DEDUCER.apply(lease, multiStreamArgs)) .collect(Collectors.toSet()); final List newLeasesToCreate = getLeasesToCreateForOpenAndClosedShards(initialPosition, shards, multiStreamArgs, streamIdentifier); @@ -908,7 +913,7 @@ public class HierarchicalShardSyncer { .map(streamId -> streamId.serialize()).orElse(""); final Set shardIdsOfCurrentLeases = currentLeases.stream() .peek(lease -> log.debug("{} : Existing lease: {}", streamIdentifier, lease)) - .map(lease -> shardIdFromLeaseDeducer.apply(lease, multiStreamArgs)) + .map(lease -> SHARD_ID_FROM_LEASE_DEDUCER.apply(lease, multiStreamArgs)) .collect(Collectors.toSet()); final List openShards = getOpenShards(shards, streamIdentifier); diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCleanupManager.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCleanupManager.java index d62cd476..8a442bd3 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCleanupManager.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCleanupManager.java @@ -179,7 +179,7 @@ public class LeaseCleanupManager { try { if (cleanupLeasesUponShardCompletion && timeToCheckForCompletedShard) { final Lease leaseFromDDB = leaseCoordinator.leaseRefresher().getLease(lease.leaseKey()); - if(leaseFromDDB != null) { + if (leaseFromDDB != null) { Set childShardKeys = leaseFromDDB.childShardIds(); if (CollectionUtils.isNullOrEmpty(childShardKeys)) { try { diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementConfig.java index d80799fa..9b95f562 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementConfig.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementConfig.java @@ -310,7 +310,7 @@ public class LeaseManagementConfig { private LeaseManagementFactory leaseManagementFactory; public HierarchicalShardSyncer hierarchicalShardSyncer() { - if(hierarchicalShardSyncer == null) { + if (hierarchicalShardSyncer == null) { hierarchicalShardSyncer = new HierarchicalShardSyncer(); } return hierarchicalShardSyncer; @@ -356,7 +356,7 @@ public class LeaseManagementConfig { * @return LeaseManagementFactory */ public LeaseManagementFactory leaseManagementFactory(final LeaseSerializer leaseSerializer, boolean isMultiStreamingMode) { - if(leaseManagementFactory == null) { + if (leaseManagementFactory == null) { leaseManagementFactory = new DynamoDBLeaseManagementFactory(kinesisClient(), dynamoDBClient(), tableName(), diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTask.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTask.java index dd576114..1986fa49 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTask.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTask.java @@ -37,7 +37,7 @@ import software.amazon.kinesis.metrics.MetricsUtil; @Slf4j @KinesisClientInternalApi public class ShardSyncTask implements ConsumerTask { - private final String SHARD_SYNC_TASK_OPERATION = "ShardSyncTask"; + private static final String SHARD_SYNC_TASK_OPERATION = "ShardSyncTask"; @NonNull private final ShardDetector shardDetector; diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresher.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresher.java index a6887f40..4bef8442 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresher.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresher.java @@ -187,7 +187,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher { public boolean createLeaseTableIfNotExists(@NonNull final Long readCapacity, @NonNull final Long writeCapacity) throws ProvisionedThroughputException, DependencyException { final CreateTableRequest.Builder builder = createTableRequestBuilder(); - if(BillingMode.PROVISIONED.equals(billingMode)) { + if (BillingMode.PROVISIONED.equals(billingMode)) { ProvisionedThroughput throughput = ProvisionedThroughput.builder().readCapacityUnits(readCapacity) .writeCapacityUnits(writeCapacity).build(); builder.provisionedThroughput(throughput); @@ -467,7 +467,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher { } catch (DynamoDbException | TimeoutException e) { throw convertAndRethrowExceptions("create", lease.leaseKey(), e); } - log.info("Created lease: {}",lease); + log.info("Created lease: {}", lease); return true; } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseSerializer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseSerializer.java index 64a7840c..9ebed654 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseSerializer.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseSerializer.java @@ -89,7 +89,7 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer { result.put(PENDING_CHECKPOINT_STATE_KEY, DynamoUtils.createAttributeValue(lease.checkpoint().subSequenceNumber())); } - if(lease.hashKeyRangeForLease() != null) { + if (lease.hashKeyRangeForLease() != null) { result.put(STARTING_HASH_KEY, DynamoUtils.createAttributeValue(lease.hashKeyRangeForLease().serializedStartingHashKey())); result.put(ENDING_HASH_KEY, DynamoUtils.createAttributeValue(lease.hashKeyRangeForLease().serializedEndingHashKey())); } @@ -274,7 +274,7 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer { result.put(CHILD_SHARD_IDS_KEY, putUpdate(DynamoUtils.createAttributeValue(lease.childShardIds()))); } - if(lease.hashKeyRangeForLease() != null) { + if (lease.hashKeyRangeForLease() != null) { result.put(STARTING_HASH_KEY, putUpdate(DynamoUtils.createAttributeValue(lease.hashKeyRangeForLease().serializedStartingHashKey()))); result.put(ENDING_HASH_KEY, putUpdate(DynamoUtils.createAttributeValue(lease.hashKeyRangeForLease().serializedEndingHashKey()))); } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/exceptions/CustomerApplicationException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/exceptions/CustomerApplicationException.java index ba97ab08..8f2e8149 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/exceptions/CustomerApplicationException.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/exceptions/CustomerApplicationException.java @@ -19,9 +19,9 @@ package software.amazon.kinesis.leases.exceptions; */ public class CustomerApplicationException extends Exception { - public CustomerApplicationException(Throwable e) { super(e);} + public CustomerApplicationException(Throwable e) { super(e); } - public CustomerApplicationException(String message, Throwable e) { super(message, e);} + public CustomerApplicationException(String message, Throwable e) { super(message, e); } - public CustomerApplicationException(String message) { super(message);} + public CustomerApplicationException(String message) { super(message); } } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ProcessTask.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ProcessTask.java index c3f9523d..fb398cda 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ProcessTask.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ProcessTask.java @@ -212,8 +212,10 @@ public class ProcessTask implements ConsumerTask { log.debug("Calling application processRecords() with {} records from {}", records.size(), shardInfoId); - final ProcessRecordsInput processRecordsInput = ProcessRecordsInput.builder().records(records).cacheExitTime(input.cacheExitTime()).cacheEntryTime(input.cacheEntryTime()) - .isAtShardEnd(input.isAtShardEnd()).checkpointer(recordProcessorCheckpointer).millisBehindLatest(input.millisBehindLatest()).build(); + final ProcessRecordsInput processRecordsInput = ProcessRecordsInput.builder().records(records) + .cacheExitTime(input.cacheExitTime()).cacheEntryTime(input.cacheEntryTime()) + .isAtShardEnd(input.isAtShardEnd()).checkpointer(recordProcessorCheckpointer) + .millisBehindLatest(input.millisBehindLatest()).build(); final MetricsScope scope = MetricsUtil.createMetricsWithOperation(metricsFactory, PROCESS_TASK_OPERATION); shardInfo.streamIdentifierSerOpt() diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java index e8406d92..7a034000 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java @@ -61,7 +61,7 @@ class ShardConsumerSubscriber implements Subscriber { @Deprecated ShardConsumerSubscriber(RecordsPublisher recordsPublisher, ExecutorService executorService, int bufferSize, ShardConsumer shardConsumer) { - this(recordsPublisher,executorService,bufferSize,shardConsumer, LifecycleConfig.DEFAULT_READ_TIMEOUTS_TO_IGNORE); + this(recordsPublisher, executorService, bufferSize, shardConsumer, LifecycleConfig.DEFAULT_READ_TIMEOUTS_TO_IGNORE); } ShardConsumerSubscriber(RecordsPublisher recordsPublisher, ExecutorService executorService, int bufferSize, @@ -74,7 +74,6 @@ class ShardConsumerSubscriber implements Subscriber { this.shardInfoId = ShardInfo.getLeaseKey(shardConsumer.shardInfo()); } - void startSubscriptions() { synchronized (lockObject) { // Setting the lastRequestTime to allow for health checks to restart subscriptions if they failed to diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShutdownTask.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShutdownTask.java index 31bc8f88..4a96d87d 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShutdownTask.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShutdownTask.java @@ -283,7 +283,7 @@ public class ShutdownTask implements ConsumerTask { } } - for(ChildShard childShard : childShards) { + for (ChildShard childShard : childShards) { final String leaseKey = ShardInfo.getLeaseKey(shardInfo, childShard.shardId()); if (leaseRefresher.getLease(leaseKey) == null) { log.debug("{} - Shard {} - Attempting to create lease for child shard {}", shardDetector.streamIdentifier(), shardInfo.shardId(), leaseKey); diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/CloudWatchMetricKey.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/CloudWatchMetricKey.java index 4b04cad7..e52893cd 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/CloudWatchMetricKey.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/CloudWatchMetricKey.java @@ -20,9 +20,7 @@ import java.util.Objects; import software.amazon.awssdk.services.cloudwatch.model.Dimension; import software.amazon.awssdk.services.cloudwatch.model.MetricDatum; - - -/* +/** * A representation of a key of a MetricDatum. This class is useful when wanting to compare * whether 2 keys have the same MetricDatum. This feature will be used in MetricAccumulatingQueue * where we aggregate metrics across multiple MetricScopes. @@ -48,12 +46,15 @@ public class CloudWatchMetricKey { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } CloudWatchMetricKey other = (CloudWatchMetricKey) obj; return Objects.equals(other.dimensions, dimensions) && Objects.equals(other.metricName, metricName); } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java index 5234ffe4..da83675f 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java @@ -36,7 +36,6 @@ import java.util.Objects; * * MetricDatumWithKey sampleDatumWithKey = new MetricDatumWithKey(new * SampleMetricKey(System.currentTimeMillis()), datum) - * */ @AllArgsConstructor @Setter @@ -59,12 +58,15 @@ public class MetricDatumWithKey { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } MetricDatumWithKey other = (MetricDatumWithKey) obj; return Objects.equals(other.key, key) && Objects.equals(other.datum, datum); } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java index 8404925d..3a8af8c2 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java @@ -192,7 +192,7 @@ public class FanOutRecordsPublisher implements RecordsPublisher { // Take action based on the time spent by the event in queue. takeDelayedDeliveryActionIfRequired(streamAndShardId, recordsRetrievedContext.getEnqueueTimestamp(), log); // Update current sequence number for the successfully delivered event. - currentSequenceNumber = ((FanoutRecordsRetrieved)recordsRetrieved).continuationSequenceNumber(); + currentSequenceNumber = ((FanoutRecordsRetrieved) recordsRetrieved).continuationSequenceNumber(); // Update the triggering flow for post scheduling upstream request. flowToBeReturned = recordsRetrievedContext.getRecordFlow(); // Try scheduling the next event in the queue or execute the subscription shutdown action. @@ -206,7 +206,8 @@ public class FanOutRecordsPublisher implements RecordsPublisher { if (flow != null && recordsDeliveryAck.batchUniqueIdentifier().getFlowIdentifier() .equals(flow.getSubscribeToShardId())) { log.error( - "{}: Received unexpected ack for the active subscription {}. Throwing. ", streamAndShardId, recordsDeliveryAck.batchUniqueIdentifier().getFlowIdentifier()); + "{}: Received unexpected ack for the active subscription {}. Throwing.", + streamAndShardId, recordsDeliveryAck.batchUniqueIdentifier().getFlowIdentifier()); throw new IllegalStateException("Unexpected ack for the active subscription"); } // Otherwise publisher received a stale ack. @@ -315,7 +316,7 @@ public class FanOutRecordsPublisher implements RecordsPublisher { synchronized (lockObject) { if (!hasValidSubscriber()) { - if(hasValidFlow()) { + if (hasValidFlow()) { log.warn( "{}: [SubscriptionLifetime] - (FanOutRecordsPublisher#errorOccurred) @ {} id: {} -- Subscriber is null." + " Last successful request details -- {}", streamAndShardId, flow.connectionStartedAt, @@ -335,7 +336,8 @@ public class FanOutRecordsPublisher implements RecordsPublisher { if (flow != null) { String logMessage = String.format( "%s: [SubscriptionLifetime] - (FanOutRecordsPublisher#errorOccurred) @ %s id: %s -- %s." + - " Last successful request details -- %s", streamAndShardId, flow.connectionStartedAt, flow.subscribeToShardId, category.throwableTypeString, lastSuccessfulRequestDetails); + " Last successful request details -- %s", streamAndShardId, flow.connectionStartedAt, + flow.subscribeToShardId, category.throwableTypeString, lastSuccessfulRequestDetails); switch (category.throwableType) { case READ_TIMEOUT: log.debug(logMessage, propagationThrowable); @@ -778,7 +780,11 @@ public class FanOutRecordsPublisher implements RecordsPublisher { executeExceptionOccurred(throwable); } else { final SubscriptionShutdownEvent subscriptionShutdownEvent = new SubscriptionShutdownEvent( - () -> {parent.recordsDeliveryQueue.poll(); executeExceptionOccurred(throwable);}, "onError", throwable); + () -> { + parent.recordsDeliveryQueue.poll(); + executeExceptionOccurred(throwable); + }, + "onError", throwable); tryEnqueueSubscriptionShutdownEvent(subscriptionShutdownEvent); } } @@ -786,7 +792,6 @@ public class FanOutRecordsPublisher implements RecordsPublisher { private void executeExceptionOccurred(Throwable throwable) { synchronized (parent.lockObject) { - log.debug("{}: [SubscriptionLifetime]: (RecordFlow#exceptionOccurred) @ {} id: {} -- {}: {}", parent.streamAndShardId, connectionStartedAt, subscribeToShardId, throwable.getClass().getName(), throwable.getMessage()); @@ -817,7 +822,11 @@ public class FanOutRecordsPublisher implements RecordsPublisher { executeComplete(); } else { final SubscriptionShutdownEvent subscriptionShutdownEvent = new SubscriptionShutdownEvent( - () -> {parent.recordsDeliveryQueue.poll(); executeComplete();}, "onComplete"); + () -> { + parent.recordsDeliveryQueue.poll(); + executeComplete(); + }, + "onComplete"); tryEnqueueSubscriptionShutdownEvent(subscriptionShutdownEvent); } } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRetrievalFactory.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRetrievalFactory.java index 35301624..bcfb1081 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRetrievalFactory.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRetrievalFactory.java @@ -54,7 +54,7 @@ public class FanOutRetrievalFactory implements RetrievalFactory { final StreamConfig streamConfig, final MetricsFactory metricsFactory) { final Optional streamIdentifierStr = shardInfo.streamIdentifierSerOpt(); - if(streamIdentifierStr.isPresent()) { + if (streamIdentifierStr.isPresent()) { final StreamIdentifier streamIdentifier = StreamIdentifier.multiStreamInstance(streamIdentifierStr.get()); return new FanOutRecordsPublisher(kinesisClient, shardInfo.shardId(), getOrCreateConsumerArn(streamIdentifier, streamConfig.consumerArn()), diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PollingConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PollingConfig.java index 4dd64016..0cc7058d 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PollingConfig.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PollingConfig.java @@ -137,7 +137,7 @@ public class PollingConfig implements RetrievalSpecificConfig { @Override public RetrievalFactory retrievalFactory() { // Prioritize the PollingConfig specified value if its updated. - if(usePollingConfigIdleTimeValue) { + if (usePollingConfigIdleTimeValue) { recordsFetcherFactory.idleMillisBetweenCalls(idleTimeBetweenReadsInMillis); } return new SynchronousBlockingRetrievalFactory(streamName(), kinesisClient(), recordsFetcherFactory, diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisher.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisher.java index 07f4aaac..eb5937f7 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisher.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisher.java @@ -327,7 +327,7 @@ public class PrefetchRecordsPublisher implements RecordsPublisher { } resetLock.writeLock().lock(); try { - publisherSession.reset((PrefetchRecordsRetrieved)recordsRetrieved); + publisherSession.reset((PrefetchRecordsRetrieved) recordsRetrieved); wasReset = true; } finally { resetLock.writeLock().unlock(); @@ -555,7 +555,7 @@ public class PrefetchRecordsPublisher implements RecordsPublisher { return; } // Add a sleep if lastSuccessfulCall is still null but this is not the first try to avoid retry storm - if(lastSuccessfulCall == null) { + if (lastSuccessfulCall == null) { Thread.sleep(idleMillisBetweenCalls); return; } From eb6fd0cf32056e6df2a76d5064ca60848e2aa5f4 Mon Sep 17 00:00:00 2001 From: stair <123031771+stair-aws@users.noreply.github.com> Date: Fri, 23 Jun 2023 16:15:33 -0400 Subject: [PATCH 2/9] Bound Checkstyle to `validate` goal for automated enforcement. (#1149) --- .../lifecycle/ShardConsumerSubscriber.java | 2 + .../fanout/FanOutRecordsPublisher.java | 14 +++++++ .../retrieval/polling/KinesisDataFetcher.java | 2 + checkstyle/checkstyle-suppressions.xml | 8 ++++ checkstyle/checkstyle.xml | 39 +++++++++++++++++++ pom.xml | 21 ++++++++++ 6 files changed, 86 insertions(+) create mode 100644 checkstyle/checkstyle-suppressions.xml create mode 100644 checkstyle/checkstyle.xml diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java index 7a034000..81528c4e 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriber.java @@ -130,7 +130,9 @@ class ShardConsumerSubscriber implements Subscriber { Duration timeSinceLastResponse = Duration.between(lastRequestTime, now); if (timeSinceLastResponse.toMillis() > maxTimeBetweenRequests) { log.error( + // CHECKSTYLE.OFF: LineLength "{}: Last request was dispatched at {}, but no response as of {} ({}). Cancelling subscription, and restarting. Last successful request details -- {}", + // CHECKSTYLE.ON: LineLength shardInfoId, lastRequestTime, now, timeSinceLastResponse, recordsPublisher.getLastSuccessfulRequestDetails()); cancel(); diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java index 3a8af8c2..ca4ce12d 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java @@ -369,7 +369,9 @@ public class FanOutRecordsPublisher implements RecordsPublisher { } else { if (triggeringFlow != null) { log.debug( + // CHECKSTYLE.OFF: LineLength "{}: [SubscriptionLifetime] - (FanOutRecordsPublisher#errorOccurred) @ {} id: {} -- {} -> triggeringFlow wasn't the active flow. Didn't dispatch error", + // CHECKSTYLE.ON: LineLength streamAndShardId, triggeringFlow.connectionStartedAt, triggeringFlow.subscribeToShardId, category.throwableTypeString); triggeringFlow.cancel(); @@ -605,7 +607,9 @@ public class FanOutRecordsPublisher implements RecordsPublisher { synchronized (lockObject) { if (subscriber != s) { log.warn( + // CHECKSTYLE.OFF: LineLength "{}: (FanOutRecordsPublisher/Subscription#request) - Rejected an attempt to request({}), because subscribers don't match. Last successful request details -- {}", + // CHECKSTYLE.ON: LineLength streamAndShardId, n, lastSuccessfulRequestDetails); return; } @@ -632,13 +636,17 @@ public class FanOutRecordsPublisher implements RecordsPublisher { synchronized (lockObject) { if (subscriber != s) { log.warn( + // CHECKSTYLE.OFF: LineLength "{}: (FanOutRecordsPublisher/Subscription#cancel) - Rejected attempt to cancel subscription, because subscribers don't match. Last successful request details -- {}", + // CHECKSTYLE.ON: LineLength streamAndShardId, lastSuccessfulRequestDetails); return; } if (!hasValidSubscriber()) { log.warn( + // CHECKSTYLE.OFF: LineLength "{}: (FanOutRecordsPublisher/Subscription#cancel) - Cancelled called even with an invalid subscriber. Last successful request details -- {}", + // CHECKSTYLE.ON: LineLength streamAndShardId, lastSuccessfulRequestDetails); } subscriber = null; @@ -808,7 +816,9 @@ public class FanOutRecordsPublisher implements RecordsPublisher { isErrorDispatched = true; } else { log.debug( + // CHECKSTYLE.OFF: LineLength "{}: [SubscriptionLifetime]: (RecordFlow#exceptionOccurred) @ {} id: {} -- An error has previously been dispatched, not dispatching this error {}: {}", + // CHECKSTYLE.OFF: LineLength parent.streamAndShardId, connectionStartedAt, subscribeToShardId, throwable.getClass().getName(), throwable.getMessage()); } @@ -839,7 +849,9 @@ public class FanOutRecordsPublisher implements RecordsPublisher { .add(new RecordsRetrievedContext(Either.right(subscriptionShutdownEvent), this, Instant.now())); } catch (Exception e) { log.warn( + // CHECKSTYLE.OFF: LineLength "{}: Unable to enqueue the {} shutdown event due to capacity restrictions in delivery queue with remaining capacity {}. Ignoring. Last successful request details -- {}", + // CHECKSTYLE.ON: LineLength parent.streamAndShardId, subscriptionShutdownEvent.getEventIdentifier(), parent.recordsDeliveryQueue.remainingCapacity(), parent.lastSuccessfulRequestDetails, subscriptionShutdownEvent.getShutdownEventThrowableOptional()); } @@ -863,7 +875,9 @@ public class FanOutRecordsPublisher implements RecordsPublisher { } if (this.isDisposed) { log.warn( + // CHECKSTYLE.OFF: LineLength "{}: [SubscriptionLifetime]: (RecordFlow#complete) @ {} id: {} -- This flow has been disposed not dispatching completion. Last successful request details -- {}", + // CHECKSTYLE.ON: LineLength parent.streamAndShardId, connectionStartedAt, subscribeToShardId, parent.lastSuccessfulRequestDetails); return; } diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcher.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcher.java index 65da2b32..495dcfb1 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcher.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcher.java @@ -145,7 +145,9 @@ public class KinesisDataFetcher implements DataFetcher { } } + // CHECKSTYLE.OFF: MemberName final DataFetcherResult TERMINAL_RESULT = new DataFetcherResult() { + // CHECKSTYLE.ON: MemberName @Override public GetRecordsResponse getResult() { return GetRecordsResponse.builder() diff --git a/checkstyle/checkstyle-suppressions.xml b/checkstyle/checkstyle-suppressions.xml new file mode 100644 index 00000000..91be49c8 --- /dev/null +++ b/checkstyle/checkstyle-suppressions.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml new file mode 100644 index 00000000..07932723 --- /dev/null +++ b/checkstyle/checkstyle.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 7ebd6e54..82d7857d 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,27 @@ + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.3.0 + + checkstyle/checkstyle.xml + true + true + checkstyle/checkstyle-suppressions.xml + + + + validate + + check + + + + + From dcd1c53fb10ac118406dbfe3a195a27b3a20922d Mon Sep 17 00:00:00 2001 From: pelaezryan Date: Mon, 26 Jun 2023 09:02:19 -0700 Subject: [PATCH 3/9] Update to Multilang Daemon to support StreamArn (#1143) * Updated multilang to support streamArn * Updated arn import to use software.amzon instead of com.amazonaws, also updated unit tests to be more explicit with the expected exceptions * Updated exception wording for region validation in StreamArn to be more consistent with other error messages * reverted spacing change * Updated StreamArn in multilang to only replace streamName (not region as well). Also updated unit tests and added Region validation * Updated region validation in multilang to be more readible * Refactored multilang unit tests to be more simple * Updated multilang daemon to validate streamArn based on pattern rather than individual section * removed region validation as this was not a requirement for stringArn support in multilangdaemon * removed spacing and removed unit test assertion on exception message * removed unnecessary param from unit test * removed unused imports from multilang unit tests * simplified the assertion for multilang daemon unit tests * Cleaned up unit test code following best practices for spacing/naming conventions and simplied kinesisClientLibConfiguration * Updated region code in unit tests for multilang daemon --------- Co-authored-by: Ryan Pelaez --- .../config/KinesisClientLibConfigurator.java | 21 ++- .../config/MultiLangDaemonConfiguration.java | 5 +- .../kinesis/multilang/MessageReaderTest.java | 1 - .../kinesis/multilang/MessageWriterTest.java | 3 - .../multilang/MultiLangDaemonConfigTest.java | 169 ++++++++++++++---- .../multilang/MultiLangDaemonTest.java | 1 - .../multilang/MultiLangProtocolTest.java | 3 - .../kinesis/multilang/ReadSTDERRTaskTest.java | 2 - ...eamingShardRecordProcessorFactoryTest.java | 3 - ...tialsProviderPropertyValueDecoderTest.java | 6 - .../KinesisClientLibConfiguratorTest.java | 41 +++-- .../multilang/messages/MessageTest.java | 7 - .../kinesis/common/StreamIdentifier.java | 14 +- 13 files changed, 195 insertions(+), 81 deletions(-) diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java index f3facdc0..c95d0853 100644 --- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java +++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java @@ -23,8 +23,10 @@ import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.ConvertUtilsBean; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import software.amazon.awssdk.arns.Arn; +import software.amazon.awssdk.regions.Region; +import software.amazon.kinesis.common.StreamIdentifier; /** * KinesisClientLibConfigurator constructs a KinesisClientLibConfiguration from java properties file. The following @@ -55,7 +57,7 @@ public class KinesisClientLibConfigurator { * Program will fail immediately, if customer provide: 1) invalid variable value. Program will log it as warning and * continue, if customer provide: 1) variable with unsupported variable type. 2) a variable with name which does not * match any of the variables in KinesisClientLibConfigration. - * + * * @param properties a Properties object containing the configuration information * @return KinesisClientLibConfiguration */ @@ -69,8 +71,19 @@ public class KinesisClientLibConfigurator { }); Validate.notBlank(configuration.getApplicationName(), "Application name is required"); - Validate.notBlank(configuration.getStreamName(), "Stream name is required"); + + if (configuration.getStreamArn() != null && !configuration.getStreamArn().trim().isEmpty()) { + final Arn streamArnObj = Arn.fromString(configuration.getStreamArn()); + StreamIdentifier.validateArn(streamArnObj); + //Parse out the stream Name from the Arn (and/or override existing value for Stream Name) + final String streamNameFromArn = streamArnObj.resource().resource(); + configuration.setStreamName(streamNameFromArn); + + } + + Validate.notBlank(configuration.getStreamName(), "Stream name or Stream Arn is required. Stream Arn takes precedence if both are passed in."); Validate.isTrue(configuration.getKinesisCredentialsProvider().isDirty(), "A basic set of AWS credentials must be provided"); + return configuration; } @@ -97,4 +110,4 @@ public class KinesisClientLibConfigurator { } -} +} \ No newline at end of file diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java index da280ddf..7a7f2e79 100644 --- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java +++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java @@ -28,7 +28,6 @@ import java.util.UUID; import java.util.function.Function; import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.ConvertUtilsBean; import org.apache.commons.beanutils.Converter; import org.apache.commons.beanutils.converters.ArrayConverter; @@ -73,6 +72,8 @@ public class MultiLangDaemonConfiguration { private String applicationName; private String streamName; + private String streamArn; + @ConfigurationSettable(configurationClass = ConfigsBuilder.class) private String tableName; @@ -403,4 +404,4 @@ public class MultiLangDaemonConfiguration { return resolvedConfiguration(shardRecordProcessorFactory).build(); } -} +} \ No newline at end of file diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java index b6541227..14ac357c 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java @@ -28,7 +28,6 @@ import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import software.amazon.kinesis.multilang.MessageReader; import software.amazon.kinesis.multilang.messages.Message; import software.amazon.kinesis.multilang.messages.StatusMessage; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java index 6a0c06b4..eaf6be7b 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java @@ -32,15 +32,12 @@ import org.mockito.Mockito; import software.amazon.kinesis.lifecycle.events.LeaseLostInput; import software.amazon.kinesis.lifecycle.events.ShardEndedInput; -import software.amazon.kinesis.multilang.MessageWriter; -import software.amazon.kinesis.multilang.messages.LeaseLostMessage; import software.amazon.kinesis.multilang.messages.Message; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import software.amazon.kinesis.lifecycle.events.InitializationInput; import software.amazon.kinesis.lifecycle.events.ProcessRecordsInput; -import software.amazon.kinesis.lifecycle.ShutdownReason; import software.amazon.kinesis.retrieval.KinesisClientRecord; import static org.mockito.Mockito.verify; diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java index b86a64ad..c6be1157 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java @@ -14,17 +14,14 @@ */ package software.amazon.kinesis.multilang; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.util.Properties; -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.ConvertUtilsBean; -import org.junit.Before; +import software.amazon.awssdk.regions.Region; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -39,48 +36,154 @@ import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration; @RunWith(MockitoJUnitRunner.class) public class MultiLangDaemonConfigTest { - private static String FILENAME = "some.properties"; + private static final String FILENAME = "some.properties"; + private static final String EXE = "TestExe.exe"; + private static final String APPLICATION_NAME = MultiLangDaemonConfigTest.class.getSimpleName(); + private static final String STREAM_NAME = "fakeStream"; + private static final String STREAM_NAME_IN_ARN = "FAKE_STREAM_NAME"; + private static final Region REGION = Region.US_EAST_1; + private static final String STREAM_ARN = "arn:aws:kinesis:us-east-2:012345678987:stream/" + STREAM_NAME_IN_ARN; + + @Mock + private ClassLoader classLoader; @Mock private AwsCredentialsProvider credentialsProvider; @Mock private AwsCredentials creds; - @Mock + private KinesisClientLibConfigurator configurator; + private MultiLangDaemonConfig deamonConfig; - @Before - public void setup() { - ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean(); - BeanUtilsBean utilsBean = new BeanUtilsBean(convertUtilsBean); - MultiLangDaemonConfiguration multiLangDaemonConfiguration = new MultiLangDaemonConfiguration(utilsBean, - convertUtilsBean); - multiLangDaemonConfiguration.setApplicationName("cool-app"); - multiLangDaemonConfiguration.setStreamName("cool-stream"); - multiLangDaemonConfiguration.setWorkerIdentifier("cool-worker"); - when(credentialsProvider.resolveCredentials()).thenReturn(creds); - when(creds.accessKeyId()).thenReturn("cool-user"); - when(configurator.getConfiguration(any(Properties.class))).thenReturn(multiLangDaemonConfiguration); - } + /** + * Instantiate a MultiLangDaemonConfig object + * @param streamName + * @param streamArn + * @throws IOException + */ + public void setup(String streamName, String streamArn) throws IOException { - @Test - public void constructorTest() throws IOException { - String PROPERTIES = "executableName = randomEXE \n" + "applicationName = testApp \n" - + "streamName = fakeStream \n" + "AWSCredentialsProvider = DefaultAWSCredentialsProviderChain\n" - + "processingLanguage = malbolge"; - ClassLoader classLoader = Mockito.mock(ClassLoader.class); + String properties = String.format("executableName = %s\n" + + "applicationName = %s\n" + + "AWSCredentialsProvider = DefaultAWSCredentialsProviderChain\n" + + "processingLanguage = malbolge\n" + + "regionName = %s\n", + EXE, + APPLICATION_NAME, + "us-east-1"); - Mockito.doReturn(new ByteArrayInputStream(PROPERTIES.getBytes())).when(classLoader) + if (streamName != null) { + properties += String.format("streamName = %s\n", streamName); + } + if (streamArn != null) { + properties += String.format("streamArn = %s\n", streamArn); + } + classLoader = Mockito.mock(ClassLoader.class); + + Mockito.doReturn(new ByteArrayInputStream(properties.getBytes())).when(classLoader) .getResourceAsStream(FILENAME); - MultiLangDaemonConfig deamonConfig = new MultiLangDaemonConfig(FILENAME, classLoader, configurator); + when(credentialsProvider.resolveCredentials()).thenReturn(creds); + when(creds.accessKeyId()).thenReturn("cool-user"); + configurator = new KinesisClientLibConfigurator(); - assertNotNull(deamonConfig.getExecutorService()); - assertNotNull(deamonConfig.getMultiLangDaemonConfiguration()); - assertNotNull(deamonConfig.getRecordProcessorFactory()); + deamonConfig = new MultiLangDaemonConfig(FILENAME, classLoader, configurator); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorFailsBecauseStreamArnIsInvalid() throws Exception { + setup("", "this_is_not_a_valid_arn"); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorFailsBecauseStreamArnIsInvalid2() throws Exception { + setup("", "arn:aws:kinesis:us-east-2:ACCOUNT_ID:BadFormatting:stream/" + STREAM_NAME_IN_ARN); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorFailsBecauseStreamNameAndArnAreEmpty() throws Exception { + setup("", ""); + } + + @Test(expected = NullPointerException.class) + public void testConstructorFailsBecauseStreamNameAndArnAreNull() throws Exception { + setup(null, null); + } + + @Test(expected = NullPointerException.class) + public void testConstructorFailsBecauseStreamNameIsNullAndArnIsEmpty() throws Exception { + setup(null, ""); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorFailsBecauseStreamNameIsEmptyAndArnIsNull() throws Exception { + setup("", null); } @Test - public void propertyValidation() { + public void testConstructorUsingStreamName() throws IOException { + setup(STREAM_NAME, null); + + assertConfigurationsMatch(STREAM_NAME, null); + } + + @Test + public void testConstructorUsingStreamNameAndStreamArnIsEmpty() throws IOException { + setup(STREAM_NAME, ""); + + assertConfigurationsMatch(STREAM_NAME, ""); + } + + @Test + public void testConstructorUsingStreamNameAndStreamArnIsWhitespace() throws IOException { + setup(STREAM_NAME, " "); + + assertConfigurationsMatch(STREAM_NAME, ""); + } + + @Test + public void testConstructorUsingStreamArn() throws IOException { + setup(null, STREAM_ARN); + + assertConfigurationsMatch(STREAM_NAME_IN_ARN, STREAM_ARN); + } + + @Test + public void testConstructorUsingStreamNameAsEmptyAndStreamArn() throws IOException { + setup("", STREAM_ARN); + + assertConfigurationsMatch(STREAM_NAME_IN_ARN, STREAM_ARN); + } + + @Test + public void testConstructorUsingStreamArnOverStreamName() throws IOException { + setup(STREAM_NAME, STREAM_ARN); + + assertConfigurationsMatch(STREAM_NAME_IN_ARN, STREAM_ARN); + } + + /** + * Verify the daemonConfig properties are what we expect them to be. + * @param deamonConfig + * @param expectedStreamName + */ + private void assertConfigurationsMatch(String expectedStreamName, String expectedStreamArn) { + final MultiLangDaemonConfiguration multiLangConfiguration = deamonConfig.getMultiLangDaemonConfiguration(); + assertNotNull(deamonConfig.getExecutorService()); + assertNotNull(multiLangConfiguration); + assertNotNull(deamonConfig.getRecordProcessorFactory()); + + assertEquals(EXE, deamonConfig.getRecordProcessorFactory().getCommandArray()[0]); + assertEquals(APPLICATION_NAME, multiLangConfiguration.getApplicationName()); + assertEquals(expectedStreamName, multiLangConfiguration.getStreamName()); + assertEquals(REGION, multiLangConfiguration.getDynamoDbClient().get("region")); + assertEquals(REGION, multiLangConfiguration.getCloudWatchClient().get("region")); + assertEquals(REGION, multiLangConfiguration.getKinesisClient().get("region")); + assertEquals(expectedStreamArn, multiLangConfiguration.getStreamArn()); + } + + @Test + public void testPropertyValidation() { String PROPERTIES_NO_EXECUTABLE_NAME = "applicationName = testApp \n" + "streamName = fakeStream \n" + "AWSCredentialsProvider = DefaultAWSCredentialsProviderChain\n" + "processingLanguage = malbolge"; ClassLoader classLoader = Mockito.mock(ClassLoader.class); @@ -99,4 +202,4 @@ public class MultiLangDaemonConfigTest { } } -} +} \ No newline at end of file diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonTest.java index 0c1d0b60..3229e2b8 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonTest.java @@ -17,7 +17,6 @@ package software.amazon.kinesis.multilang; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; import static org.mockito.Matchers.anyObject; diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java index dc6166aa..d385b2f9 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -61,10 +60,8 @@ import software.amazon.kinesis.multilang.messages.ShardEndedMessage; import software.amazon.kinesis.multilang.messages.StatusMessage; import com.google.common.util.concurrent.SettableFuture; -import software.amazon.kinesis.coordinator.KinesisClientLibConfiguration; import software.amazon.kinesis.lifecycle.events.InitializationInput; import software.amazon.kinesis.lifecycle.events.ProcessRecordsInput; -import software.amazon.kinesis.lifecycle.ShutdownReason; import software.amazon.kinesis.processor.RecordProcessorCheckpointer; import software.amazon.kinesis.retrieval.KinesisClientRecord; diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java index b3bb0719..bffd431d 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java @@ -27,8 +27,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import software.amazon.kinesis.multilang.DrainChildSTDERRTask; -import software.amazon.kinesis.multilang.LineReaderTask; public class ReadSTDERRTaskTest { diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorFactoryTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorFactoryTest.java index 7a7d7b11..1954cf91 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorFactoryTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorFactoryTest.java @@ -14,12 +14,9 @@ */ package software.amazon.kinesis.multilang; -import software.amazon.kinesis.coordinator.KinesisClientLibConfiguration; import org.junit.Assert; import org.junit.Test; -import software.amazon.kinesis.multilang.MultiLangRecordProcessorFactory; -import software.amazon.kinesis.multilang.MultiLangShardRecordProcessor; import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration; import software.amazon.kinesis.processor.ShardRecordProcessor; import org.junit.runner.RunWith; diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoderTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoderTest.java index 8da22d53..36f496d3 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoderTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoderTest.java @@ -16,7 +16,6 @@ package software.amazon.kinesis.multilang.config; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import java.util.Arrays; @@ -32,11 +31,6 @@ import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.AWSCredentialsProviderChain; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.AwsCredentials; -import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; -import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain; - public class AWSCredentialsProviderPropertyValueDecoderTest { private static final String TEST_ACCESS_KEY_ID = "123"; diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfiguratorTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfiguratorTest.java index 031fc427..1f05240a 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfiguratorTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfiguratorTest.java @@ -278,10 +278,8 @@ public class KinesisClientLibConfiguratorTest { } } - @Test + @Test(expected = IllegalArgumentException.class) public void testWithMissingCredentialsProvider() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("A basic set of AWS credentials must be provided"); String test = StringUtils.join(new String[] { "streamName = a", "applicationName = b", "workerId = 123", "failoverTimeMillis = 100", "shardSyncIntervalMillis = 500" }, '\n'); @@ -305,22 +303,37 @@ public class KinesisClientLibConfiguratorTest { assertFalse(config.getWorkerIdentifier().isEmpty()); } - @Test - public void testWithMissingStreamName() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("Stream name is required"); - - String test = StringUtils.join(new String[] { "applicationName = b", - "AWSCredentialsProvider = " + credentialName1, "workerId = 123", "failoverTimeMillis = 100" }, '\n'); + @Test(expected = NullPointerException.class) + public void testWithMissingStreamNameAndMissingStreamArn() { + String test = StringUtils.join(new String[] { + "applicationName = b", + "AWSCredentialsProvider = " + credentialName1, + "workerId = 123", + "failoverTimeMillis = 100" }, + '\n'); InputStream input = new ByteArrayInputStream(test.getBytes()); configurator.getConfiguration(input); } - @Test + @Test(expected = IllegalArgumentException.class) + public void testWithEmptyStreamNameAndMissingStreamArn() { + + String test = StringUtils.join(new String[] { + "applicationName = b", + "AWSCredentialsProvider = " + credentialName1, + "workerId = 123", + "failoverTimeMillis = 100", + "streamName = ", + "streamArn = "}, + '\n'); + InputStream input = new ByteArrayInputStream(test.getBytes()); + + configurator.getConfiguration(input); + } + + @Test(expected = NullPointerException.class) public void testWithMissingApplicationName() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("Application name is required"); String test = StringUtils.join(new String[] { "streamName = a", "AWSCredentialsProvider = " + credentialName1, "workerId = 123", "failoverTimeMillis = 100" }, '\n'); @@ -493,4 +506,4 @@ public class KinesisClientLibConfiguratorTest { MultiLangDaemonConfiguration config = configurator.getConfiguration(input); return config; } -} +} \ No newline at end of file diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java index 47337221..86798080 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java @@ -26,13 +26,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import software.amazon.kinesis.lifecycle.events.InitializationInput; import software.amazon.kinesis.lifecycle.events.ProcessRecordsInput; import software.amazon.kinesis.lifecycle.ShutdownReason; -import software.amazon.kinesis.multilang.messages.CheckpointMessage; -import software.amazon.kinesis.multilang.messages.InitializeMessage; -import software.amazon.kinesis.multilang.messages.Message; -import software.amazon.kinesis.multilang.messages.ProcessRecordsMessage; -import software.amazon.kinesis.multilang.messages.ShutdownMessage; -import software.amazon.kinesis.multilang.messages.ShutdownRequestedMessage; -import software.amazon.kinesis.multilang.messages.StatusMessage; import software.amazon.kinesis.retrieval.KinesisClientRecord; public class MessageTest { diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamIdentifier.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamIdentifier.java index 8307ed82..82cef04b 100644 --- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamIdentifier.java +++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamIdentifier.java @@ -167,12 +167,22 @@ public class StreamIdentifier { .build(); } - private static void validateArn(Arn streamArn) { + /** + * Verify the streamArn follows the appropriate formatting. + * Throw an exception if it does not. + * @param streamArn + */ + public static void validateArn(Arn streamArn) { if (!STREAM_ARN_PATTERN.matcher(streamArn.toString()).matches() || !streamArn.region().isPresent()) { - throw new IllegalArgumentException("Unable to create a StreamIdentifier from " + streamArn); + throw new IllegalArgumentException("Invalid streamArn " + streamArn); } } + /** + * Verify creationEpoch is greater than 0. + * Throw an exception if it is not. + * @param creationEpoch + */ private static void validateCreationEpoch(long creationEpoch) { if (creationEpoch <= 0) { throw new IllegalArgumentException( From 5105317eb4b8a012feec32209920b6b31e364d0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Jun 2023 15:11:34 -0400 Subject: [PATCH 4/9] Bump guava from 31.1-jre to 32.0.0-jre in /amazon-kinesis-client (#1142) Bumps [guava](https://github.com/google/guava) from 31.1-jre to 32.0.0-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- amazon-kinesis-client/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amazon-kinesis-client/pom.xml b/amazon-kinesis-client/pom.xml index 3eb8ad94..30824281 100644 --- a/amazon-kinesis-client/pom.xml +++ b/amazon-kinesis-client/pom.xml @@ -88,7 +88,7 @@ com.google.guava guava - 31.1-jre + 32.0.0-jre com.google.protobuf From 74d8f4b780a53af09830acc957248902ede44248 Mon Sep 17 00:00:00 2001 From: stair <123031771+stair-aws@users.noreply.github.com> Date: Mon, 26 Jun 2023 15:25:10 -0400 Subject: [PATCH 5/9] Enabled Checkstyle validation of test resources. (#1150) No functional change. --- .../kinesis/multilang/MessageReaderTest.java | 21 ++++---- .../kinesis/multilang/MessageWriterTest.java | 14 +++--- .../multilang/MultiLangDaemonConfigTest.java | 9 ++-- .../kinesis/multilang/ReadSTDERRTaskTest.java | 8 +-- .../StreamingShardRecordProcessorTest.java | 50 ++++++++----------- .../kinesis/checkpoint/CheckpointerTest.java | 10 ++-- .../checkpoint/InMemoryCheckpointer.java | 14 +++--- ...dShardRecordProcessorCheckpointerTest.java | 34 ++++++------- ...sticShuffleShardSyncLeaderDeciderTest.java | 2 +- .../coordinator/DiagnosticEventsTest.java | 8 +-- .../PeriodicShardSyncManagerTest.java | 14 +++--- .../kinesis/coordinator/SchedulerTest.java | 22 ++++---- .../kinesis/coordinator/WorkerTest.java | 21 ++++---- .../leases/HierarchicalShardSyncerTest.java | 22 +++++--- .../leases/LeaseCoordinatorExerciser.java | 15 +++--- .../kinesis/leases/ShardObjectHelper.java | 6 +-- ...llingModePayPerRequestIntegrationTest.java | 2 +- .../DynamoDBLeaseRenewerIntegrationTest.java | 2 +- .../dynamodb/DynamoDBLeaseRenewerTest.java | 2 +- .../metrics/MetricAccumulatingQueueTest.java | 4 +- .../fanout/FanOutRecordsPublisherTest.java | 42 +++++++++------- .../polling/KinesisDataFetcherTest.java | 2 +- ...efetchRecordsPublisherIntegrationTest.java | 4 +- .../polling/PrefetchRecordsPublisherTest.java | 16 +++--- .../amazon/kinesis/utils/BlockingUtils.java | 6 +-- .../utils/SubscribeToShardRequestMatcher.java | 2 +- checkstyle/checkstyle.xml | 5 +- pom.xml | 1 + 28 files changed, 183 insertions(+), 175 deletions(-) diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java index 14ac357c..f6fab4c1 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageReaderTest.java @@ -34,9 +34,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class MessageReaderTest { - private static final String shardId = "shard-123"; + private static final String SHARD_ID = "shard-123"; - /* + /** * This line is based on the definition of the protocol for communication between the KCL record processor and * the client's process. */ @@ -44,7 +44,7 @@ public class MessageReaderTest { return String.format("{\"action\":\"checkpoint\", \"checkpoint\":\"%s\"}", sequenceNumber); } - /* + /** * This line is based on the definition of the protocol for communication between the KCL record processor and * the client's process. */ @@ -79,10 +79,9 @@ public class MessageReaderTest { String[] responseFors = new String[] { "initialize", "processRecords", "processRecords", "shutdown" }; InputStream stream = buildInputStreamOfGoodInput(sequenceNumbers, responseFors); MessageReader reader = - new MessageReader().initialize(stream, shardId, new ObjectMapper(), Executors.newCachedThreadPool()); + new MessageReader().initialize(stream, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool()); for (String responseFor : responseFors) { - StatusMessage statusMessage = null; try { Message message = reader.getNextMessageFromSTDOUT().get(); if (message instanceof StatusMessage) { @@ -102,14 +101,14 @@ public class MessageReaderTest { InputStream stream = buildInputStreamOfGoodInput(sequenceNumbers, responseFors); MessageReader reader = - new MessageReader().initialize(stream, shardId, new ObjectMapper(), Executors.newCachedThreadPool()); + new MessageReader().initialize(stream, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool()); Future drainFuture = reader.drainSTDOUT(); Boolean drainResult = drainFuture.get(); Assert.assertNotNull(drainResult); Assert.assertTrue(drainResult); } - /* + /** * readValue should fail safely and just continue looping */ @Test @@ -134,7 +133,7 @@ public class MessageReaderTest { } MessageReader reader = - new MessageReader().initialize(bufferReader, shardId, new ObjectMapper(), + new MessageReader().initialize(bufferReader, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool()); try { @@ -149,7 +148,7 @@ public class MessageReaderTest { public void messageReaderBuilderTest() { InputStream stream = new ByteArrayInputStream("".getBytes()); MessageReader reader = - new MessageReader().initialize(stream, shardId, new ObjectMapper(), Executors.newCachedThreadPool()); + new MessageReader().initialize(stream, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool()); Assert.assertNotNull(reader); } @@ -158,7 +157,7 @@ public class MessageReaderTest { BufferedReader input = Mockito.mock(BufferedReader.class); Mockito.doThrow(IOException.class).when(input).readLine(); MessageReader reader = - new MessageReader().initialize(input, shardId, new ObjectMapper(), Executors.newCachedThreadPool()); + new MessageReader().initialize(input, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool()); Future readTask = reader.getNextMessageFromSTDOUT(); @@ -176,7 +175,7 @@ public class MessageReaderTest { public void noMoreMessagesTest() throws InterruptedException { InputStream stream = new ByteArrayInputStream("".getBytes()); MessageReader reader = - new MessageReader().initialize(stream, shardId, new ObjectMapper(), Executors.newCachedThreadPool()); + new MessageReader().initialize(stream, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool()); Future future = reader.getNextMessageFromSTDOUT(); try { diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java index eaf6be7b..c997c193 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java @@ -44,7 +44,7 @@ import static org.mockito.Mockito.verify; public class MessageWriterTest { - private static final String shardId = "shard-123"; + private static final String SHARD_ID = "shard-123"; MessageWriter messageWriter; OutputStream stream; @@ -57,7 +57,7 @@ public class MessageWriterTest { public void setup() { stream = Mockito.mock(OutputStream.class); messageWriter = - new MessageWriter().initialize(stream, shardId, new ObjectMapper(), Executors.newCachedThreadPool()); + new MessageWriter().initialize(stream, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool()); } /* @@ -83,7 +83,7 @@ public class MessageWriterTest { @Test public void writeInitializeMessageTest() throws IOException, InterruptedException, ExecutionException { - Future future = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(shardId).build()); + Future future = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(SHARD_ID).build()); future.get(); verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt()); @@ -128,20 +128,20 @@ public class MessageWriterTest { @Test public void streamIOExceptionTest() throws IOException, InterruptedException, ExecutionException { Mockito.doThrow(IOException.class).when(stream).flush(); - Future initializeTask = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(shardId).build()); + Future initializeTask = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(SHARD_ID).build()); Boolean result = initializeTask.get(); Assert.assertNotNull(result); Assert.assertFalse(result); } @Test - public void objectMapperFails() throws JsonProcessingException, InterruptedException, ExecutionException { + public void objectMapperFails() throws JsonProcessingException { thrown.expect(RuntimeException.class); thrown.expectMessage("Encountered I/O error while writing LeaseLostMessage action to subprocess"); ObjectMapper mapper = Mockito.mock(ObjectMapper.class); Mockito.doThrow(JsonProcessingException.class).when(mapper).writeValueAsString(Mockito.any(Message.class)); - messageWriter = new MessageWriter().initialize(stream, shardId, mapper, Executors.newCachedThreadPool()); + messageWriter = new MessageWriter().initialize(stream, SHARD_ID, mapper, Executors.newCachedThreadPool()); messageWriter.writeLeaseLossMessage(LeaseLostInput.builder().build()); } @@ -154,7 +154,7 @@ public class MessageWriterTest { Assert.assertFalse(this.messageWriter.isOpen()); try { // Any message should fail - this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(shardId).build()); + this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(SHARD_ID).build()); Assert.fail("MessageWriter should be closed and unable to write."); } catch (IllegalStateException e) { // This should happen. diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java index c6be1157..c5740a2f 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangDaemonConfigTest.java @@ -164,7 +164,7 @@ public class MultiLangDaemonConfigTest { /** * Verify the daemonConfig properties are what we expect them to be. - * @param deamonConfig + * * @param expectedStreamName */ private void assertConfigurationsMatch(String expectedStreamName, String expectedStreamArn) { @@ -184,16 +184,15 @@ public class MultiLangDaemonConfigTest { @Test public void testPropertyValidation() { - String PROPERTIES_NO_EXECUTABLE_NAME = "applicationName = testApp \n" + "streamName = fakeStream \n" + String propertiesNoExecutableName = "applicationName = testApp \n" + "streamName = fakeStream \n" + "AWSCredentialsProvider = DefaultAWSCredentialsProviderChain\n" + "processingLanguage = malbolge"; ClassLoader classLoader = Mockito.mock(ClassLoader.class); - Mockito.doReturn(new ByteArrayInputStream(PROPERTIES_NO_EXECUTABLE_NAME.getBytes())).when(classLoader) + Mockito.doReturn(new ByteArrayInputStream(propertiesNoExecutableName.getBytes())).when(classLoader) .getResourceAsStream(FILENAME); - MultiLangDaemonConfig config; try { - config = new MultiLangDaemonConfig(FILENAME, classLoader, configurator); + new MultiLangDaemonConfig(FILENAME, classLoader, configurator); Assert.fail("Construction of the config should have failed due to property validation failing."); } catch (IllegalArgumentException e) { // Good diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java index bffd431d..45ff3052 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/ReadSTDERRTaskTest.java @@ -30,7 +30,7 @@ import org.mockito.Mockito; public class ReadSTDERRTaskTest { - private static final String shardId = "shard-123"; + private static final String SHARD_ID = "shard-123"; private BufferedReader mockBufferReader; @Before @@ -43,7 +43,7 @@ public class ReadSTDERRTaskTest { String errorMessages = "OMG\nThis is test message\n blah blah blah \n"; InputStream stream = new ByteArrayInputStream(errorMessages.getBytes()); - LineReaderTask reader = new DrainChildSTDERRTask().initialize(stream, shardId, ""); + LineReaderTask reader = new DrainChildSTDERRTask().initialize(stream, SHARD_ID, ""); Assert.assertNotNull(reader); } @@ -52,7 +52,7 @@ public class ReadSTDERRTaskTest { String errorMessages = "OMG\nThis is test message\n blah blah blah \n"; BufferedReader bufferReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(errorMessages.getBytes()))); - LineReaderTask errorReader = new DrainChildSTDERRTask().initialize(bufferReader, shardId, ""); + LineReaderTask errorReader = new DrainChildSTDERRTask().initialize(bufferReader, SHARD_ID, ""); Assert.assertNotNull(errorReader); Boolean result = errorReader.call(); @@ -65,7 +65,7 @@ public class ReadSTDERRTaskTest { } catch (IOException e) { Assert.fail("Not supposed to get an exception when we're just building our mock."); } - LineReaderTask errorReader = new DrainChildSTDERRTask().initialize(mockBufferReader, shardId, ""); + LineReaderTask errorReader = new DrainChildSTDERRTask().initialize(mockBufferReader, SHARD_ID, ""); Assert.assertNotNull(errorReader); Future result = Executors.newCachedThreadPool().submit(errorReader); Boolean finishedCleanly = null; diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorTest.java index e3368e07..caa925b0 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/StreamingShardRecordProcessorTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Collections; @@ -46,9 +45,7 @@ import org.mockito.stubbing.Answer; import com.fasterxml.jackson.databind.ObjectMapper; import software.amazon.awssdk.services.kinesis.model.Record; -import software.amazon.kinesis.exceptions.InvalidStateException; import software.amazon.kinesis.exceptions.KinesisClientLibDependencyException; -import software.amazon.kinesis.exceptions.ShutdownException; import software.amazon.kinesis.exceptions.ThrottlingException; import software.amazon.kinesis.lifecycle.events.InitializationInput; import software.amazon.kinesis.lifecycle.events.LeaseLostInput; @@ -67,7 +64,7 @@ import software.amazon.kinesis.retrieval.KinesisClientRecord; @RunWith(MockitoJUnitRunner.class) public class StreamingShardRecordProcessorTest { - private static final String shardId = "shard-123"; + private static final String SHARD_ID = "shard-123"; private int systemExitCount = 0; @@ -79,77 +76,73 @@ public class StreamingShardRecordProcessorTest { private RecordProcessorCheckpointer unimplementedCheckpointer = new RecordProcessorCheckpointer() { @Override - public void checkpoint() throws KinesisClientLibDependencyException, InvalidStateException, - ThrottlingException, ShutdownException { + public void checkpoint() throws KinesisClientLibDependencyException, ThrottlingException { throw new UnsupportedOperationException(); } @Override public void checkpoint(String sequenceNumber) throws KinesisClientLibDependencyException, - InvalidStateException, ThrottlingException, ShutdownException, IllegalArgumentException { + ThrottlingException, IllegalArgumentException { throw new UnsupportedOperationException(); } @Override public void checkpoint(Record record) - throws KinesisClientLibDependencyException, - InvalidStateException, ThrottlingException, ShutdownException { + throws KinesisClientLibDependencyException, ThrottlingException { throw new UnsupportedOperationException(); } @Override public void checkpoint(String sequenceNumber, long subSequenceNumber) - throws KinesisClientLibDependencyException, - InvalidStateException, ThrottlingException, ShutdownException, - IllegalArgumentException { + throws KinesisClientLibDependencyException, ThrottlingException, IllegalArgumentException { throw new UnsupportedOperationException(); } @Override public PreparedCheckpointer prepareCheckpoint() - throws KinesisClientLibDependencyException, - InvalidStateException, ThrottlingException, ShutdownException { + throws KinesisClientLibDependencyException, ThrottlingException { throw new UnsupportedOperationException(); } @Override - public PreparedCheckpointer prepareCheckpoint(byte[] applicationState) throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { + public PreparedCheckpointer prepareCheckpoint(byte[] applicationState) + throws KinesisClientLibDependencyException, ThrottlingException { throw new UnsupportedOperationException(); } @Override public PreparedCheckpointer prepareCheckpoint(Record record) - throws KinesisClientLibDependencyException, - InvalidStateException, ThrottlingException, ShutdownException { + throws KinesisClientLibDependencyException, ThrottlingException { throw new UnsupportedOperationException(); } @Override - public PreparedCheckpointer prepareCheckpoint(Record record, byte[] applicationState) throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { + public PreparedCheckpointer prepareCheckpoint(Record record, byte[] applicationState) + throws KinesisClientLibDependencyException, ThrottlingException { throw new UnsupportedOperationException(); } @Override public PreparedCheckpointer prepareCheckpoint(String sequenceNumber) - throws KinesisClientLibDependencyException, - InvalidStateException, ThrottlingException, ShutdownException, IllegalArgumentException { + throws KinesisClientLibDependencyException, ThrottlingException, IllegalArgumentException { throw new UnsupportedOperationException(); } @Override - public PreparedCheckpointer prepareCheckpoint(String sequenceNumber, byte[] applicationState) throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException, IllegalArgumentException { + public PreparedCheckpointer prepareCheckpoint(String sequenceNumber, byte[] applicationState) + throws KinesisClientLibDependencyException, ThrottlingException, IllegalArgumentException { return null; } @Override public PreparedCheckpointer prepareCheckpoint(String sequenceNumber, long subSequenceNumber) - throws KinesisClientLibDependencyException, - InvalidStateException, ThrottlingException, ShutdownException, IllegalArgumentException { + throws KinesisClientLibDependencyException, ThrottlingException, IllegalArgumentException { throw new UnsupportedOperationException(); } @Override - public PreparedCheckpointer prepareCheckpoint(String sequenceNumber, long subSequenceNumber, byte[] applicationState) throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException, IllegalArgumentException { + public PreparedCheckpointer prepareCheckpoint(String sequenceNumber, long subSequenceNumber, byte[] applicationState) + throws KinesisClientLibDependencyException, ThrottlingException, IllegalArgumentException { throw new UnsupportedOperationException(); } @@ -171,7 +164,7 @@ public class StreamingShardRecordProcessorTest { private MultiLangDaemonConfiguration configuration; @Before - public void prepare() throws IOException, InterruptedException, ExecutionException { + public void prepare() throws InterruptedException, ExecutionException { // Fake command systemExitCount = 0; @@ -230,7 +223,7 @@ public class StreamingShardRecordProcessorTest { List testRecords = Collections.emptyList(); - recordProcessor.initialize(InitializationInput.builder().shardId(shardId).build()); + recordProcessor.initialize(InitializationInput.builder().shardId(SHARD_ID).build()); recordProcessor.processRecords(ProcessRecordsInput.builder().records(testRecords) .checkpointer(unimplementedCheckpointer).build()); recordProcessor.processRecords(ProcessRecordsInput.builder().records(testRecords) @@ -240,7 +233,6 @@ public class StreamingShardRecordProcessorTest { @Test public void processorPhasesTest() throws InterruptedException, ExecutionException { - Answer answer = new Answer() { StatusMessage[] answers = new StatusMessage[] { new StatusMessage(InitializeMessage.ACTION), @@ -263,7 +255,7 @@ public class StreamingShardRecordProcessorTest { verify(messageWriter) .writeInitializeMessage(argThat(Matchers.withInit( - InitializationInput.builder().shardId(shardId).build()))); + InitializationInput.builder().shardId(SHARD_ID).build()))); verify(messageWriter, times(2)).writeProcessRecordsMessage(any(ProcessRecordsInput.class)); verify(messageWriter).writeLeaseLossMessage(any(LeaseLostInput.class)); } @@ -295,7 +287,7 @@ public class StreamingShardRecordProcessorTest { phases(answer); verify(messageWriter).writeInitializeMessage(argThat(Matchers.withInit(InitializationInput.builder() - .shardId(shardId).build()))); + .shardId(SHARD_ID).build()))); verify(messageWriter, times(2)).writeProcessRecordsMessage(any(ProcessRecordsInput.class)); verify(messageWriter, never()).writeLeaseLossMessage(any(LeaseLostInput.class)); Assert.assertEquals(1, systemExitCount); diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/CheckpointerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/CheckpointerTest.java index b823c8e3..eb341238 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/CheckpointerTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/CheckpointerTest.java @@ -37,9 +37,9 @@ public class CheckpointerTest { @Test public final void testInitialSetCheckpoint() throws Exception { - String sequenceNumber = "1"; + String sequenceNumber = "1"; String shardId = "myShardId"; - ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber(sequenceNumber); + ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber(sequenceNumber); checkpoint.setCheckpoint(shardId, new ExtendedSequenceNumber(sequenceNumber), testConcurrencyToken); ExtendedSequenceNumber registeredCheckpoint = checkpoint.getCheckpoint(shardId); Assert.assertEquals(extendedSequenceNumber, registeredCheckpoint); @@ -49,8 +49,8 @@ public class CheckpointerTest { public final void testAdvancingSetCheckpoint() throws Exception { String shardId = "myShardId"; for (Integer i = 0; i < 10; i++) { - String sequenceNumber = i.toString(); - ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber(sequenceNumber); + String sequenceNumber = i.toString(); + ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber(sequenceNumber); checkpoint.setCheckpoint(shardId, new ExtendedSequenceNumber(sequenceNumber), testConcurrencyToken); ExtendedSequenceNumber registeredCheckpoint = checkpoint.getCheckpoint(shardId); Assert.assertEquals(extendedSequenceNumber, registeredCheckpoint); @@ -67,7 +67,7 @@ public class CheckpointerTest { String checkpointValue = "12345"; String shardId = "testShardId-1"; String concurrencyToken = "token-1"; - ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber(checkpointValue); + ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber(checkpointValue); checkpoint.setCheckpoint(shardId, new ExtendedSequenceNumber(checkpointValue), concurrencyToken); Assert.assertEquals(extendedSequenceNumber, checkpoint.getCheckpoint(shardId)); Assert.assertEquals(extendedSequenceNumber, checkpoint.getCheckpointObject(shardId).checkpoint()); diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java index 8f6e165d..a2d83568 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java @@ -39,8 +39,7 @@ public class InMemoryCheckpointer implements Checkpointer { * {@inheritDoc} */ @Override - public void setCheckpoint(String leaseKey, ExtendedSequenceNumber checkpointValue, String concurrencyToken) - throws KinesisClientLibException { + public void setCheckpoint(String leaseKey, ExtendedSequenceNumber checkpointValue, String concurrencyToken) { checkpoints.put(leaseKey, checkpointValue); flushpoints.put(leaseKey, checkpointValue); pendingCheckpoints.remove(leaseKey); @@ -49,33 +48,32 @@ public class InMemoryCheckpointer implements Checkpointer { if (log.isDebugEnabled()) { log.debug("shardId: {} checkpoint: {}", leaseKey, checkpointValue); } - } /** * {@inheritDoc} */ @Override - public ExtendedSequenceNumber getCheckpoint(String leaseKey) throws KinesisClientLibException { + public ExtendedSequenceNumber getCheckpoint(String leaseKey) { ExtendedSequenceNumber checkpoint = flushpoints.get(leaseKey); log.debug("checkpoint shardId: {} checkpoint: {}", leaseKey, checkpoint); return checkpoint; } @Override - public void prepareCheckpoint(String leaseKey, ExtendedSequenceNumber pendingCheckpoint, String concurrencyToken) - throws KinesisClientLibException { + public void prepareCheckpoint(String leaseKey, ExtendedSequenceNumber pendingCheckpoint, String concurrencyToken) { prepareCheckpoint(leaseKey, pendingCheckpoint, concurrencyToken, null); } @Override - public void prepareCheckpoint(String leaseKey, ExtendedSequenceNumber pendingCheckpoint, String concurrencyToken, byte[] pendingCheckpointState) throws KinesisClientLibException { + public void prepareCheckpoint(String leaseKey, ExtendedSequenceNumber pendingCheckpoint, String concurrencyToken, + byte[] pendingCheckpointState) { pendingCheckpoints.put(leaseKey, pendingCheckpoint); pendingCheckpointStates.put(leaseKey, pendingCheckpointState); } @Override - public Checkpoint getCheckpointObject(String leaseKey) throws KinesisClientLibException { + public Checkpoint getCheckpointObject(String leaseKey) { ExtendedSequenceNumber checkpoint = flushpoints.get(leaseKey); ExtendedSequenceNumber pendingCheckpoint = pendingCheckpoints.get(leaseKey); byte[] pendingCheckpointState = pendingCheckpointStates.get(leaseKey); diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java index 2ff82004..37a40b6b 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java @@ -91,11 +91,11 @@ public class ShardShardRecordProcessorCheckpointerTest { */ @Test public final void testCheckpointRecord() throws Exception { - ShardRecordProcessorCheckpointer processingCheckpointer = + ShardRecordProcessorCheckpointer processingCheckpointer = new ShardRecordProcessorCheckpointer(shardInfo, checkpoint); - processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); - ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5025"); - Record record = makeRecord("5025"); + processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); + ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5025"); + Record record = makeRecord("5025"); processingCheckpointer.largestPermittedCheckpointValue(extendedSequenceNumber); processingCheckpointer.checkpoint(record); assertThat(checkpoint.getCheckpoint(shardId), equalTo(extendedSequenceNumber)); @@ -107,13 +107,13 @@ public class ShardShardRecordProcessorCheckpointerTest { */ @Test public final void testCheckpointSubRecord() throws Exception { - ShardRecordProcessorCheckpointer processingCheckpointer = + ShardRecordProcessorCheckpointer processingCheckpointer = new ShardRecordProcessorCheckpointer(shardInfo, checkpoint); - processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); - ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5030"); - Record record = makeRecord("5030"); + processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); + ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5030"); + Record record = makeRecord("5030"); //UserRecord subRecord = new UserRecord(record); - processingCheckpointer.largestPermittedCheckpointValue(extendedSequenceNumber); + processingCheckpointer.largestPermittedCheckpointValue(extendedSequenceNumber); processingCheckpointer.checkpoint(record); assertThat(checkpoint.getCheckpoint(shardId), equalTo(extendedSequenceNumber)); } @@ -124,11 +124,11 @@ public class ShardShardRecordProcessorCheckpointerTest { */ @Test public final void testCheckpointSequenceNumber() throws Exception { - ShardRecordProcessorCheckpointer processingCheckpointer = + ShardRecordProcessorCheckpointer processingCheckpointer = new ShardRecordProcessorCheckpointer(shardInfo, checkpoint); - processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); - ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5035"); - processingCheckpointer.largestPermittedCheckpointValue(extendedSequenceNumber); + processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); + ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5035"); + processingCheckpointer.largestPermittedCheckpointValue(extendedSequenceNumber); processingCheckpointer.checkpoint("5035"); assertThat(checkpoint.getCheckpoint(shardId), equalTo(extendedSequenceNumber)); } @@ -139,11 +139,11 @@ public class ShardShardRecordProcessorCheckpointerTest { */ @Test public final void testCheckpointExtendedSequenceNumber() throws Exception { - ShardRecordProcessorCheckpointer processingCheckpointer = + ShardRecordProcessorCheckpointer processingCheckpointer = new ShardRecordProcessorCheckpointer(shardInfo, checkpoint); - processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); - ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5040"); - processingCheckpointer.largestPermittedCheckpointValue(extendedSequenceNumber); + processingCheckpointer.setInitialCheckpointValue(startingExtendedSequenceNumber); + ExtendedSequenceNumber extendedSequenceNumber = new ExtendedSequenceNumber("5040"); + processingCheckpointer.largestPermittedCheckpointValue(extendedSequenceNumber); processingCheckpointer.checkpoint("5040", 0); assertThat(checkpoint.getCheckpoint(shardId), equalTo(extendedSequenceNumber)); } diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDeciderTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDeciderTest.java index dff2a8cb..9508903b 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDeciderTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDeciderTest.java @@ -105,7 +105,7 @@ public class DeterministicShuffleShardSyncLeaderDeciderTest { @Test public void testElectedLeadersAsPerExpectedShufflingOrder() throws Exception { - List leases = getLeases(5, false /*emptyLeaseOwner */,false /* duplicateLeaseOwner */, true /* activeLeases */); + List leases = getLeases(5, false /*emptyLeaseOwner */, false /* duplicateLeaseOwner */, true /* activeLeases */); when(leaseRefresher.listLeases()).thenReturn(leases); Set expectedLeaders = getExpectedLeaders(leases); for (String leader : expectedLeaders) { diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DiagnosticEventsTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DiagnosticEventsTest.java index d6098cca..08ed8abb 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DiagnosticEventsTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/DiagnosticEventsTest.java @@ -86,7 +86,7 @@ public class DiagnosticEventsTest { assertEquals(event.getLargestPoolSize(), largestPoolSize); assertEquals(event.getMaximumPoolSize(), maximumPoolSize); assertEquals(event.getLeasesOwned(), leaseAssignments.size()); - assertEquals(event.getCurrentQueueSize(),0); + assertEquals(0, event.getCurrentQueueSize()); verify(defaultHandler, times(1)).visit(event); } @@ -110,7 +110,7 @@ public class DiagnosticEventsTest { assertEquals(event.getExecutorStateEvent().getLargestPoolSize(), largestPoolSize); assertEquals(event.getExecutorStateEvent().getMaximumPoolSize(), maximumPoolSize); assertEquals(event.getExecutorStateEvent().getLeasesOwned(), leaseAssignments.size()); - assertEquals(event.getExecutorStateEvent().getCurrentQueueSize(),0); + assertEquals(0, event.getExecutorStateEvent().getCurrentQueueSize()); assertTrue(event.getThrowable() instanceof TestRejectedTaskException); verify(defaultHandler, times(1)).visit(event); @@ -136,7 +136,7 @@ public class DiagnosticEventsTest { assertEquals(executorStateEvent.getLargestPoolSize(), largestPoolSize); assertEquals(executorStateEvent.getMaximumPoolSize(), maximumPoolSize); assertEquals(executorStateEvent.getLeasesOwned(), leaseAssignments.size()); - assertEquals(executorStateEvent.getCurrentQueueSize(),0); + assertEquals(0, executorStateEvent.getCurrentQueueSize()); RejectedTaskEvent rejectedTaskEvent = factory.rejectedTaskEvent(executorStateEvent, new TestRejectedTaskException()); @@ -145,7 +145,7 @@ public class DiagnosticEventsTest { assertEquals(rejectedTaskEvent.getExecutorStateEvent().getLargestPoolSize(), largestPoolSize); assertEquals(rejectedTaskEvent.getExecutorStateEvent().getMaximumPoolSize(), maximumPoolSize); assertEquals(rejectedTaskEvent.getExecutorStateEvent().getLeasesOwned(), leaseAssignments.size()); - assertEquals(rejectedTaskEvent.getExecutorStateEvent().getCurrentQueueSize(),0); + assertEquals(0, rejectedTaskEvent.getExecutorStateEvent().getCurrentQueueSize()); assertTrue(rejectedTaskEvent.getThrowable() instanceof TestRejectedTaskException); } diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManagerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManagerTest.java index f7492d8d..71375c3d 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManagerTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/PeriodicShardSyncManagerTest.java @@ -210,7 +210,7 @@ public class PeriodicShardSyncManagerTest { }}.stream().map(hashKeyRangeForLease -> { MultiStreamLease lease = new MultiStreamLease(); lease.hashKeyRange(hashKeyRangeForLease); - if(lease.hashKeyRangeForLease().startingHashKey().toString().equals("4")) { + if (lease.hashKeyRangeForLease().startingHashKey().toString().equals("4")) { lease.checkpoint(ExtendedSequenceNumber.SHARD_END); } else { lease.checkpoint(ExtendedSequenceNumber.TRIM_HORIZON); @@ -342,7 +342,7 @@ public class PeriodicShardSyncManagerTest { lease.leaseKey(MultiStreamLease.getLeaseKey(streamIdentifier.serialize(), "shard-"+(++leaseCounter[0]))); lease.shardId("shard-"+(leaseCounter[0])); // Setting the hashrange only for last two leases - if(leaseCounter[0] >= 3) { + if (leaseCounter[0] >= 3) { lease.hashKeyRange(hashKeyRangeForLease); } lease.checkpoint(ExtendedSequenceNumber.TRIM_HORIZON); @@ -355,7 +355,7 @@ public class PeriodicShardSyncManagerTest { Assert.assertFalse(periodicShardSyncManager.checkForShardSync(streamIdentifier, multiStreamLeases).shouldDoShardSync()); // Assert that all the leases now has hashRanges set. - for(Lease lease : multiStreamLeases) { + for (Lease lease : multiStreamLeases) { Assert.assertNotNull(lease.hashKeyRangeForLease()); } } @@ -390,7 +390,7 @@ public class PeriodicShardSyncManagerTest { lease.leaseKey(MultiStreamLease.getLeaseKey(streamIdentifier.serialize(), "shard-"+(++leaseCounter[0]))); lease.shardId("shard-"+(leaseCounter[0])); // Setting the hashrange only for last two leases - if(leaseCounter[0] >= 3) { + if (leaseCounter[0] >= 3) { lease.hashKeyRange(hashKeyRangeForLease); } lease.checkpoint(ExtendedSequenceNumber.TRIM_HORIZON); @@ -403,14 +403,14 @@ public class PeriodicShardSyncManagerTest { Assert.assertTrue(periodicShardSyncManager.checkForShardSync(streamIdentifier, multiStreamLeases).shouldDoShardSync()); // Assert that all the leases now has hashRanges set. - for(Lease lease : multiStreamLeases) { + for (Lease lease : multiStreamLeases) { Assert.assertNotNull(lease.hashKeyRangeForLease()); } } @Test public void testFor1000DifferentValidSplitHierarchyTreeTheHashRangesAreAlwaysComplete() { - for(int i=0; i < 1000; i++) { + for (int i=0; i < 1000; i++) { int maxInitialLeaseCount = 100; List leases = generateInitialLeases(maxInitialLeaseCount); reshard(leases, 5, ReshardType.SPLIT, maxInitialLeaseCount, false); @@ -514,7 +514,7 @@ public class PeriodicShardSyncManagerTest { for (int i = 0; i < leasesToMerge; i += 2) { Lease parent1 = leasesEligibleForMerge.get(i); Lease parent2 = leasesEligibleForMerge.get(i + 1); - if(parent2.hashKeyRangeForLease().startingHashKey().subtract(parent1.hashKeyRangeForLease().endingHashKey()).equals(BigInteger.ONE)) + if (parent2.hashKeyRangeForLease().startingHashKey().subtract(parent1.hashKeyRangeForLease().endingHashKey()).equals(BigInteger.ONE)) { parent1.checkpoint(ExtendedSequenceNumber.SHARD_END); if (!shouldKeepSomeParentsInProgress || (shouldKeepSomeParentsInProgress && isOneFromDiceRoll())) { diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/SchedulerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/SchedulerTest.java index 46918f62..3b5bfec9 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/SchedulerTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/SchedulerTest.java @@ -35,7 +35,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.internal.verification.VerificationModeFactory.atMost; -import static software.amazon.kinesis.processor.FormerStreamsLeasesDeletionStrategy.*; import java.time.Duration; import java.util.ArrayList; @@ -104,6 +103,9 @@ import software.amazon.kinesis.metrics.MetricsFactory; import software.amazon.kinesis.metrics.MetricsConfig; import software.amazon.kinesis.processor.Checkpointer; import software.amazon.kinesis.processor.FormerStreamsLeasesDeletionStrategy; +import software.amazon.kinesis.processor.FormerStreamsLeasesDeletionStrategy.AutoDetectionAndDeferredDeletionStrategy; +import software.amazon.kinesis.processor.FormerStreamsLeasesDeletionStrategy.NoLeaseDeletionStrategy; +import software.amazon.kinesis.processor.FormerStreamsLeasesDeletionStrategy.ProvidedStreamsDeferredDeletionStrategy; import software.amazon.kinesis.processor.MultiStreamTracker; import software.amazon.kinesis.processor.ProcessorConfig; import software.amazon.kinesis.processor.ShardRecordProcessorFactory; @@ -727,8 +729,8 @@ public class SchedulerTest { boolean expectPendingStreamsForDeletion, boolean onlyStreamsNoLeasesDeletion) throws DependencyException, ProvisionedThroughputException, InvalidStateException { - List streamConfigList1 = createDummyStreamConfigList(1,5); - List streamConfigList2 = createDummyStreamConfigList(3,7); + List streamConfigList1 = createDummyStreamConfigList(1, 5); + List streamConfigList2 = createDummyStreamConfigList(3, 7); retrievalConfig = new RetrievalConfig(kinesisClient, multiStreamTracker, applicationName) .retrievalFactory(retrievalFactory); when(multiStreamTracker.streamConfigList()).thenReturn(streamConfigList1, streamConfigList2); @@ -742,7 +744,7 @@ public class SchedulerTest { Joiner.on(":").join(streamId * 111111111, "multiStreamTest-" + streamId, streamId * 12345))) .collect(Collectors.toCollection(HashSet::new)); - if(onlyStreamsNoLeasesDeletion) { + if (onlyStreamsNoLeasesDeletion) { expectedSyncedStreams = IntStream.concat(IntStream.range(1, 3), IntStream.range(5, 7)) .mapToObj(streamId -> StreamIdentifier.multiStreamInstance( Joiner.on(":").join(streamId * 111111111, "multiStreamTest-" + streamId, streamId * 12345))) @@ -756,7 +758,7 @@ public class SchedulerTest { Assert.assertEquals(expectedSyncedStreams, syncedStreams); List expectedCurrentStreamConfigs; - if(onlyStreamsNoLeasesDeletion) { + if (onlyStreamsNoLeasesDeletion) { expectedCurrentStreamConfigs = IntStream.range(3, 7).mapToObj(streamId -> new StreamConfig( StreamIdentifier.multiStreamInstance( Joiner.on(":").join(streamId * 111111111, "multiStreamTest-" + streamId, streamId * 12345)), @@ -778,8 +780,8 @@ public class SchedulerTest { @Test public void testKinesisStaleDeletedStreamCleanup() throws ProvisionedThroughputException, InvalidStateException, DependencyException { - List streamConfigList1 = createDummyStreamConfigList(1,6); - List streamConfigList2 = createDummyStreamConfigList(1,4); + List streamConfigList1 = createDummyStreamConfigList(1, 6); + List streamConfigList2 = createDummyStreamConfigList(1, 4); prepareForStaleDeletedStreamCleanupTests(streamConfigList1, streamConfigList2); @@ -820,7 +822,7 @@ public class SchedulerTest { @Test public void testKinesisStaleDeletedStreamNoCleanUpForTrackedStream() throws ProvisionedThroughputException, InvalidStateException, DependencyException { - List streamConfigList1 = createDummyStreamConfigList(1,6); + List streamConfigList1 = createDummyStreamConfigList(1, 6); prepareForStaleDeletedStreamCleanupTests(streamConfigList1); scheduler.deletedStreamListProvider().add(createDummyStreamConfig(3).streamIdentifier()); @@ -1243,7 +1245,7 @@ public class SchedulerTest { @Override public ShardSyncTaskManager createShardSyncTaskManager(MetricsFactory metricsFactory, StreamConfig streamConfig, DeletedStreamListProvider deletedStreamListProvider) { - if(shouldReturnDefaultShardSyncTaskmanager) { + if (shouldReturnDefaultShardSyncTaskmanager) { return shardSyncTaskManager; } final ShardSyncTaskManager shardSyncTaskManager = mock(ShardSyncTaskManager.class); @@ -1255,7 +1257,7 @@ public class SchedulerTest { when(shardSyncTaskManager.hierarchicalShardSyncer()).thenReturn(hierarchicalShardSyncer); when(shardDetector.streamIdentifier()).thenReturn(streamConfig.streamIdentifier()); when(shardSyncTaskManager.callShardSyncTask()).thenReturn(new TaskResult(null)); - if(shardSyncFirstAttemptFailure) { + if (shardSyncFirstAttemptFailure) { when(shardDetector.listShards()) .thenThrow(new RuntimeException("Service Exception")) .thenReturn(Collections.EMPTY_LIST); diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java index 11d17368..17cad629 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java @@ -118,8 +118,7 @@ public class WorkerTest { private static final IRecordProcessorFactory SAMPLE_RECORD_PROCESSOR_FACTORY_V2 = SAMPLE_RECORD_PROCESSOR_FACTORY; - - *//** + *//* * Test method for {@link Worker#getApplicationName()}. *//* @Test @@ -346,7 +345,7 @@ public class WorkerTest { Assert.assertTrue(count > 0); } - *//** + *//* * Runs worker with threadPoolSize == numShards * Test method for {@link Worker#run()}. *//* @@ -357,7 +356,7 @@ public class WorkerTest { runAndTestWorker(numShards, threadPoolSize); } - *//** + *//* * Runs worker with threadPoolSize < numShards * Test method for {@link Worker#run()}. *//* @@ -368,7 +367,7 @@ public class WorkerTest { runAndTestWorker(numShards, threadPoolSize); } - *//** + *//* * Runs worker with threadPoolSize > numShards * Test method for {@link Worker#run()}. *//* @@ -379,7 +378,7 @@ public class WorkerTest { runAndTestWorker(numShards, threadPoolSize); } - *//** + *//* * Runs worker with threadPoolSize < numShards * Test method for {@link Worker#run()}. *//* @@ -395,7 +394,7 @@ public class WorkerTest { runAndTestWorker(shardList, threadPoolSize, initialLeases, callProcessRecordsForEmptyRecordList, numberOfRecordsPerShard, config); } - *//** + *//* * Runs worker with threadPoolSize < numShards * Test method for {@link Worker#run()}. *//* @@ -557,7 +556,7 @@ public class WorkerTest { verify(v2RecordProcessor, times(1)).shutdown(any(ShutdownInput.class)); } - *//** + *//* * This test is testing the {@link Worker}'s shutdown behavior and by extension the behavior of * {@link ThreadPoolExecutor#shutdownNow()}. It depends on the thread pool sending an interrupt to the pool threads. * This behavior makes the test a bit racy, since we need to ensure a specific order of events. @@ -1734,7 +1733,8 @@ public class WorkerTest { return new ReflectionFieldMatcher<>(itemClass, fieldName, fieldMatcher); } } - *//** + + *//* * Returns executor service that will be owned by the worker. This is useful to test the scenario * where worker shuts down the executor service also during shutdown flow. * @@ -1756,9 +1756,6 @@ public class WorkerTest { return shards; } - *//** - * @return - *//* private List createShardListWithOneSplit() { List shards = new ArrayList(); SequenceNumberRange range0 = ShardObjectHelper.newSequenceNumberRange("39428", "987324"); diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/HierarchicalShardSyncerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/HierarchicalShardSyncerTest.java index 9e130c38..1a1abc0e 100644 --- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/HierarchicalShardSyncerTest.java +++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/HierarchicalShardSyncerTest.java @@ -1592,7 +1592,7 @@ public class HierarchicalShardSyncerTest { assertExpectedLeasesAreCreated(SHARD_GRAPH_A, shardIdsOfCurrentLeases, INITIAL_POSITION_TRIM_HORIZON); } - /** + /* *
      * Shard structure (x-axis is epochs):
      * 0  3   6   9
@@ -1869,7 +1869,7 @@ public class HierarchicalShardSyncerTest {
         assertExpectedLeasesAreCreated(SHARD_GRAPH_A, shardIdsOfCurrentLeases, INITIAL_POSITION_AT_TIMESTAMP);
     }
 
-    /**
+    /*
      * 
      * Shard structure (x-axis is epochs):
      * 0  3   6   9
@@ -2325,12 +2325,16 @@ public class HierarchicalShardSyncerTest {
     @Test
     public void testEmptyLeaseTablePopulatesLeasesWithCompleteHashRangeAfterTwoRetries() throws Exception {
         final List shardsWithIncompleteHashRange = Arrays.asList(
-                ShardObjectHelper.newShard("shardId-0", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"), ShardObjectHelper.newHashKeyRange(ShardObjectHelper.MIN_HASH_KEY, "69")),
-                ShardObjectHelper.newShard("shardId-1", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"), ShardObjectHelper.newHashKeyRange("71", ShardObjectHelper.MAX_HASH_KEY))
+                ShardObjectHelper.newShard("shardId-0", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"),
+                        ShardObjectHelper.newHashKeyRange(ShardObjectHelper.MIN_HASH_KEY, "69")),
+                ShardObjectHelper.newShard("shardId-1", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"),
+                        ShardObjectHelper.newHashKeyRange("71", ShardObjectHelper.MAX_HASH_KEY))
         );
         final List shardsWithCompleteHashRange = Arrays.asList(
-                ShardObjectHelper.newShard("shardId-2", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"), ShardObjectHelper.newHashKeyRange(ShardObjectHelper.MIN_HASH_KEY, "420")),
-                ShardObjectHelper.newShard("shardId-3", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"), ShardObjectHelper.newHashKeyRange("421", ShardObjectHelper.MAX_HASH_KEY))
+                ShardObjectHelper.newShard("shardId-2", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"),
+                        ShardObjectHelper.newHashKeyRange(ShardObjectHelper.MIN_HASH_KEY, "420")),
+                ShardObjectHelper.newShard("shardId-3", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"),
+                        ShardObjectHelper.newHashKeyRange("421", ShardObjectHelper.MAX_HASH_KEY))
         );
 
         when(dynamoDBLeaseRefresher.isLeaseTableEmpty()).thenReturn(true);
@@ -2352,8 +2356,10 @@ public class HierarchicalShardSyncerTest {
     @Test
     public void testEmptyLeaseTablePopulatesLeasesWithCompleteHashRange() throws Exception {
         final List shardsWithCompleteHashRange = Arrays.asList(
-                ShardObjectHelper.newShard("shardId-2", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"), ShardObjectHelper.newHashKeyRange(ShardObjectHelper.MIN_HASH_KEY, "420")),
-                ShardObjectHelper.newShard("shardId-3", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"), ShardObjectHelper.newHashKeyRange("421", ShardObjectHelper.MAX_HASH_KEY))
+                ShardObjectHelper.newShard("shardId-2", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"),
+                        ShardObjectHelper.newHashKeyRange(ShardObjectHelper.MIN_HASH_KEY, "420")),
+                ShardObjectHelper.newShard("shardId-3", null, null, ShardObjectHelper.newSequenceNumberRange("1", "2"),
+                        ShardObjectHelper.newHashKeyRange("421", ShardObjectHelper.MAX_HASH_KEY))
         );
 
         when(dynamoDBLeaseRefresher.isLeaseTableEmpty()).thenReturn(true);
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseCoordinatorExerciser.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseCoordinatorExerciser.java
index 186fe290..72b48f16 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseCoordinatorExerciser.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseCoordinatorExerciser.java
@@ -14,10 +14,11 @@
  */
 package software.amazon.kinesis.leases;
 
-import java.awt.*;
+import java.awt.Button;
+import java.awt.Dimension;
+import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -25,7 +26,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.swing.*;
+import javax.swing.BoxLayout;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
 
 import lombok.extern.slf4j.Slf4j;
 import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
@@ -54,9 +58,8 @@ public class LeaseCoordinatorExerciser {
     private static final long INITIAL_LEASE_TABLE_READ_CAPACITY = 10L;
     private static final long INITIAL_LEASE_TABLE_WRITE_CAPACITY = 50L;
 
-    public static void main(String[] args) throws InterruptedException, DependencyException, InvalidStateException,
-            ProvisionedThroughputException, IOException {
-
+    public static void main(String[] args) throws DependencyException, InvalidStateException,
+            ProvisionedThroughputException {
         int numCoordinators = 9;
         int numLeases = 73;
         int leaseDurationMillis = 10000;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardObjectHelper.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardObjectHelper.java
index ee2504d8..cc03a203 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardObjectHelper.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardObjectHelper.java
@@ -56,7 +56,6 @@ public class ShardObjectHelper {
     private ShardObjectHelper() {
     }
 
-
     /** Helper method to create a new shard object.
      * @param shardId
      * @param parentShardId
@@ -84,7 +83,9 @@ public class ShardObjectHelper {
                                  String adjacentParentShardId,
                                  SequenceNumberRange sequenceNumberRange,
                                  HashKeyRange hashKeyRange) {
-        return Shard.builder().shardId(shardId).parentShardId(parentShardId).adjacentParentShardId(adjacentParentShardId).sequenceNumberRange(sequenceNumberRange).hashKeyRange(hashKeyRange).build();
+        return Shard.builder().shardId(shardId).parentShardId(parentShardId)
+                .adjacentParentShardId(adjacentParentShardId).sequenceNumberRange(sequenceNumberRange)
+                .hashKeyRange(hashKeyRange).build();
     }
 
     /** Helper method.
@@ -116,5 +117,4 @@ public class ShardObjectHelper {
         return parentShardIds;
     }
 
-
 }
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerBillingModePayPerRequestIntegrationTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerBillingModePayPerRequestIntegrationTest.java
index 1dad013e..3f692da5 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerBillingModePayPerRequestIntegrationTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerBillingModePayPerRequestIntegrationTest.java
@@ -37,7 +37,7 @@ import static org.junit.Assert.assertThat;
 @RunWith(MockitoJUnitRunner.class)
 public class DynamoDBLeaseRenewerBillingModePayPerRequestIntegrationTest extends
         LeaseIntegrationBillingModePayPerRequestTest {
-    private final String TEST_METRIC = "TestOperation";
+    private static final String TEST_METRIC = "TestOperation";
 
     // This test case's leases last 2 seconds
     private static final long LEASE_DURATION_MILLIS = 2000L;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerIntegrationTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerIntegrationTest.java
index 7c884fd6..f179a073 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerIntegrationTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerIntegrationTest.java
@@ -36,7 +36,7 @@ import software.amazon.kinesis.metrics.NullMetricsFactory;
 import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
 @RunWith(MockitoJUnitRunner.class)
 public class DynamoDBLeaseRenewerIntegrationTest extends LeaseIntegrationTest {
-    private final String TEST_METRIC = "TestOperation";
+    private static final String TEST_METRIC = "TestOperation";
 
     // This test case's leases last 2 seconds
     private static final long LEASE_DURATION_MILLIS = 2000L;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerTest.java
index bfff4e92..72379e88 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewerTest.java
@@ -86,7 +86,7 @@ public class DynamoDBLeaseRenewerTest {
          */
         Lease lease1 = newLease("1");
         Lease lease2 = newLease("2");
-        leasesToRenew = Arrays.asList(lease1,lease2);
+        leasesToRenew = Arrays.asList(lease1, lease2);
         renewer.addLeasesToRenew(leasesToRenew);
 
         doReturn(true).when(leaseRefresher).renewLease(lease1);
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/MetricAccumulatingQueueTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/MetricAccumulatingQueueTest.java
index 18bba742..0354a214 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/MetricAccumulatingQueueTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/MetricAccumulatingQueueTest.java
@@ -47,8 +47,8 @@ public class MetricAccumulatingQueueTest {
      */
     @Test
     public void testAccumulation() {
-        Collection dimensionsA = Collections.singleton(dim("name","a"));
-        Collection dimensionsB = Collections.singleton(dim("name","b"));
+        Collection dimensionsA = Collections.singleton(dim("name", "a"));
+        Collection dimensionsB = Collections.singleton(dim("name", "b"));
         String keyA = "a";
         String keyB = "b";
 
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java
index 40d86c49..0f8e628e 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java
@@ -176,7 +176,7 @@ public class FanOutRecordsPublisherTest {
     }
 
     @Test
-    public void InvalidEventTest() throws Exception {
+    public void testInvalidEvent() {
         FanOutRecordsPublisher source = new FanOutRecordsPublisher(kinesisClient, SHARD_ID, CONSUMER_ARN);
 
         ArgumentCaptor captor = ArgumentCaptor
@@ -443,10 +443,11 @@ public class FanOutRecordsPublisherTest {
 
                     @Override public void onNext(RecordsRetrieved input) {
                         receivedInput.add(input.processRecordsInput());
-                        assertEquals("" + ++lastSeenSeqNum, ((FanOutRecordsPublisher.FanoutRecordsRetrieved)input).continuationSequenceNumber());
+                        assertEquals("" + ++lastSeenSeqNum,
+                                ((FanOutRecordsPublisher.FanoutRecordsRetrieved) input).continuationSequenceNumber());
                         subscription.request(1);
                         servicePublisher.request(1);
-                        if(receivedInput.size() == totalServicePublisherEvents) {
+                        if (receivedInput.size() == totalServicePublisherEvents) {
                             servicePublisherTaskCompletionLatch.countDown();
                         }
                     }
@@ -549,10 +550,11 @@ public class FanOutRecordsPublisherTest {
 
                     @Override public void onNext(RecordsRetrieved input) {
                         receivedInput.add(input.processRecordsInput());
-                        assertEquals("" + ++lastSeenSeqNum, ((FanOutRecordsPublisher.FanoutRecordsRetrieved)input).continuationSequenceNumber());
+                        assertEquals("" + ++lastSeenSeqNum,
+                                ((FanOutRecordsPublisher.FanoutRecordsRetrieved) input).continuationSequenceNumber());
                         subscription.request(1);
                         servicePublisher.request(1);
-                        if(receivedInput.size() == triggerCompleteAtNthEvent) {
+                        if (receivedInput.size() == triggerCompleteAtNthEvent) {
                             servicePublisherTaskCompletionLatch.countDown();
                         }
                     }
@@ -681,7 +683,7 @@ public class FanOutRecordsPublisherTest {
                         receivedInput.add(input.processRecordsInput());
                         subscription.request(1);
                         servicePublisher.request(1);
-                        if(receivedInput.size() == triggerCompleteAtNthEvent) {
+                        if (receivedInput.size() == triggerCompleteAtNthEvent) {
                             servicePublisherTaskCompletionLatch.countDown();
                         }
                     }
@@ -783,10 +785,11 @@ public class FanOutRecordsPublisherTest {
 
                     @Override public void onNext(RecordsRetrieved input) {
                         receivedInput.add(input.processRecordsInput());
-                        assertEquals("" + ++lastSeenSeqNum, ((FanOutRecordsPublisher.FanoutRecordsRetrieved)input).continuationSequenceNumber());
+                        assertEquals("" + ++lastSeenSeqNum,
+                                ((FanOutRecordsPublisher.FanoutRecordsRetrieved) input).continuationSequenceNumber());
                         subscription.request(1);
                         servicePublisher.request(1);
-                        if(receivedInput.size() == triggerErrorAtNthEvent) {
+                        if (receivedInput.size() == triggerErrorAtNthEvent) {
                             servicePublisherTaskCompletionLatch.countDown();
                         }
                     }
@@ -879,10 +882,11 @@ public class FanOutRecordsPublisherTest {
 
                     @Override public void onNext(RecordsRetrieved input) {
                         receivedInput.add(input.processRecordsInput());
-                        assertEquals("" + ++lastSeenSeqNum, ((FanOutRecordsPublisher.FanoutRecordsRetrieved)input).continuationSequenceNumber());
+                        assertEquals("" + ++lastSeenSeqNum,
+                                ((FanOutRecordsPublisher.FanoutRecordsRetrieved) input).continuationSequenceNumber());
                         subscription.request(1);
                         servicePublisher.request(1);
-                        if(receivedInput.size() == totalServicePublisherEvents) {
+                        if (receivedInput.size() == totalServicePublisherEvents) {
                             servicePublisherTaskCompletionLatch.countDown();
                         }
                     }
@@ -973,7 +977,8 @@ public class FanOutRecordsPublisherTest {
 
                     @Override public void onNext(RecordsRetrieved input) {
                         receivedInput.add(input.processRecordsInput());
-                        assertEquals("" + ++lastSeenSeqNum, ((FanOutRecordsPublisher.FanoutRecordsRetrieved)input).continuationSequenceNumber());
+                        assertEquals("" + ++lastSeenSeqNum,
+                                ((FanOutRecordsPublisher.FanoutRecordsRetrieved) input).continuationSequenceNumber());
                         subscription.request(1);
                         servicePublisher.request(1);
                     }
@@ -1328,7 +1333,7 @@ public class FanOutRecordsPublisherTest {
                 fanOutRecordsPublisher
                         .evictAckedEventAndScheduleNextEvent(() -> recordsRetrieved.batchUniqueIdentifier());
                 // Send stale event periodically
-                if(totalRecordsRetrieved[0] % 10 == 0) {
+                if (totalRecordsRetrieved[0] % 10 == 0) {
                     fanOutRecordsPublisher.evictAckedEventAndScheduleNextEvent(
                             () -> new BatchUniqueIdentifier("some_uuid_str", "some_old_flow"));
                 }
@@ -1368,7 +1373,7 @@ public class FanOutRecordsPublisherTest {
         int count = 0;
         // Now that we allowed upto 10 elements queued up, send a pair of good and stale ack to verify records
         // delivered as expected.
-        while(count++ < 10 && (batchUniqueIdentifierQueued = ackQueue.take()) != null) {
+        while (count++ < 10 && (batchUniqueIdentifierQueued = ackQueue.take()) != null) {
             final BatchUniqueIdentifier batchUniqueIdentifierFinal = batchUniqueIdentifierQueued;
             fanOutRecordsPublisher
                     .evictAckedEventAndScheduleNextEvent(() -> batchUniqueIdentifierFinal);
@@ -1403,7 +1408,7 @@ public class FanOutRecordsPublisherTest {
         int count = 0;
         // Now that we allowed upto 10 elements queued up, send a pair of good and stale ack to verify records
         // delivered as expected.
-        while(count++ < 2 && (batchUniqueIdentifierQueued = ackQueue.poll(1000, TimeUnit.MILLISECONDS)) != null) {
+        while (count++ < 2 && (batchUniqueIdentifierQueued = ackQueue.poll(1000, TimeUnit.MILLISECONDS)) != null) {
             final BatchUniqueIdentifier batchUniqueIdentifierFinal = batchUniqueIdentifierQueued;
             fanOutRecordsPublisher.evictAckedEventAndScheduleNextEvent(
                     () -> new BatchUniqueIdentifier("some_uuid_str", batchUniqueIdentifierFinal.getFlowIdentifier()));
@@ -1457,7 +1462,8 @@ public class FanOutRecordsPublisherTest {
 
         flowCaptor.getValue().exceptionOccurred(exception);
 
-        Optional onErrorEvent = subscriber.events.stream().filter(e -> e instanceof OnErrorEvent).map(e -> (OnErrorEvent)e).findFirst();
+        Optional onErrorEvent = subscriber.events.stream().filter(e -> e instanceof OnErrorEvent)
+                .map(e -> (OnErrorEvent) e).findFirst();
 
         assertThat(onErrorEvent, equalTo(Optional.of(new OnErrorEvent(exception))));
         assertThat(acquireTimeoutLogged.get(), equalTo(true));
@@ -1587,8 +1593,8 @@ public class FanOutRecordsPublisherTest {
         public void run() {
             for (int i = 1; i <= numOfTimes; ) {
                 demandNotifier.acquireUninterruptibly();
-                if(i == sendCompletionAt) {
-                    if(shardEndAction != null) {
+                if (i == sendCompletionAt) {
+                    if (shardEndAction != null) {
                         shardEndAction.accept(i++);
                     } else {
                         action.accept(i++);
@@ -1596,7 +1602,7 @@ public class FanOutRecordsPublisherTest {
                     completeAction.run();
                     break;
                 }
-                if(i == sendErrorAt) {
+                if (i == sendErrorAt) {
                     action.accept(i++);
                     errorAction.run();
                     break;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcherTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcherTest.java
index 2e09f34a..4ac8bbf7 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcherTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/KinesisDataFetcherTest.java
@@ -331,7 +331,7 @@ public class KinesisDataFetcherTest {
 
     private CompletableFuture makeGetRecordsResponse(String nextIterator, List records) {
         List childShards = new ArrayList<>();
-        if(nextIterator == null) {
+        if (nextIterator == null) {
             childShards = createChildShards();
         }
         return CompletableFuture.completedFuture(GetRecordsResponse.builder().nextShardIterator(nextIterator)
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherIntegrationTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherIntegrationTest.java
index 5d757a6c..d9955da4 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherIntegrationTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherIntegrationTest.java
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -277,7 +276,8 @@ public class PrefetchRecordsPublisherIntegrationTest {
 
         @Override
         public DataFetcherResult getRecords() {
-            GetRecordsResponse getRecordsResult = GetRecordsResponse.builder().records(new ArrayList<>(records)).nextShardIterator(nextShardIterator).millisBehindLatest(1000L).build();
+            GetRecordsResponse getRecordsResult = GetRecordsResponse.builder().records(new ArrayList<>(records))
+                    .nextShardIterator(nextShardIterator).millisBehindLatest(1000L).build();
 
             return new AdvancingResult(getRecordsResult);
         }
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherTest.java
index 74707eb4..af02469a 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisherTest.java
@@ -327,7 +327,7 @@ public class PrefetchRecordsPublisherTest {
         //        TODO: fix this verification
         //        verify(getRecordsRetrievalStrategy, times(callRate)).getRecords(MAX_RECORDS_PER_CALL);
         //        assertEquals(spyQueue.size(), callRate);
-        assertTrue("Call Rate is "+callRate,callRate < MAX_SIZE);
+        assertTrue("Call Rate is " + callRate, callRate < MAX_SIZE);
     }
 
     @Test
@@ -422,8 +422,10 @@ public class PrefetchRecordsPublisherTest {
 
     @Test
     public void testRetryableRetrievalExceptionContinues() {
-        GetRecordsResponse response = GetRecordsResponse.builder().millisBehindLatest(100L).records(Collections.emptyList()).nextShardIterator(NEXT_SHARD_ITERATOR).build();
-        when(getRecordsRetrievalStrategy.getRecords(anyInt())).thenThrow(new RetryableRetrievalException("Timeout", new TimeoutException("Timeout"))).thenReturn(response);
+        GetRecordsResponse response = GetRecordsResponse.builder().millisBehindLatest(100L)
+                .records(Collections.emptyList()).nextShardIterator(NEXT_SHARD_ITERATOR).build();
+        when(getRecordsRetrievalStrategy.getRecords(anyInt()))
+                .thenThrow(new RetryableRetrievalException("Timeout", new TimeoutException("Timeout"))).thenReturn(response);
 
         getRecordsCache.start(sequenceNumber, initialPosition);
 
@@ -638,7 +640,7 @@ public class PrefetchRecordsPublisherTest {
 
         verify(getRecordsRetrievalStrategy, atLeast(2)).getRecords(anyInt());
 
-        while(getRecordsCache.getPublisherSession().prefetchRecordsQueue().remainingCapacity() > 0) {
+        while (getRecordsCache.getPublisherSession().prefetchRecordsQueue().remainingCapacity() > 0) {
             Thread.yield();
         }
 
@@ -697,7 +699,7 @@ public class PrefetchRecordsPublisherTest {
 
         public void resetIteratorTo(String nextIterator) {
             Iterator newIterator = responses.iterator();
-            while(newIterator.hasNext()) {
+            while (newIterator.hasNext()) {
                 GetRecordsResponse current = newIterator.next();
                 if (StringUtils.equals(nextIterator, current.nextShardIterator())) {
                     if (!newIterator.hasNext()) {
@@ -725,7 +727,7 @@ public class PrefetchRecordsPublisherTest {
 
         private static final int LOSS_EVERY_NTH_RECORD = 50;
         private static int recordCounter = 0;
-        private static final ScheduledExecutorService consumerHealthChecker = Executors.newScheduledThreadPool(1);
+        private static final ScheduledExecutorService CONSUMER_HEALTH_CHECKER = Executors.newScheduledThreadPool(1);
 
         public LossyNotificationSubscriber(Subscriber delegate, RecordsPublisher recordsPublisher) {
             super(delegate, recordsPublisher);
@@ -738,7 +740,7 @@ public class PrefetchRecordsPublisherTest {
                 getDelegateSubscriber().onNext(recordsRetrieved);
             } else {
                 log.info("Record Loss Triggered");
-                consumerHealthChecker.schedule(() ->  {
+                CONSUMER_HEALTH_CHECKER.schedule(() ->  {
                     getRecordsPublisher().restartFrom(recordsRetrieved);
                     Flowable.fromPublisher(getRecordsPublisher()).subscribeOn(Schedulers.computation())
                             .observeOn(Schedulers.computation(), true, 8).subscribe(this);
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/BlockingUtils.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/BlockingUtils.java
index 0d68e51b..cd7ad8a6 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/BlockingUtils.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/BlockingUtils.java
@@ -21,7 +21,7 @@ public class BlockingUtils {
 
     public static  Records blockUntilRecordsAvailable(Supplier recordsSupplier, long timeoutMillis) {
         Records recordsRetrieved;
-        while((recordsRetrieved = recordsSupplier.get()) == null && timeoutMillis > 0 ) {
+        while ((recordsRetrieved = recordsSupplier.get()) == null && timeoutMillis > 0 ) {
             try {
                 Thread.sleep(100);
             } catch (InterruptedException e) {
@@ -29,7 +29,7 @@ public class BlockingUtils {
             }
             timeoutMillis -= 100;
         }
-        if(recordsRetrieved != null) {
+        if (recordsRetrieved != null) {
             return recordsRetrieved;
         } else {
             throw new RuntimeException("No records found");
@@ -37,7 +37,7 @@ public class BlockingUtils {
     }
 
     public static boolean blockUntilConditionSatisfied(Supplier conditionSupplier, long timeoutMillis) {
-        while(!conditionSupplier.get() && timeoutMillis > 0 ) {
+        while (!conditionSupplier.get() && timeoutMillis > 0 ) {
             try {
                 Thread.sleep(100);
             } catch (InterruptedException e) {
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/SubscribeToShardRequestMatcher.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/SubscribeToShardRequestMatcher.java
index d120d95a..43c887a3 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/SubscribeToShardRequestMatcher.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/SubscribeToShardRequestMatcher.java
@@ -12,7 +12,7 @@ public class SubscribeToShardRequestMatcher extends ArgumentMatcher
         
         
-        
+        
+            
+            
+        
         
         
         
diff --git a/pom.xml b/pom.xml
index 82d7857d..90cec514 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,6 +81,7 @@
           checkstyle/checkstyle.xml
           true
           true
+          true
           checkstyle/checkstyle-suppressions.xml
         
         

From 768f6a36bb5755df6f95414922061f05d5f93f55 Mon Sep 17 00:00:00 2001
From: stair <123031771+stair-aws@users.noreply.github.com>
Date: Mon, 26 Jun 2023 16:19:30 -0400
Subject: [PATCH 6/9] Checkstyle: added `UnusedImports` check. (#1153)

---
 .../MultiLangRecordProcessorFactory.java      |  1 -
 ...edentialsProviderPropertyValueDecoder.java |  2 --
 .../multilang/config/BuilderDynaBean.java     |  2 --
 .../config/KinesisClientLibConfigurator.java  |  6 +----
 .../config/MultiLangDaemonConfiguration.java  |  2 --
 .../kinesis/multilang/MessageWriterTest.java  |  2 --
 .../multilang/MultiLangProtocolTest.java      |  9 ++++----
 .../kinesis/leases/MultiStreamLease.java      |  2 --
 .../kinesis/metrics/MetricDatumWithKey.java   |  7 +++---
 .../fanout/FanOutRecordsPublisher.java        |  4 ----
 .../checkpoint/InMemoryCheckpointer.java      |  1 -
 .../amazon/kinesis/config/KCLAppConfig.java   |  2 --
 .../GracefulShutdownCoordinatorTest.java      |  2 --
 .../kinesis/coordinator/WorkerTest.java       |  2 --
 ...tegrationBillingModePayPerRequestTest.java |  8 -------
 .../amazon/kinesis/leases/ShardInfoTest.java  |  2 --
 ...namoDBLeaseCoordinatorIntegrationTest.java |  1 -
 .../dynamodb/DynamoDBLeaseRefresherTest.java  |  2 --
 .../DynamoDBLeaseTakerIntegrationTest.java    |  3 ---
 .../lifecycle/BlockOnParentShardTaskTest.java |  6 +----
 .../ShardConsumerSubscriberTest.java          | 22 -------------------
 .../FanOutConsumerRegistrationTest.java       |  2 --
 .../fanout/FanOutRecordsPublisherTest.java    | 18 +--------------
 .../kinesis/utils/AWSResourceManager.java     |  8 +------
 .../kinesis/utils/LeaseTableManager.java      |  2 --
 .../kinesis/utils/StreamExistenceManager.java |  2 --
 checkstyle/checkstyle.xml                     |  1 +
 27 files changed, 12 insertions(+), 109 deletions(-)

diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangRecordProcessorFactory.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangRecordProcessorFactory.java
index a1c01c51..c4aab958 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangRecordProcessorFactory.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangRecordProcessorFactory.java
@@ -19,7 +19,6 @@ import java.util.concurrent.ExecutorService;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 import lombok.extern.slf4j.Slf4j;
-import software.amazon.kinesis.coordinator.KinesisClientLibConfiguration;
 import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
 import software.amazon.kinesis.processor.ShardRecordProcessorFactory;
 import software.amazon.kinesis.processor.ShardRecordProcessor;
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoder.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoder.java
index da3db4fb..97fa975e 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoder.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/AWSCredentialsProviderPropertyValueDecoder.java
@@ -22,8 +22,6 @@ import java.util.List;
 import com.amazonaws.auth.AWSCredentialsProvider;
 import com.amazonaws.auth.AWSCredentialsProviderChain;
 import lombok.extern.slf4j.Slf4j;
-import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
-import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
 
 /**
  * Get AWSCredentialsProvider property.
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/BuilderDynaBean.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/BuilderDynaBean.java
index 2e5502cd..2035695c 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/BuilderDynaBean.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/BuilderDynaBean.java
@@ -20,7 +20,6 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
 import java.util.function.Function;
-import java.util.function.Supplier;
 
 import lombok.Getter;
 import org.apache.commons.beanutils.ConvertUtilsBean;
@@ -150,7 +149,6 @@ public class BuilderDynaBean implements DynaBean {
         } else {
             return expected.cast(dynaBeanCreateSupport.build());
         }
-
     }
 
     private void validateResolvedEmptyHandler() {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java
index c95d0853..5e2ddb1d 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/KinesisClientLibConfigurator.java
@@ -25,7 +25,6 @@ import org.apache.commons.beanutils.ConvertUtilsBean;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.Validate;
 import software.amazon.awssdk.arns.Arn;
-import software.amazon.awssdk.regions.Region;
 import software.amazon.kinesis.common.StreamIdentifier;
 
 /**
@@ -42,7 +41,6 @@ public class KinesisClientLibConfigurator {
     private final BeanUtilsBean utilsBean;
     private final MultiLangDaemonConfiguration configuration;
 
-
     /**
      * Constructor.
      */
@@ -78,7 +76,6 @@ public class KinesisClientLibConfigurator {
             //Parse out the stream Name from the Arn (and/or override existing value for Stream Name)
             final String streamNameFromArn = streamArnObj.resource().resource();
             configuration.setStreamName(streamNameFromArn);
-
         }
 
         Validate.notBlank(configuration.getStreamName(), "Stream name or Stream Arn is required. Stream Arn takes precedence if both are passed in.");
@@ -109,5 +106,4 @@ public class KinesisClientLibConfigurator {
         return getConfiguration(properties);
     }
 
-
-}
\ No newline at end of file
+}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java
index 7a7f2e79..d8f58741 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfiguration.java
@@ -158,7 +158,6 @@ public class MultiLangDaemonConfiguration {
         metricsEnabledDimensions = new HashSet<>(Arrays.asList(dimensions));
     }
 
-
     private RetrievalMode retrievalMode = RetrievalMode.DEFAULT;
 
     private final FanoutConfigBean fanoutConfig = new FanoutConfigBean();
@@ -170,7 +169,6 @@ public class MultiLangDaemonConfiguration {
     private long shutdownGraceMillis;
     private Integer timeoutInSeconds;
 
-
     private final BuilderDynaBean kinesisCredentialsProvider;
 
     public void setAWSCredentialsProvider(String providerString) {
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java
index c997c193..588f6140 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MessageWriterTest.java
@@ -51,8 +51,6 @@ public class MessageWriterTest {
     @Rule
     public final ExpectedException thrown = ExpectedException.none();
 
-    // ExecutorService executor;
-
     @Before
     public void setup() {
         stream = Mockito.mock(OutputStream.class);
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java
index d385b2f9..5320aec5 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/MultiLangProtocolTest.java
@@ -103,7 +103,7 @@ public class MultiLangProtocolTest {
     }
 
     @Test
-    public void initializeTest() throws InterruptedException, ExecutionException {
+    public void testInitialize() {
         when(messageWriter
                 .writeInitializeMessage(argThat(Matchers.withInit(InitializationInput.builder()
                         .shardId(shardId).build())))).thenReturn(buildFuture(true));
@@ -113,7 +113,7 @@ public class MultiLangProtocolTest {
     }
 
     @Test
-    public void processRecordsTest() throws InterruptedException, ExecutionException {
+    public void testProcessRecords() {
         when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
         when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(
                 new StatusMessage("processRecords"), Message.class));
@@ -128,7 +128,6 @@ public class MultiLangProtocolTest {
         when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(new StatusMessage(LeaseLostMessage.ACTION), Message.class));
 
         assertThat(protocol.leaseLost(LeaseLostInput.builder().build()), equalTo(true));
-
     }
 
     @Test
@@ -174,7 +173,7 @@ public class MultiLangProtocolTest {
     }
 
     @Test
-    public void processRecordsWithCheckpointsTest() throws InterruptedException, ExecutionException,
+    public void testProcessRecordsWithCheckpoints() throws
         KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
 
         when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
@@ -203,7 +202,7 @@ public class MultiLangProtocolTest {
     }
 
     @Test
-    public void processRecordsWithABadCheckpointTest() throws InterruptedException, ExecutionException {
+    public void testProcessRecordsWithABadCheckpoint() {
         when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
         when(messageWriter.writeCheckpointMessageWithError(anyString(), anyLong(), any(Throwable.class))).thenReturn(buildFuture(false));
         when(messageReader.getNextMessageFromSTDOUT()).thenAnswer(buildMessageAnswers(new ArrayList() {
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/MultiStreamLease.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/MultiStreamLease.java
index c8811354..c79cc458 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/MultiStreamLease.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/MultiStreamLease.java
@@ -23,8 +23,6 @@ import lombok.Setter;
 import lombok.experimental.Accessors;
 import org.apache.commons.lang3.Validate;
 
-import java.util.Objects;
-
 import static com.google.common.base.Verify.verifyNotNull;
 
 @Setter
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java
index da83675f..e94c8730 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/metrics/MetricDatumWithKey.java
@@ -15,7 +15,6 @@
 package software.amazon.kinesis.metrics;
 
 import lombok.AllArgsConstructor;
-import lombok.Data;
 import lombok.Setter;
 import lombok.experimental.Accessors;
 import software.amazon.awssdk.services.cloudwatch.model.MetricDatum;
@@ -29,11 +28,11 @@ import java.util.Objects;
  * @param  is a class that stores information about a MetricDatum. This is useful
  *        to compare MetricDatums, aggregate similar MetricDatums or store information about a datum
  *        that may be relevant to the user (i.e. MetricName, CustomerId, TimeStamp, etc).
- * 
+ *
  *        Example:
- * 
+ *
  *        Let SampleMetricKey be a KeyType that takes in the time in which the datum was created.
- * 
+ *
  *        MetricDatumWithKey sampleDatumWithKey = new MetricDatumWithKey(new
  *        SampleMetricKey(System.currentTimeMillis()), datum)
  */
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java
index ca4ce12d..7177211f 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisher.java
@@ -27,14 +27,12 @@ import org.reactivestreams.Subscriber;
 import org.reactivestreams.Subscription;
 import software.amazon.awssdk.core.async.SdkPublisher;
 import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
-import software.amazon.awssdk.services.kinesis.model.ChildShard;
 import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
 import software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent;
 import software.amazon.awssdk.services.kinesis.model.SubscribeToShardEventStream;
 import software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest;
 import software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponse;
 import software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponseHandler;
-import software.amazon.awssdk.utils.CollectionUtils;
 import software.amazon.awssdk.utils.Either;
 import software.amazon.kinesis.annotations.KinesisClientInternalApi;
 import software.amazon.kinesis.common.InitialPositionInStreamExtended;
@@ -117,7 +115,6 @@ public class FanOutRecordsPublisher implements RecordsPublisher {
             this.currentSequenceNumber = extendedSequenceNumber.sequenceNumber();
             this.isFirstConnection = true;
         }
-
     }
 
     @Override
@@ -276,7 +273,6 @@ public class FanOutRecordsPublisher implements RecordsPublisher {
         SubscriptionShutdownEvent(Runnable subscriptionShutdownAction, String eventIdentifier) {
             this(subscriptionShutdownAction, eventIdentifier, null);
         }
-
     }
 
     private boolean hasValidSubscriber() {
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java
index a2d83568..2a93e83d 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/InMemoryCheckpointer.java
@@ -17,7 +17,6 @@ package software.amazon.kinesis.checkpoint;
 import java.util.HashMap;
 import java.util.Map;
 
-import software.amazon.kinesis.exceptions.KinesisClientLibException;
 import software.amazon.kinesis.processor.Checkpointer;
 import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
 
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/config/KCLAppConfig.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/config/KCLAppConfig.java
index b67efa10..5365ca4f 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/config/KCLAppConfig.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/config/KCLAppConfig.java
@@ -29,7 +29,6 @@ import java.io.IOException;
 import java.net.Inet4Address;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
-import java.util.Optional;
 
 /**
  * Default configuration for a producer or consumer used in integration tests.
@@ -81,7 +80,6 @@ public abstract class KCLAppConfig {
     }
 
     public final KinesisAsyncClient buildAsyncKinesisClient() throws URISyntaxException, IOException {
-
         if (kinesisAsyncClient == null) {
             // Setup H2 client config.
             final NettyNioAsyncHttpClient.Builder builder = NettyNioAsyncHttpClient.builder()
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinatorTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinatorTest.java
index 84dcaa9c..44c7272c 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinatorTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinatorTest.java
@@ -15,12 +15,10 @@
 package software.amazon.kinesis.coordinator;
 
 import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.not;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyLong;
 import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java
index 17cad629..ec076e8d 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/coordinator/WorkerTest.java
@@ -14,8 +14,6 @@
  */
 package software.amazon.kinesis.coordinator;
 
-import java.util.concurrent.ThreadPoolExecutor;
-
 /**
  * Unit tests of Worker.
  */
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseIntegrationBillingModePayPerRequestTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseIntegrationBillingModePayPerRequestTest.java
index 9f7735f9..128d347a 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseIntegrationBillingModePayPerRequestTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/LeaseIntegrationBillingModePayPerRequestTest.java
@@ -15,16 +15,8 @@
 package software.amazon.kinesis.leases;
 
 import lombok.extern.slf4j.Slf4j;
-import org.junit.Rule;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.mockito.Mock;
-import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
-import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
 import software.amazon.awssdk.services.dynamodb.model.BillingMode;
 import software.amazon.kinesis.leases.dynamodb.DynamoDBLeaseRefresher;
-import software.amazon.kinesis.leases.dynamodb.DynamoDBLeaseSerializer;
-import software.amazon.kinesis.leases.dynamodb.TableCreatorCallback;
 
 @Slf4j
 public class LeaseIntegrationBillingModePayPerRequestTest extends LeaseIntegrationTest {
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardInfoTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardInfoTest.java
index 276f6c25..4ccafe52 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardInfoTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/ShardInfoTest.java
@@ -26,11 +26,9 @@ import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import software.amazon.kinesis.leases.ShardInfo;
 import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
 
 public class ShardInfoTest {
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorIntegrationTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorIntegrationTest.java
index d89c010e..05d4ba74 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorIntegrationTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorIntegrationTest.java
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresherTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresherTest.java
index 643cc99c..102a9f17 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresherTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRefresherTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -158,7 +157,6 @@ public class DynamoDBLeaseRefresherTest {
 
         verify(mockScanFuture, times(2)).get(anyLong(), any(TimeUnit.class));
         verify(dynamoDbClient, times(2)).scan(any(ScanRequest.class));
-
     }
 
     @Test
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseTakerIntegrationTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseTakerIntegrationTest.java
index 475f1940..772aa542 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseTakerIntegrationTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseTakerIntegrationTest.java
@@ -15,9 +15,7 @@
 package software.amazon.kinesis.leases.dynamodb;
 
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -153,7 +151,6 @@ public class DynamoDBLeaseTakerIntegrationTest extends LeaseIntegrationTest {
         assertThat(addedLeases.values().containsAll(allLeases), equalTo(true));
     }
 
-
     /**
      * Sets the leaseDurationMillis to 0, ensuring a get request to update the existing lease after computing
      * leases to take
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/BlockOnParentShardTaskTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/BlockOnParentShardTaskTest.java
index 06a72230..61473833 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/BlockOnParentShardTaskTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/BlockOnParentShardTaskTest.java
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.when;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Optional;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -43,7 +42,7 @@ public class BlockOnParentShardTaskTest {
     private final String shardId = "shardId-97";
     private final String streamId = "123:stream:146";
     private final String concurrencyToken = "testToken";
-    private final List emptyParentShardIds = new ArrayList();
+    private final List emptyParentShardIds = new ArrayList<>();
     private ShardInfo shardInfo;
 
     @Before
@@ -77,7 +76,6 @@ public class BlockOnParentShardTaskTest {
     @Test
     public final void testCallShouldNotThrowBlockedOnParentWhenParentsHaveFinished()
         throws DependencyException, InvalidStateException, ProvisionedThroughputException {
-
         ShardInfo shardInfo = null;
         BlockOnParentShardTask task = null;
         String parent1ShardId = "shardId-1";
@@ -118,7 +116,6 @@ public class BlockOnParentShardTaskTest {
     @Test
     public final void testCallShouldNotThrowBlockedOnParentWhenParentsHaveFinishedMultiStream()
             throws DependencyException, InvalidStateException, ProvisionedThroughputException {
-
         ShardInfo shardInfo = null;
         BlockOnParentShardTask task = null;
         String parent1LeaseKey = streamId + ":" + "shardId-1";
@@ -162,7 +159,6 @@ public class BlockOnParentShardTaskTest {
     @Test
     public final void testCallWhenParentsHaveNotFinished()
             throws DependencyException, InvalidStateException, ProvisionedThroughputException {
-
         ShardInfo shardInfo = null;
         BlockOnParentShardTask task = null;
         String parent1ShardId = "shardId-1";
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriberTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriberTest.java
index 09ba6ec9..4299c163 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriberTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/lifecycle/ShardConsumerSubscriberTest.java
@@ -35,7 +35,6 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Optional;
 import java.util.concurrent.CyclicBarrier;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -173,7 +172,6 @@ public class ShardConsumerSubscriberTest {
         assertThat(subscriber.getAndResetDispatchFailure(), nullValue());
 
         verify(shardConsumer, times(20)).handleInput(argThat(eqProcessRecordsInput(processRecordsInput)), any(Subscription.class));
-
     }
 
     @Test
@@ -293,12 +291,10 @@ public class ShardConsumerSubscriberTest {
         assertThat(received.size(), equalTo(recordsPublisher.responses.size()));
         Stream.iterate(0, i -> i + 1).limit(received.size()).forEach(i -> assertThat(received.get(i),
                 eqProcessRecordsInput(recordsPublisher.responses.get(i).recordsRetrieved.processRecordsInput())));
-
     }
 
     @Test
     public void restartAfterRequestTimerExpiresWhenNotGettingRecordsAfterInitialization() throws Exception {
-
         executorService = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder()
                 .setNameFormat("test-" + testName.getMethodName() + "-%04d").setDaemon(true).build());
 
@@ -347,12 +343,10 @@ public class ShardConsumerSubscriberTest {
         assertThat(received.size(), equalTo(recordsPublisher.responses.size()));
         Stream.iterate(0, i -> i + 1).limit(received.size()).forEach(i -> assertThat(received.get(i),
                 eqProcessRecordsInput(recordsPublisher.responses.get(i).recordsRetrieved.processRecordsInput())));
-
     }
 
     @Test
     public void restartAfterRequestTimerExpiresWhenInitialTaskExecutionIsRejected() throws Exception {
-
         executorService = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder()
                 .setNameFormat("test-" + testName.getMethodName() + "-%04d").setDaemon(true).build());
 
@@ -405,7 +399,6 @@ public class ShardConsumerSubscriberTest {
         assertThat(received.size(), equalTo(recordsPublisher.responses.size()));
         Stream.iterate(0, i -> i + 1).limit(received.size()).forEach(i -> assertThat(received.get(i),
                 eqProcessRecordsInput(recordsPublisher.responses.get(i).recordsRetrieved.processRecordsInput())));
-
     }
 
     private Object directlyExecuteRunnable(InvocationOnMock invocation) {
@@ -623,8 +616,6 @@ public class ShardConsumerSubscriberTest {
 
     /**
      * Test to validate the warning message from ShardConsumer is not suppressed with the default configuration of 0
-     * 
-     * @throws Exception
      */
     @Test
     public void noLoggingSuppressionNeededOnHappyPathTest() {
@@ -648,8 +639,6 @@ public class ShardConsumerSubscriberTest {
 
     /**
      * Test to validate the warning message from ShardConsumer is not suppressed with the default configuration of 0
-     * 
-     * @throws Exception
      */
     @Test
     public void loggingNotSuppressedAfterTimeoutTest() {
@@ -677,8 +666,6 @@ public class ShardConsumerSubscriberTest {
     /**
      * Test to validate the warning message from ShardConsumer is successfully supressed if we only have intermittant
      * readTimeouts.
-     * 
-     * @throws Exception
      */
     @Test
     public void loggingSuppressedAfterIntermittentTimeoutTest() {
@@ -705,8 +692,6 @@ public class ShardConsumerSubscriberTest {
     /**
      * Test to validate the warning message from ShardConsumer is successfully logged if multiple sequential timeouts
      * occur.
-     * 
-     * @throws Exception
      */
     @Test
     public void loggingPartiallySuppressedAfterMultipleTimeoutTest() {
@@ -733,8 +718,6 @@ public class ShardConsumerSubscriberTest {
 
     /**
      * Test to validate the warning message from ShardConsumer is successfully logged if sequential timeouts occur.
-     * 
-     * @throws Exception
      */
     @Test
     public void loggingPartiallySuppressedAfterConsecutiveTimeoutTest() {
@@ -763,8 +746,6 @@ public class ShardConsumerSubscriberTest {
     /**
      * Test to validate the non-timeout warning message from ShardConsumer is not suppressed with the default
      * configuration of 0
-     * 
-     * @throws Exception
      */
     @Test
     public void loggingNotSuppressedOnNonReadTimeoutExceptionNotIgnoringReadTimeoutsExceptionTest() {
@@ -792,12 +773,9 @@ public class ShardConsumerSubscriberTest {
     /**
      * Test to validate the non-timeout warning message from ShardConsumer is not suppressed with 2 ReadTimeouts to
      * ignore
-     * 
-     * @throws Exception
      */
     @Test
     public void loggingNotSuppressedOnNonReadTimeoutExceptionIgnoringReadTimeoutsTest() {
-
         // We're not throwing a ReadTimeout, so no suppression is expected.
         // The test expects a non-ReadTimeout exception to be thrown on requests 3 and 5, and we expect logs on
         // each Non-ReadTimeout Exception, no matter what the number of ReadTimeoutsToIgnore we pass in,
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutConsumerRegistrationTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutConsumerRegistrationTest.java
index 245e22d5..fca6799d 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutConsumerRegistrationTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutConsumerRegistrationTest.java
@@ -19,7 +19,6 @@ import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -28,7 +27,6 @@ import static org.mockito.Mockito.when;
 import java.util.concurrent.CompletableFuture;
 
 import org.apache.commons.lang3.StringUtils;
-import org.hamcrest.Matchers;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java
index 0f8e628e..9615794b 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/fanout/FanOutRecordsPublisherTest.java
@@ -8,7 +8,6 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
 import io.reactivex.rxjava3.subscribers.SafeSubscriber;
 import lombok.Data;
 import lombok.RequiredArgsConstructor;
-import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
@@ -54,7 +53,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
@@ -77,7 +75,6 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.never;
@@ -172,7 +169,6 @@ public class FanOutRecordsPublisherTest {
                 assertThat(clientRecordsList.get(i), matchers.get(i));
             }
         });
-
     }
 
     @Test
@@ -239,7 +235,6 @@ public class FanOutRecordsPublisherTest {
                 assertThat(clientRecordsList.get(i), matchers.get(i));
             }
         });
-
     }
 
     @Test
@@ -317,11 +312,10 @@ public class FanOutRecordsPublisherTest {
         });
 
         assertThat(source.getCurrentSequenceNumber(), equalTo("3000"));
-
     }
 
     @Test
-    public void testIfEventsAreNotDeliveredToShardConsumerWhenPreviousEventDeliveryTaskGetsRejected() throws Exception {
+    public void testIfEventsAreNotDeliveredToShardConsumerWhenPreviousEventDeliveryTaskGetsRejected() {
         FanOutRecordsPublisher source = new FanOutRecordsPublisher(kinesisClient, SHARD_ID, CONSUMER_ARN);
 
         ArgumentCaptor captor = ArgumentCaptor
@@ -395,7 +389,6 @@ public class FanOutRecordsPublisherTest {
         });
 
         assertThat(source.getCurrentSequenceNumber(), equalTo("1000"));
-
     }
 
     @Test
@@ -489,12 +482,10 @@ public class FanOutRecordsPublisherTest {
         });
 
         assertThat(source.getCurrentSequenceNumber(), equalTo(totalServicePublisherEvents + ""));
-
     }
 
     @Test
     public void testIfStreamOfEventsAndOnCompleteAreDeliveredInOrderWithBackpressureAdheringServicePublisher() throws Exception {
-
         CountDownLatch onS2SCallLatch = new CountDownLatch(2);
 
         doAnswer(new Answer() {
@@ -601,7 +592,6 @@ public class FanOutRecordsPublisherTest {
         // Let's wait for sometime to allow the publisher to re-subscribe
         onS2SCallLatch.await(5000, TimeUnit.MILLISECONDS);
         verify(kinesisClient, times(2)).subscribeToShard(any(SubscribeToShardRequest.class), flowCaptor.capture());
-
     }
 
     @Test
@@ -730,7 +720,6 @@ public class FanOutRecordsPublisherTest {
         // With shard end event, onComplete must be propagated to the subscriber.
         onCompleteLatch.await(5000, TimeUnit.MILLISECONDS);
         assertTrue("OnComplete should be triggered", isOnCompleteTriggered[0]);
-
     }
 
     @Test
@@ -834,7 +823,6 @@ public class FanOutRecordsPublisherTest {
         assertThat(source.getCurrentSequenceNumber(), equalTo(triggerErrorAtNthEvent + ""));
         onErrorReceiveLatch.await(5000, TimeUnit.MILLISECONDS);
         assertTrue("OnError should have been thrown", isOnErrorThrown[0]);
-
     }
 
     @Test
@@ -928,7 +916,6 @@ public class FanOutRecordsPublisherTest {
         });
 
         assertThat(source.getCurrentSequenceNumber(), equalTo(totalServicePublisherEvents + ""));
-
     }
 
     @Test
@@ -1131,7 +1118,6 @@ public class FanOutRecordsPublisherTest {
                 assertThat(clientRecordsList.get(i), matchers.get(i));
             }
         });
-
     }
 
     @Test
@@ -1247,7 +1233,6 @@ public class FanOutRecordsPublisherTest {
 
         verifyRecords(nonFailingSubscriber.received.get(0).records(), matchers);
         verifyRecords(nonFailingSubscriber.received.get(1).records(), nextMatchers);
-
     }
 
     @Test
@@ -1467,7 +1452,6 @@ public class FanOutRecordsPublisherTest {
 
         assertThat(onErrorEvent, equalTo(Optional.of(new OnErrorEvent(exception))));
         assertThat(acquireTimeoutLogged.get(), equalTo(true));
-
     }
 
     private void verifyRecords(List clientRecordsList, List matchers) {
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/AWSResourceManager.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/AWSResourceManager.java
index 3314f922..4a6bcfaf 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/AWSResourceManager.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/AWSResourceManager.java
@@ -2,14 +2,8 @@ package software.amazon.kinesis.utils;
 
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import software.amazon.awssdk.services.dynamodb.model.ListTablesRequest;
-import software.amazon.awssdk.services.dynamodb.model.ListTablesResponse;
-import software.amazon.kinesis.common.FutureUtils;
 
-import java.time.Duration;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
 @Slf4j
@@ -28,7 +22,7 @@ public abstract class AWSResourceManager {
 
     /**
      * Get a list of all the names of resources of a specified type
-     * @return
+     *
      * @throws Exception
      */
     public abstract List getAllResourceNames() throws Exception;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/LeaseTableManager.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/LeaseTableManager.java
index e8d1cb05..40d711bd 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/LeaseTableManager.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/LeaseTableManager.java
@@ -12,8 +12,6 @@ import software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException;
 import software.amazon.awssdk.services.dynamodb.model.TableStatus;
 import software.amazon.kinesis.common.FutureUtils;
 
-import java.io.IOException;
-import java.net.URISyntaxException;
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.List;
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/StreamExistenceManager.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/StreamExistenceManager.java
index eeffb36b..b5f06b78 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/StreamExistenceManager.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/utils/StreamExistenceManager.java
@@ -2,8 +2,6 @@ package software.amazon.kinesis.utils;
 
 import lombok.Value;
 import lombok.extern.slf4j.Slf4j;
-import software.amazon.awssdk.services.dynamodb.model.ListTablesRequest;
-import software.amazon.awssdk.services.dynamodb.model.ListTablesResponse;
 import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
 import software.amazon.awssdk.services.kinesis.model.CreateStreamRequest;
 import software.amazon.awssdk.services.kinesis.model.DeleteStreamRequest;
diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml
index 0186a496..10031e23 100644
--- a/checkstyle/checkstyle.xml
+++ b/checkstyle/checkstyle.xml
@@ -36,6 +36,7 @@
         
         
         
+        
         
     
 

From 4eff3981474c706350bd9f4f7c8a88e9b2501e9e Mon Sep 17 00:00:00 2001
From: pelaezryan 
Date: Tue, 27 Jun 2023 10:21:49 -0700
Subject: [PATCH 7/9] Preparation for v2.5.1 (#1155)

* Preparation for minor version v2.5.1

---------

Co-authored-by: Ryan Pelaez 
---
 CHANGELOG.md                                          | 11 +++++++++++
 README.md                                             |  2 +-
 amazon-kinesis-client-multilang/pom.xml               |  2 +-
 amazon-kinesis-client/pom.xml                         |  2 +-
 .../amazon/kinesis/retrieval/RetrievalConfig.java     |  2 +-
 pom.xml                                               |  2 +-
 6 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54a7892e..fc7ec987 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,17 @@
 For **1.x** release notes, please see [v1.x/CHANGELOG.md](https://github.com/awslabs/amazon-kinesis-client/blob/v1.x/CHANGELOG.md)
 
 ---
+### Release 2.5.1 (June 27, 2023)
+* [#1143](https://github.com/awslabs/amazon-kinesis-client/pull/1143) Upgrade MultiLangDaemon to support StreamARN
+* [#1145](https://github.com/awslabs/amazon-kinesis-client/pull/1145) Introduced GitHub actions to trigger Maven builds during merge/pull requests
+* [#1136](https://github.com/awslabs/amazon-kinesis-client/pull/1136) Added testing architecture and KCL 2.x basic polling/streaming tests
+* [#1153](https://github.com/awslabs/amazon-kinesis-client/pull/1153) Checkstyle: added `UnusedImports` check.
+* [#1150](https://github.com/awslabs/amazon-kinesis-client/pull/1150) Enabled Checkstyle validation of test resources.
+* [#1149](https://github.com/awslabs/amazon-kinesis-client/pull/1149) Bound Checkstyle to `validate` goal for automated enforcement.
+* [#1148](https://github.com/awslabs/amazon-kinesis-client/pull/1148) Code cleanup to faciliate Checkstyle enforcement.
+* [#1142](https://github.com/awslabs/amazon-kinesis-client/pull/1142) Upgrade Google Guava dependency version from 31.1-jre to 32.0.0-jre
+* [#1115](https://github.com/awslabs/amazon-kinesis-client/pull/1115) Update KCL version from 2.5.0 to 2.5.1-SNAPSHOT
+
 ### Release 2.5.0 (May 19, 2023)
 * **[#1109](https://github.com/awslabs/amazon-kinesis-client/pull/1109) Add support for stream ARNs**
 * **[#1065](https://github.com/awslabs/amazon-kinesis-client/pull/1065) Allow tags to be added when lease table is created**
diff --git a/README.md b/README.md
index 6328e115..3cc92799 100644
--- a/README.md
+++ b/README.md
@@ -56,7 +56,7 @@ The recommended way to use the KCL for Java is to consume it from Maven.
   
       software.amazon.kinesis
       amazon-kinesis-client
-      2.4.8
+      2.5.1
   
   ```
 
diff --git a/amazon-kinesis-client-multilang/pom.xml b/amazon-kinesis-client-multilang/pom.xml
index b3a48210..8494c3c8 100644
--- a/amazon-kinesis-client-multilang/pom.xml
+++ b/amazon-kinesis-client-multilang/pom.xml
@@ -21,7 +21,7 @@
   
     amazon-kinesis-client-pom
     software.amazon.kinesis
-    2.5.1-SNAPSHOT
+    2.5.1
   
   4.0.0
 
diff --git a/amazon-kinesis-client/pom.xml b/amazon-kinesis-client/pom.xml
index 30824281..2ba3aaac 100644
--- a/amazon-kinesis-client/pom.xml
+++ b/amazon-kinesis-client/pom.xml
@@ -22,7 +22,7 @@
   
     software.amazon.kinesis
     amazon-kinesis-client-pom
-    2.5.1-SNAPSHOT
+    2.5.1
   
 
   amazon-kinesis-client
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java
index 5d01edeb..ea302b19 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java
@@ -49,7 +49,7 @@ public class RetrievalConfig {
      */
     public static final String KINESIS_CLIENT_LIB_USER_AGENT = "amazon-kinesis-client-library-java";
 
-    public static final String KINESIS_CLIENT_LIB_USER_AGENT_VERSION = "2.5.1-SNAPSHOT";
+    public static final String KINESIS_CLIENT_LIB_USER_AGENT_VERSION = "2.5.1";
 
     /**
      * Client used to make calls to Kinesis for records retrieval
diff --git a/pom.xml b/pom.xml
index 90cec514..dcebcb9c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
   amazon-kinesis-client-pom
   pom
   Amazon Kinesis Client Library
-  2.5.1-SNAPSHOT
+  2.5.1
   The Amazon Kinesis Client Library for Java enables Java developers to easily consume and process data
     from Amazon Kinesis.
   

From a9b0d00852208ef2fac587633c58d561c30e1672 Mon Sep 17 00:00:00 2001
From: stair <123031771+stair-aws@users.noreply.github.com>
Date: Tue, 27 Jun 2023 15:24:03 -0400
Subject: [PATCH 8/9] Checkstyle: added additional checks to, primarily,
 safeguard against bugs. (#1154)

---
 .../multilang/messages/MessageTest.java        |  2 +-
 .../kinesis/retrieval/RetrievalConfig.java     |  2 +-
 ...rdShardRecordProcessorCheckpointerTest.java | 11 ++++-------
 .../metrics/EndingMetricsScopeTest.java        |  1 -
 .../retrieval/AWSExceptionManagerTest.java     | 18 ++++++------------
 .../retrieval/ThrottlingReporterTest.java      |  3 ---
 checkstyle/checkstyle.xml                      |  7 +++++++
 7 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java
index 86798080..62e5a741 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/MessageTest.java
@@ -49,7 +49,7 @@ public class MessageTest {
                 new ProcessRecordsMessage(),
                 new ShutdownRequestedMessage(),
                 new LeaseLostMessage(),
-                new ShardEndedMessage()
+                new ShardEndedMessage(),
         };
 
 //        TODO: fix this
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java
index ea302b19..3cb4a0d9 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/RetrievalConfig.java
@@ -152,7 +152,7 @@ public class RetrievalConfig {
         if (streamTracker().isMultiStream()) {
             throw new IllegalArgumentException(
                     "Cannot set initialPositionInStreamExtended when multiStreamTracker is set");
-        };
+        }
 
         final StreamIdentifier streamIdentifier = getSingleStreamIdentifier();
         final StreamConfig updatedConfig = new StreamConfig(streamIdentifier, initialPositionInStreamExtended);
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java
index 37a40b6b..98ce1dc5 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/checkpoint/ShardShardRecordProcessorCheckpointerTest.java
@@ -397,7 +397,7 @@ public class ShardShardRecordProcessorCheckpointerTest {
         assertThat(checkpointer.largestPermittedCheckpointValue(), equalTo(sequenceNumber));
     }
 
-    /*
+    /**
      * This test is a mixed test of checking some basic functionality of checkpointing at a sequence number and making
      * sure certain bounds checks and validations are being performed inside the checkpointer to prevent clients from
      * checkpointing out of order/too big/non-numeric values that aren't valid strings for them to be checkpointing
@@ -444,7 +444,7 @@ public class ShardShardRecordProcessorCheckpointerTest {
                 new ExtendedSequenceNumber("bogus-checkpoint-value"), // Can't checkpoint at non-numeric string
                 ExtendedSequenceNumber.SHARD_END, // Can't go to the end unless it is set as the max
                 ExtendedSequenceNumber.TRIM_HORIZON, // Can't go back to an initial sentinel value
-                ExtendedSequenceNumber.LATEST // Can't go back to an initial sentinel value
+                ExtendedSequenceNumber.LATEST, // Can't go back to an initial sentinel value
         };
         for (ExtendedSequenceNumber badCheckpointValue : valuesWeShouldNotBeAbleToCheckpointAt) {
             try {
@@ -477,7 +477,7 @@ public class ShardShardRecordProcessorCheckpointerTest {
                 processingCheckpointer.lastCheckpointValue(), equalTo(ExtendedSequenceNumber.SHARD_END));
     }
 
-    /*
+    /**
      * This test is a mixed test of checking some basic functionality of two phase checkpointing at a sequence number
      * and making sure certain bounds checks and validations are being performed inside the checkpointer to prevent
      * clients from checkpointing out of order/too big/non-numeric values that aren't valid strings for them to be
@@ -548,7 +548,7 @@ public class ShardShardRecordProcessorCheckpointerTest {
                         new ExtendedSequenceNumber("bogus-checkpoint-value"), // Can't checkpoint at non-numeric string
                         ExtendedSequenceNumber.SHARD_END, // Can't go to the end unless it is set as the max
                         ExtendedSequenceNumber.TRIM_HORIZON, // Can't go back to an initial sentinel value
-                        ExtendedSequenceNumber.LATEST // Can't go back to an initial sentinel value
+                        ExtendedSequenceNumber.LATEST, // Can't go back to an initial sentinel value
                 };
         for (ExtendedSequenceNumber badCheckpointValue : valuesWeShouldNotBeAbleToCheckpointAt) {
             try {
@@ -566,7 +566,6 @@ public class ShardShardRecordProcessorCheckpointerTest {
             assertThat("Largest sequence number should not have changed",
                     processingCheckpointer.largestPermittedCheckpointValue(), equalTo(thirdSequenceNumber));
             assertThat(checkpoint.getCheckpointObject(shardId).pendingCheckpoint(), nullValue());
-
         }
 
         // advance to third number
@@ -601,7 +600,6 @@ public class ShardShardRecordProcessorCheckpointerTest {
      *
      * @throws Exception
      */
-    @SuppressWarnings("serial")
     @Test
     public final void testMixedCheckpointCalls() throws Exception {
         for (LinkedHashMap testPlan : getMixedCallsTestPlan()) {
@@ -617,7 +615,6 @@ public class ShardShardRecordProcessorCheckpointerTest {
      *
      * @throws Exception
      */
-    @SuppressWarnings("serial")
     @Test
     public final void testMixedTwoPhaseCheckpointCalls() throws Exception {
         for (LinkedHashMap testPlan : getMixedCallsTestPlan()) {
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/EndingMetricsScopeTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/EndingMetricsScopeTest.java
index 2a32764d..a3d792ae 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/EndingMetricsScopeTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/metrics/EndingMetricsScopeTest.java
@@ -17,7 +17,6 @@ package software.amazon.kinesis.metrics;
 import org.junit.Test;
 
 import software.amazon.awssdk.services.cloudwatch.model.StandardUnit;
-import software.amazon.kinesis.metrics.EndingMetricsScope;
 
 public class EndingMetricsScopeTest {
 
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/AWSExceptionManagerTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/AWSExceptionManagerTest.java
index 8319a0ac..030979df 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/AWSExceptionManagerTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/AWSExceptionManagerTest.java
@@ -27,31 +27,28 @@ import static org.junit.Assert.assertThat;
 @Slf4j
 public class AWSExceptionManagerTest {
 
+    private static final String EXPECTED_HANDLING_MARKER = AWSExceptionManagerTest.class.getSimpleName();
+
+    private final AWSExceptionManager manager = new AWSExceptionManager();
+
     @Test
     public void testSpecificException() {
-        AWSExceptionManager manager = new AWSExceptionManager();
-        final String EXPECTED_HANDLING_MARKER = "Handled-TestException";
-
         manager.add(TestException.class, t -> {
             log.info("Handling test exception: {} -> {}", t.getMessage(), t.getAdditionalMessage());
             return new RuntimeException(EXPECTED_HANDLING_MARKER, t);
         });
 
-        TestException te = new TestException("Main Mesage", "Sub Message");
-
+        TestException te = new TestException("Main Message", "Sub Message");
 
         RuntimeException converted = manager.apply(te);
 
         assertThat(converted, isA(RuntimeException.class));
         assertThat(converted.getMessage(), equalTo(EXPECTED_HANDLING_MARKER));
         assertThat(converted.getCause(), equalTo(te));
-
     }
 
     @Test
     public void testParentException() {
-        AWSExceptionManager manager = new AWSExceptionManager();
-        final String EXPECTED_HANDLING_MARKER = "Handled-IllegalStateException";
         manager.add(IllegalArgumentException.class, i -> new RuntimeException("IllegalArgument", i));
         manager.add(Exception.class, i -> new RuntimeException("RawException", i));
         manager.add(IllegalStateException.class, i -> new RuntimeException(EXPECTED_HANDLING_MARKER, i));
@@ -66,8 +63,7 @@ public class AWSExceptionManagerTest {
 
     @Test
     public void testDefaultHandler() {
-        final String EXPECTED_HANDLING_MARKER = "Handled-Default";
-        AWSExceptionManager manager = new AWSExceptionManager().defaultFunction(i -> new RuntimeException(EXPECTED_HANDLING_MARKER, i));
+        manager.defaultFunction(i -> new RuntimeException(EXPECTED_HANDLING_MARKER, i));
 
         manager.add(IllegalArgumentException.class, i -> new RuntimeException("IllegalArgument", i));
         manager.add(Exception.class, i -> new RuntimeException("RawException", i));
@@ -83,8 +79,6 @@ public class AWSExceptionManagerTest {
 
     @Test
     public void testIdHandler() {
-        AWSExceptionManager manager = new AWSExceptionManager();
-
         manager.add(IllegalArgumentException.class, i -> new RuntimeException("IllegalArgument", i));
         manager.add(Exception.class, i -> new RuntimeException("RawException", i));
         manager.add(IllegalStateException.class, i -> i);
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/ThrottlingReporterTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/ThrottlingReporterTest.java
index eec5ea9e..f13f0ad0 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/ThrottlingReporterTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/retrieval/ThrottlingReporterTest.java
@@ -24,7 +24,6 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.slf4j.Logger;
-import software.amazon.kinesis.retrieval.ThrottlingReporter;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ThrottlingReporterTest {
@@ -40,7 +39,6 @@ public class ThrottlingReporterTest {
         reporter.throttled();
         verify(throttleLog).warn(anyString());
         verify(throttleLog, never()).error(anyString());
-
     }
 
     @Test
@@ -63,7 +61,6 @@ public class ThrottlingReporterTest {
         reporter.throttled();
         verify(throttleLog, times(2)).warn(anyString());
         verify(throttleLog, times(3)).error(anyString());
-
     }
 
     private class LogTestingThrottingReporter extends ThrottlingReporter {
diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml
index 10031e23..76c4b330 100644
--- a/checkstyle/checkstyle.xml
+++ b/checkstyle/checkstyle.xml
@@ -23,8 +23,13 @@
 
     
         
+        
         
+        
+        
+        
         
+        
         
         
         
@@ -36,7 +41,9 @@
         
         
         
+        
         
+        
         
     
 

From feadd5e043522456e5bd9cdc0c551b01547e26ec Mon Sep 17 00:00:00 2001
From: stair <123031771+stair-aws@users.noreply.github.com>
Date: Wed, 28 Jun 2023 10:36:32 -0400
Subject: [PATCH 9/9] Fix NPE on graceful shutdown before DDB
 `LeaseCoordinator` starts. (#1157)

---
 .../dynamodb/DynamoDBLeaseCoordinator.java    |  5 +--
 .../DynamoDBLeaseCoordinatorTest.java         | 32 ++++++++++++++-----
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinator.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinator.java
index 07e9068d..da6d8e07 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinator.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinator.java
@@ -329,8 +329,9 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
 
     @Override
     public void stopLeaseTaker() {
-        takerFuture.cancel(false);
-
+        if (takerFuture != null) {
+            takerFuture.cancel(false);
+        }
     }
 
     @Override
diff --git a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorTest.java b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorTest.java
index caa7a6c7..cf1c536b 100644
--- a/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorTest.java
+++ b/amazon-kinesis-client/src/test/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseCoordinatorTest.java
@@ -1,6 +1,5 @@
 package software.amazon.kinesis.leases.dynamodb;
 
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -12,7 +11,7 @@ import software.amazon.kinesis.metrics.MetricsFactory;
 
 import java.util.UUID;
 
-import static org.mockito.Mockito.times;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -51,17 +50,34 @@ public class DynamoDBLeaseCoordinatorTest {
 
         leaseCoordinator.initialize();
 
-        verify(leaseRefresher, times(1)).createLeaseTableIfNotExists();
-        verify(leaseRefresher, times(1)).waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS);
+        verify(leaseRefresher).createLeaseTableIfNotExists();
+        verify(leaseRefresher).waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS);
     }
 
-    @Test
+    @Test(expected = DependencyException.class)
     public void testInitialize_tableCreationFails() throws Exception {
         when(leaseRefresher.createLeaseTableIfNotExists()).thenReturn(false);
         when(leaseRefresher.waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS)).thenReturn(false);
 
-        Assert.assertThrows(DependencyException.class, () -> leaseCoordinator.initialize());
-        verify(leaseRefresher, times(1)).createLeaseTableIfNotExists();
-        verify(leaseRefresher, times(1)).waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS);
+        try {
+            leaseCoordinator.initialize();
+        } finally {
+            verify(leaseRefresher).createLeaseTableIfNotExists();
+            verify(leaseRefresher).waitUntilLeaseTableExists(SECONDS_BETWEEN_POLLS, TIMEOUT_SECONDS);
+        }
     }
+
+    /**
+     * Validates a {@link NullPointerException} is not thrown when the lease taker
+     * is stopped before it starts/exists.
+     *
+     * @see issue #745
+     * @see issue #900
+     */
+    @Test
+    public void testStopLeaseTakerBeforeStart() {
+        leaseCoordinator.stopLeaseTaker();
+        assertTrue(leaseCoordinator.getAssignments().isEmpty());
+    }
+
 }