diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/coordinator/KinesisClientLibConfiguration.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/coordinator/KinesisClientLibConfiguration.java
index d8d9068d..179eb9e4 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/coordinator/KinesisClientLibConfiguration.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/coordinator/KinesisClientLibConfiguration.java
@@ -18,11 +18,9 @@ import java.util.Date;
import java.util.Optional;
import java.util.Set;
-import org.apache.commons.lang3.Validate;
-
import com.google.common.collect.ImmutableSet;
-
import lombok.Getter;
+import org.apache.commons.lang3.Validate;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.kinesis.checkpoint.ShardRecordProcessorCheckpointer;
import software.amazon.kinesis.common.InitialPositionInStream;
@@ -119,14 +117,16 @@ public class KinesisClientLibConfiguration {
/**
* Metrics dimensions that always will be enabled regardless of the config provided by user.
*/
- public static final Set METRICS_ALWAYS_ENABLED_DIMENSIONS = ImmutableSet
- .of(MetricsUtil.OPERATION_DIMENSION_NAME);
+ public static final Set METRICS_ALWAYS_ENABLED_DIMENSIONS =
+ ImmutableSet.of(MetricsUtil.OPERATION_DIMENSION_NAME);
/**
* Allowed dimensions for CloudWatch metrics. By default, worker ID dimension will be disabled.
*/
- public static final Set DEFAULT_METRICS_ENABLED_DIMENSIONS = ImmutableSet. builder()
- .addAll(METRICS_ALWAYS_ENABLED_DIMENSIONS).add(MetricsUtil.SHARD_ID_DIMENSION_NAME).build();
+ public static final Set DEFAULT_METRICS_ENABLED_DIMENSIONS = ImmutableSet.builder()
+ .addAll(METRICS_ALWAYS_ENABLED_DIMENSIONS)
+ .add(MetricsUtil.SHARD_ID_DIMENSION_NAME)
+ .build();
/**
* Metrics dimensions that signify all possible dimensions.
@@ -285,8 +285,8 @@ public class KinesisClientLibConfiguration {
* @param workerId
* Used to distinguish different workers/processes of a Kinesis application
*/
- public KinesisClientLibConfiguration(String applicationName, String streamName,
- AwsCredentialsProvider credentialsProvider, String workerId) {
+ public KinesisClientLibConfiguration(
+ String applicationName, String streamName, AwsCredentialsProvider credentialsProvider, String workerId) {
this(applicationName, streamName, credentialsProvider, credentialsProvider, credentialsProvider, workerId);
}
@@ -308,16 +308,36 @@ public class KinesisClientLibConfiguration {
* @param workerId
* Used to distinguish different workers/processes of a Kinesis application
*/
- public KinesisClientLibConfiguration(String applicationName, String streamName,
- AwsCredentialsProvider kinesisCredentialsProvider, AwsCredentialsProvider dynamoDBCredentialsProvider,
- AwsCredentialsProvider cloudWatchCredentialsProvider, String workerId) {
- this(applicationName, streamName, null, null, DEFAULT_INITIAL_POSITION_IN_STREAM, kinesisCredentialsProvider,
- dynamoDBCredentialsProvider, cloudWatchCredentialsProvider, DEFAULT_FAILOVER_TIME_MILLIS, workerId,
- DEFAULT_MAX_RECORDS, DEFAULT_IDLETIME_BETWEEN_READS_MILLIS,
- DEFAULT_DONT_CALL_PROCESS_RECORDS_FOR_EMPTY_RECORD_LIST, DEFAULT_PARENT_SHARD_POLL_INTERVAL_MILLIS,
- DEFAULT_SHARD_SYNC_INTERVAL_MILLIS, DEFAULT_CLEANUP_LEASES_UPON_SHARDS_COMPLETION,
- DEFAULT_TASK_BACKOFF_TIME_MILLIS, DEFAULT_METRICS_BUFFER_TIME_MILLIS, DEFAULT_METRICS_MAX_QUEUE_SIZE,
- DEFAULT_VALIDATE_SEQUENCE_NUMBER_BEFORE_CHECKPOINTING, null, DEFAULT_SHUTDOWN_GRACE_MILLIS,
+ public KinesisClientLibConfiguration(
+ String applicationName,
+ String streamName,
+ AwsCredentialsProvider kinesisCredentialsProvider,
+ AwsCredentialsProvider dynamoDBCredentialsProvider,
+ AwsCredentialsProvider cloudWatchCredentialsProvider,
+ String workerId) {
+ this(
+ applicationName,
+ streamName,
+ null,
+ null,
+ DEFAULT_INITIAL_POSITION_IN_STREAM,
+ kinesisCredentialsProvider,
+ dynamoDBCredentialsProvider,
+ cloudWatchCredentialsProvider,
+ DEFAULT_FAILOVER_TIME_MILLIS,
+ workerId,
+ DEFAULT_MAX_RECORDS,
+ DEFAULT_IDLETIME_BETWEEN_READS_MILLIS,
+ DEFAULT_DONT_CALL_PROCESS_RECORDS_FOR_EMPTY_RECORD_LIST,
+ DEFAULT_PARENT_SHARD_POLL_INTERVAL_MILLIS,
+ DEFAULT_SHARD_SYNC_INTERVAL_MILLIS,
+ DEFAULT_CLEANUP_LEASES_UPON_SHARDS_COMPLETION,
+ DEFAULT_TASK_BACKOFF_TIME_MILLIS,
+ DEFAULT_METRICS_BUFFER_TIME_MILLIS,
+ DEFAULT_METRICS_MAX_QUEUE_SIZE,
+ DEFAULT_VALIDATE_SEQUENCE_NUMBER_BEFORE_CHECKPOINTING,
+ null,
+ DEFAULT_SHUTDOWN_GRACE_MILLIS,
DEFAULT_SCHEDULER_INITIALIZATION_BACKOFF_TIME_MILLIS);
}
@@ -377,20 +397,53 @@ public class KinesisClientLibConfiguration {
*/
// CHECKSTYLE:IGNORE HiddenFieldCheck FOR NEXT 26 LINES
// CHECKSTYLE:IGNORE ParameterNumber FOR NEXT 26 LINES
- public KinesisClientLibConfiguration(String applicationName, String streamName, String kinesisEndpoint,
- InitialPositionInStream initialPositionInStream, AwsCredentialsProvider kinesisCredentialsProvider,
- AwsCredentialsProvider dynamoDBCredentialsProvider, AwsCredentialsProvider cloudWatchCredentialsProvider,
- long failoverTimeMillis, String workerId, int maxRecords, long idleTimeBetweenReadsInMillis,
- boolean callProcessRecordsEvenForEmptyRecordList, long parentShardPollIntervalMillis,
- long shardSyncIntervalMillis, boolean cleanupTerminatedShardsBeforeExpiry, long taskBackoffTimeMillis,
- long metricsBufferTimeMillis, int metricsMaxQueueSize, boolean validateSequenceNumberBeforeCheckpointing,
- String regionName, long shutdownGraceMillis, long schedulerInitializationBackoffTimeMillis) {
- this(applicationName, streamName, kinesisEndpoint, null, initialPositionInStream, kinesisCredentialsProvider,
- dynamoDBCredentialsProvider, cloudWatchCredentialsProvider, failoverTimeMillis, workerId, maxRecords,
- idleTimeBetweenReadsInMillis, callProcessRecordsEvenForEmptyRecordList, parentShardPollIntervalMillis,
- shardSyncIntervalMillis, cleanupTerminatedShardsBeforeExpiry, taskBackoffTimeMillis,
- metricsBufferTimeMillis, metricsMaxQueueSize, validateSequenceNumberBeforeCheckpointing, regionName,
- shutdownGraceMillis, schedulerInitializationBackoffTimeMillis);
+ public KinesisClientLibConfiguration(
+ String applicationName,
+ String streamName,
+ String kinesisEndpoint,
+ InitialPositionInStream initialPositionInStream,
+ AwsCredentialsProvider kinesisCredentialsProvider,
+ AwsCredentialsProvider dynamoDBCredentialsProvider,
+ AwsCredentialsProvider cloudWatchCredentialsProvider,
+ long failoverTimeMillis,
+ String workerId,
+ int maxRecords,
+ long idleTimeBetweenReadsInMillis,
+ boolean callProcessRecordsEvenForEmptyRecordList,
+ long parentShardPollIntervalMillis,
+ long shardSyncIntervalMillis,
+ boolean cleanupTerminatedShardsBeforeExpiry,
+ long taskBackoffTimeMillis,
+ long metricsBufferTimeMillis,
+ int metricsMaxQueueSize,
+ boolean validateSequenceNumberBeforeCheckpointing,
+ String regionName,
+ long shutdownGraceMillis,
+ long schedulerInitializationBackoffTimeMillis) {
+ this(
+ applicationName,
+ streamName,
+ kinesisEndpoint,
+ null,
+ initialPositionInStream,
+ kinesisCredentialsProvider,
+ dynamoDBCredentialsProvider,
+ cloudWatchCredentialsProvider,
+ failoverTimeMillis,
+ workerId,
+ maxRecords,
+ idleTimeBetweenReadsInMillis,
+ callProcessRecordsEvenForEmptyRecordList,
+ parentShardPollIntervalMillis,
+ shardSyncIntervalMillis,
+ cleanupTerminatedShardsBeforeExpiry,
+ taskBackoffTimeMillis,
+ metricsBufferTimeMillis,
+ metricsMaxQueueSize,
+ validateSequenceNumberBeforeCheckpointing,
+ regionName,
+ shutdownGraceMillis,
+ schedulerInitializationBackoffTimeMillis);
}
/**
@@ -449,15 +502,30 @@ public class KinesisClientLibConfiguration {
*/
// CHECKSTYLE:IGNORE HiddenFieldCheck FOR NEXT 26 LINES
// CHECKSTYLE:IGNORE ParameterNumber FOR NEXT 26 LINES
- public KinesisClientLibConfiguration(String applicationName, String streamName, String kinesisEndpoint,
- String dynamoDBEndpoint, InitialPositionInStream initialPositionInStream,
- AwsCredentialsProvider kinesisCredentialsProvider, AwsCredentialsProvider dynamoDBCredentialsProvider,
- AwsCredentialsProvider cloudWatchCredentialsProvider, long failoverTimeMillis, String workerId,
- int maxRecords, long idleTimeBetweenReadsInMillis, boolean callProcessRecordsEvenForEmptyRecordList,
- long parentShardPollIntervalMillis, long shardSyncIntervalMillis,
- boolean cleanupTerminatedShardsBeforeExpiry, long taskBackoffTimeMillis, long metricsBufferTimeMillis,
- int metricsMaxQueueSize, boolean validateSequenceNumberBeforeCheckpointing, String regionName,
- long shutdownGraceMillis, long schedulerInitializationBackoffTimeMillis) {
+ public KinesisClientLibConfiguration(
+ String applicationName,
+ String streamName,
+ String kinesisEndpoint,
+ String dynamoDBEndpoint,
+ InitialPositionInStream initialPositionInStream,
+ AwsCredentialsProvider kinesisCredentialsProvider,
+ AwsCredentialsProvider dynamoDBCredentialsProvider,
+ AwsCredentialsProvider cloudWatchCredentialsProvider,
+ long failoverTimeMillis,
+ String workerId,
+ int maxRecords,
+ long idleTimeBetweenReadsInMillis,
+ boolean callProcessRecordsEvenForEmptyRecordList,
+ long parentShardPollIntervalMillis,
+ long shardSyncIntervalMillis,
+ boolean cleanupTerminatedShardsBeforeExpiry,
+ long taskBackoffTimeMillis,
+ long metricsBufferTimeMillis,
+ int metricsMaxQueueSize,
+ boolean validateSequenceNumberBeforeCheckpointing,
+ String regionName,
+ long shutdownGraceMillis,
+ long schedulerInitializationBackoffTimeMillis) {
// Check following values are greater than zero
checkIsValuePositive("FailoverTimeMillis", failoverTimeMillis);
checkIsValuePositive("IdleTimeBetweenReadsInMillis", idleTimeBetweenReadsInMillis);
@@ -495,8 +563,8 @@ public class KinesisClientLibConfiguration {
this.maxLeasesToStealAtOneTime = DEFAULT_MAX_LEASES_TO_STEAL_AT_ONE_TIME;
this.initialLeaseTableReadCapacity = DEFAULT_INITIAL_LEASE_TABLE_READ_CAPACITY;
this.initialLeaseTableWriteCapacity = DEFAULT_INITIAL_LEASE_TABLE_WRITE_CAPACITY;
- this.initialPositionInStreamExtended = InitialPositionInStreamExtended
- .newInitialPosition(initialPositionInStream);
+ this.initialPositionInStreamExtended =
+ InitialPositionInStreamExtended.newInitialPosition(initialPositionInStream);
this.skipShardSyncAtWorkerInitializationIfLeasesExist = DEFAULT_SKIP_SHARD_SYNC_AT_STARTUP_IF_LEASES_EXIST;
this.shardPrioritization = DEFAULT_SHARD_PRIORITIZATION;
this.recordsFetcherFactory = new SimpleRecordsFetcherFactory();
@@ -559,15 +627,30 @@ public class KinesisClientLibConfiguration {
*/
// CHECKSTYLE:IGNORE HiddenFieldCheck FOR NEXT 26 LINES
// CHECKSTYLE:IGNORE ParameterNumber FOR NEXT 26 LINES
- public KinesisClientLibConfiguration(String applicationName, String streamName, String kinesisEndpoint,
- String dynamoDBEndpoint, InitialPositionInStream initialPositionInStream,
- AwsCredentialsProvider kinesisCredentialsProvider, AwsCredentialsProvider dynamoDBCredentialsProvider,
- AwsCredentialsProvider cloudWatchCredentialsProvider, long failoverTimeMillis, String workerId,
- int maxRecords, long idleTimeBetweenReadsInMillis, boolean callProcessRecordsEvenForEmptyRecordList,
- long parentShardPollIntervalMillis, long shardSyncIntervalMillis,
- boolean cleanupTerminatedShardsBeforeExpiry, long taskBackoffTimeMillis, long metricsBufferTimeMillis,
- int metricsMaxQueueSize, boolean validateSequenceNumberBeforeCheckpointing, String regionName,
- RecordsFetcherFactory recordsFetcherFactory, long schedulerInitializationBackoffTimeMillis) {
+ public KinesisClientLibConfiguration(
+ String applicationName,
+ String streamName,
+ String kinesisEndpoint,
+ String dynamoDBEndpoint,
+ InitialPositionInStream initialPositionInStream,
+ AwsCredentialsProvider kinesisCredentialsProvider,
+ AwsCredentialsProvider dynamoDBCredentialsProvider,
+ AwsCredentialsProvider cloudWatchCredentialsProvider,
+ long failoverTimeMillis,
+ String workerId,
+ int maxRecords,
+ long idleTimeBetweenReadsInMillis,
+ boolean callProcessRecordsEvenForEmptyRecordList,
+ long parentShardPollIntervalMillis,
+ long shardSyncIntervalMillis,
+ boolean cleanupTerminatedShardsBeforeExpiry,
+ long taskBackoffTimeMillis,
+ long metricsBufferTimeMillis,
+ int metricsMaxQueueSize,
+ boolean validateSequenceNumberBeforeCheckpointing,
+ String regionName,
+ RecordsFetcherFactory recordsFetcherFactory,
+ long schedulerInitializationBackoffTimeMillis) {
// Check following values are greater than zero
checkIsValuePositive("FailoverTimeMillis", failoverTimeMillis);
checkIsValuePositive("IdleTimeBetweenReadsInMillis", idleTimeBetweenReadsInMillis);
@@ -607,8 +690,8 @@ public class KinesisClientLibConfiguration {
this.maxLeasesToStealAtOneTime = DEFAULT_MAX_LEASES_TO_STEAL_AT_ONE_TIME;
this.initialLeaseTableReadCapacity = DEFAULT_INITIAL_LEASE_TABLE_READ_CAPACITY;
this.initialLeaseTableWriteCapacity = DEFAULT_INITIAL_LEASE_TABLE_WRITE_CAPACITY;
- this.initialPositionInStreamExtended = InitialPositionInStreamExtended
- .newInitialPosition(initialPositionInStream);
+ this.initialPositionInStreamExtended =
+ InitialPositionInStreamExtended.newInitialPosition(initialPositionInStream);
this.skipShardSyncAtWorkerInitializationIfLeasesExist = DEFAULT_SKIP_SHARD_SYNC_AT_STARTUP_IF_LEASES_EXIST;
this.shardPrioritization = DEFAULT_SHARD_PRIORITIZATION;
this.recordsFetcherFactory = recordsFetcherFactory;
@@ -933,8 +1016,8 @@ public class KinesisClientLibConfiguration {
*/
public KinesisClientLibConfiguration withInitialPositionInStream(InitialPositionInStream initialPositionInStream) {
this.initialPositionInStream = initialPositionInStream;
- this.initialPositionInStreamExtended = InitialPositionInStreamExtended
- .newInitialPosition(initialPositionInStream);
+ this.initialPositionInStreamExtended =
+ InitialPositionInStreamExtended.newInitialPosition(initialPositionInStream);
return this;
}
@@ -984,8 +1067,8 @@ public class KinesisClientLibConfiguration {
public KinesisClientLibConfiguration withMaxRecords(int maxRecords) {
checkIsValuePositive("MaxRecords", (long) maxRecords);
if (maxRecords > DEFAULT_MAX_RECORDS) {
- throw new IllegalArgumentException(
- "maxRecords must be less than or equal to " + DEFAULT_MAX_RECORDS + " but current value is " + maxRecords);
+ throw new IllegalArgumentException("maxRecords must be less than or equal to " + DEFAULT_MAX_RECORDS
+ + " but current value is " + maxRecords);
}
this.maxRecords = maxRecords;
return this;
@@ -1145,8 +1228,10 @@ public class KinesisClientLibConfiguration {
} else if (metricsEnabledDimensions.contains(MetricsScope.METRICS_DIMENSIONS_ALL)) {
this.metricsEnabledDimensions = METRICS_DIMENSIONS_ALL;
} else {
- this.metricsEnabledDimensions = ImmutableSet. builder().addAll(metricsEnabledDimensions)
- .addAll(METRICS_ALWAYS_ENABLED_DIMENSIONS).build();
+ this.metricsEnabledDimensions = ImmutableSet.builder()
+ .addAll(metricsEnabledDimensions)
+ .addAll(METRICS_ALWAYS_ENABLED_DIMENSIONS)
+ .build();
}
return this;
}
@@ -1277,7 +1362,8 @@ public class KinesisClientLibConfiguration {
* @return this configuration object
*/
public KinesisClientLibConfiguration withMaxLeaseRenewalThreads(int maxLeaseRenewalThreads) {
- Validate.isTrue(maxLeaseRenewalThreads > 2,
+ Validate.isTrue(
+ maxLeaseRenewalThreads > 2,
"The maximum number of lease renewal threads must be greater than or equal to 2.");
this.maxLeaseRenewalThreads = maxLeaseRenewalThreads;
@@ -1337,7 +1423,8 @@ public class KinesisClientLibConfiguration {
* @return KinesisClientLibConfiguration
*/
public KinesisClientLibConfiguration withDataFetchingStrategy(String dataFetchingStrategy) {
- this.recordsFetcherFactory.dataFetchingStrategy(DataFetchingStrategy.valueOf(dataFetchingStrategy.toUpperCase()));
+ this.recordsFetcherFactory.dataFetchingStrategy(
+ DataFetchingStrategy.valueOf(dataFetchingStrategy.toUpperCase()));
return this;
}
@@ -1423,7 +1510,8 @@ public class KinesisClientLibConfiguration {
* Interval in milliseconds between retrying the scheduler initialization.
* @return
*/
- public KinesisClientLibConfiguration withSchedulerInitializationBackoffTimeMillis(long schedulerInitializationBackoffTimeMillis) {
+ public KinesisClientLibConfiguration withSchedulerInitializationBackoffTimeMillis(
+ long schedulerInitializationBackoffTimeMillis) {
checkIsValuePositive("schedulerInitializationBackoffTimeMillis", schedulerInitializationBackoffTimeMillis);
this.schedulerInitializationBackoffTimeMillis = schedulerInitializationBackoffTimeMillis;
return this;
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDERRTask.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDERRTask.java
index f175d905..1f67ece5 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDERRTask.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDERRTask.java
@@ -23,8 +23,7 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
class DrainChildSTDERRTask extends LineReaderTask {
- DrainChildSTDERRTask() {
- }
+ DrainChildSTDERRTask() {}
@Override
protected HandleLineResult handleLine(String line) {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDOUTTask.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDOUTTask.java
index 19208304..573fe570 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDOUTTask.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/DrainChildSTDOUTTask.java
@@ -22,23 +22,22 @@ import lombok.extern.slf4j.Slf4j;
* This class is used to drain the STDOUT of the child process. After the child process has been given a shutdown
* message and responded indicating that it is shutdown, we attempt to close the input and outputs of that process so
* that the process can exit.
- *
+ *
* To understand why this is necessary, consider the following scenario:
- *
+ *
*
* - Child process responds that it is done with shutdown.
* - Child process prints debugging text to STDOUT that fills the pipe buffer so child becomes blocked.
* - Parent process doesn't drain child process's STDOUT.
* - Child process remains blocked.
*
- *
+ *
* To prevent the child process from becoming blocked in this way, it is the responsibility of the parent process to
* drain the child process's STDOUT. We reprint each drained line to our log to permit debugging.
*/
@Slf4j
class DrainChildSTDOUTTask extends LineReaderTask {
- DrainChildSTDOUTTask() {
- }
+ DrainChildSTDOUTTask() {}
@Override
protected HandleLineResult handleLine(String line) {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/GetNextMessageTask.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/GetNextMessageTask.java
index 34fe30d3..a9fca27c 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/GetNextMessageTask.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/GetNextMessageTask.java
@@ -17,10 +17,9 @@ package software.amazon.kinesis.multilang;
import java.io.BufferedReader;
import java.io.IOException;
-import software.amazon.kinesis.multilang.messages.Message;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import lombok.extern.slf4j.Slf4j;
+import software.amazon.kinesis.multilang.messages.Message;
/**
* Gets the next message off the STDOUT of the child process. Throws an exception if a message is not found before the
@@ -34,7 +33,7 @@ class GetNextMessageTask extends LineReaderTask {
/**
* Constructor.
- *
+ *
* @param objectMapper An object mapper for decoding json messages from the input stream.
*/
GetNextMessageTask(ObjectMapper objectMapper) {
@@ -43,7 +42,7 @@ class GetNextMessageTask extends LineReaderTask {
/**
* Checks if a line is an empty line.
- *
+ *
* @param line A string
* @return True if the line is an empty string, i.e. "", false otherwise.
*/
@@ -71,8 +70,10 @@ class GetNextMessageTask extends LineReaderTask {
@Override
protected Message returnAfterException(Exception e) {
- throw new RuntimeException("Encountered an error while reading a line from STDIN for shard " + getShardId()
- + " so won't be able to return a message.", e);
+ throw new RuntimeException(
+ "Encountered an error while reading a line from STDIN for shard " + getShardId()
+ + " so won't be able to return a message.",
+ e);
}
@Override
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/LineReaderTask.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/LineReaderTask.java
index 3c01c7b7..915fc088 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/LineReaderTask.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/LineReaderTask.java
@@ -30,7 +30,7 @@ import lombok.extern.slf4j.Slf4j;
* {@link #returnAfterEndOfInput()}
* {@link #returnAfterException(Exception)}
*
- *
+ *
* @param
*/
@Slf4j
@@ -41,8 +41,7 @@ abstract class LineReaderTask implements Callable {
private String shardId;
- LineReaderTask() {
- }
+ LineReaderTask() {}
/**
* Reads lines off the input stream until a return value is set, or an exception is encountered, or the end of the
@@ -72,7 +71,7 @@ abstract class LineReaderTask implements Callable {
* return from the {@link #call()} function by having a value, indicating that value should be returned immediately
* without reading further, or not having a value, indicating that more lines of input need to be read before
* returning.
- *
+ *
* @param line A line read from the input stream.
* @return HandleLineResult which may or may not have a has return value, indicating to return or not return yet
* respectively.
@@ -83,7 +82,7 @@ abstract class LineReaderTask implements Callable {
* This method will be called if there is an error while reading from the input stream. The return value of this
* method will be returned as the result of this Callable unless an Exception is thrown. If an Exception is thrown
* then that exception will be thrown by the Callable.
- *
+ *
* @param e An exception that occurred while reading from the input stream.
* @return What to return.
*/
@@ -93,7 +92,7 @@ abstract class LineReaderTask implements Callable {
* This method will be called once the end of the input stream is reached. The return value of this method will be
* returned as the result of this Callable. Implementations of this method are welcome to throw a runtime exception
* to indicate that the task was unsuccessful.
- *
+ *
* @return What to return.
*/
protected abstract T returnAfterEndOfInput();
@@ -101,7 +100,7 @@ abstract class LineReaderTask implements Callable {
/**
* Allows subclasses to provide more detailed logs. Specifically, this allows the drain tasks and GetNextMessageTask
* to log which shard they're working on.
- *
+ *
* @return The shard id
*/
public String getShardId() {
@@ -110,7 +109,7 @@ abstract class LineReaderTask implements Callable {
/**
* The description should be a string explaining what this particular LineReader class does.
- *
+ *
* @return The description.
*/
public String getDescription() {
@@ -121,7 +120,7 @@ abstract class LineReaderTask implements Callable {
* The result of a call to {@link LineReaderTask#handleLine(String)}. Allows implementations of that method to
* indicate whether a particular invocation of that method produced a return for this task or not. If a return value
* doesn't exist the {@link #call()} method will continue to the next line.
- *
+ *
* @param
*/
protected class HandleLineResult {
@@ -158,7 +157,7 @@ abstract class LineReaderTask implements Callable {
* {@link MultiLangShardRecordProcessor#initialize(String)} is called. So we follow a pattern where the attributes are
* set inside this method instead of the constructor so that this object will be initialized when all its attributes
* are known to the record processor.
- *
+ *
* @param stream
* @param shardId
* @param description
@@ -180,5 +179,4 @@ abstract class LineReaderTask implements Callable {
this.description = description;
return this;
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageReader.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageReader.java
index a649490c..a8d5f64f 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageReader.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageReader.java
@@ -20,19 +20,19 @@ import java.io.InputStreamReader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
-import software.amazon.kinesis.multilang.messages.Message;
import com.fasterxml.jackson.databind.ObjectMapper;
+import software.amazon.kinesis.multilang.messages.Message;
/**
* Provides methods for interacting with the child process's STDOUT.
- *
+ *
* {@link #getNextMessageFromSTDOUT()} reads lines from the child process's STDOUT and attempts to decode a
* {@link Message} object from each line. A child process's STDOUT could have lines that don't contain data related to
* the multi-language protocol, such as when the child process prints debugging information to its STDOUT (instead of
* logging to a file), also when a child processes writes a Message it is expected to prepend and append a new line
* character to their message to help ensure that it is isolated on a line all by itself which results in empty lines
* being present in STDOUT. Lines which cannot be decoded to a Message object are ignored.
- *
+ *
* {@link #drainSTDOUT()} simply reads all data from the child process's STDOUT until the stream is closed.
*/
class MessageReader {
@@ -48,19 +48,18 @@ class MessageReader {
/**
* Use the initialize methods after construction.
*/
- MessageReader() {
- }
+ MessageReader() {}
/**
* Returns a future which represents an attempt to read the next message in the child process's STDOUT. If the task
* is successful, the result of the future will be the next message found in the child process's STDOUT, if the task
* is unable to find a message before the child process's STDOUT is closed, or reading from STDOUT causes an
* IOException, then an execution exception will be generated by this future.
- *
+ *
* The task employed by this method reads from the child process's STDOUT line by line. The task attempts to decode
* each line into a {@link Message} object. Lines that fail to decode to a Message are ignored and the task
* continues to the next line until it finds a Message.
- *
+ *
* @return
*/
Future getNextMessageFromSTDOUT() {
@@ -73,7 +72,7 @@ class MessageReader {
* Returns a future that represents a computation that drains the STDOUT of the child process. That future's result
* is true if the end of the child's STDOUT is reached, its result is false if there was an error while reading from
* the stream. This task will log all the lines it drains to permit debugging.
- *
+ *
* @return
*/
Future drainSTDOUT() {
@@ -89,19 +88,16 @@ class MessageReader {
* {@link MultiLangShardRecordProcessor#initialize(String)} is called. So we follow a pattern where the attributes are
* set inside this method instead of the constructor so that this object will be initialized when all its attributes
* are known to the record processor.
- *
+ *
* @param stream Used to read messages from the subprocess.
* @param shardId The shard we're working on.
* @param objectMapper The object mapper to decode messages.
* @param executorService An executor service to run tasks in.
*/
- MessageReader initialize(InputStream stream,
- String shardId,
- ObjectMapper objectMapper,
- ExecutorService executorService) {
- return this.initialize(new BufferedReader(new InputStreamReader(stream)), shardId, objectMapper,
- executorService);
-
+ MessageReader initialize(
+ InputStream stream, String shardId, ObjectMapper objectMapper, ExecutorService executorService) {
+ return this.initialize(
+ new BufferedReader(new InputStreamReader(stream)), shardId, objectMapper, executorService);
}
/**
@@ -110,10 +106,8 @@ class MessageReader {
* @param objectMapper The object mapper to decode messages.
* @param executorService An executor service to run tasks in.
*/
- MessageReader initialize(BufferedReader reader,
- String shardId,
- ObjectMapper objectMapper,
- ExecutorService executorService) {
+ MessageReader initialize(
+ BufferedReader reader, String shardId, ObjectMapper objectMapper, ExecutorService executorService) {
this.reader = reader;
this.shardId = shardId;
this.objectMapper = objectMapper;
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageWriter.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageWriter.java
index 371c044b..c50c2004 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageWriter.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MessageWriter.java
@@ -23,7 +23,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import lombok.extern.slf4j.Slf4j;
import software.amazon.kinesis.lifecycle.events.InitializationInput;
import software.amazon.kinesis.lifecycle.events.LeaseLostInput;
@@ -55,13 +54,12 @@ class MessageWriter {
/**
* Use initialize method after construction.
*/
- MessageWriter() {
- }
+ MessageWriter() {}
/**
* Writes the message then writes the line separator provided by the system. Flushes each message to guarantee it
* is delivered as soon as possible to the subprocess.
- *
+ *
* @param message A message to be written to the subprocess.
* @return
* @throws IOException
@@ -76,7 +74,10 @@ class MessageWriter {
*/
synchronized (writer) {
writer.write(message, 0, message.length());
- writer.write(System.lineSeparator(), 0, System.lineSeparator().length());
+ writer.write(
+ System.lineSeparator(),
+ 0,
+ System.lineSeparator().length());
writer.flush();
}
log.info("Message size == {} bytes for shard {}", message.getBytes().length, shardId);
@@ -98,7 +99,7 @@ class MessageWriter {
/**
* Converts the message to a JSON string and writes it to the subprocess.
- *
+ *
* @param message A message to be written to the subprocess.
* @return
*/
@@ -108,9 +109,9 @@ class MessageWriter {
String jsonText = objectMapper.writeValueAsString(message);
return writeMessageToOutput(jsonText);
} catch (IOException e) {
- String errorMessage =
- String.format("Encountered I/O error while writing %s action to subprocess", message.getClass()
- .getSimpleName());
+ String errorMessage = String.format(
+ "Encountered I/O error while writing %s action to subprocess",
+ message.getClass().getSimpleName());
log.error(errorMessage, e);
throw new RuntimeException(errorMessage, e);
}
@@ -118,7 +119,7 @@ class MessageWriter {
/**
* Writes an {@link InitializeMessage} to the subprocess.
- *
+ *
* @param initializationInput
* contains information about the shard being initialized
*/
@@ -128,7 +129,7 @@ class MessageWriter {
/**
* Writes a {@link ProcessRecordsMessage} message to the subprocess.
- *
+ *
* @param processRecordsInput
* the records, and associated metadata to be processed.
*/
@@ -138,7 +139,7 @@ class MessageWriter {
/**
* Writes the lease lost message to the sub process.
- *
+ *
* @param leaseLostInput
* the lease lost input. This is currently unused as lease loss doesn't actually have anything in it
* @return A future that is set when the message has been written.
@@ -149,7 +150,7 @@ class MessageWriter {
/**
* Writes a message to the sub process indicating that the shard has ended
- *
+ *
* @param shardEndedInput
* the shard end input. This is currently unused as the checkpoint is extracted, and used by the caller.
* @return A future that is set when the message has been written.
@@ -167,7 +168,7 @@ class MessageWriter {
/**
* Writes a {@link CheckpointMessage} to the subprocess.
- *
+ *
* @param sequenceNumber
* The sequence number that was checkpointed.
* @param subSequenceNumber
@@ -175,14 +176,14 @@ class MessageWriter {
* @param throwable
* The exception that was thrown by a checkpoint attempt. Null if one didn't occur.
*/
- Future writeCheckpointMessageWithError(String sequenceNumber, Long subSequenceNumber,
- Throwable throwable) {
+ Future writeCheckpointMessageWithError(
+ String sequenceNumber, Long subSequenceNumber, Throwable throwable) {
return writeMessage(new CheckpointMessage(sequenceNumber, subSequenceNumber, throwable));
}
/**
* Closes the output stream and prevents further attempts to write.
- *
+ *
* @throws IOException Thrown when closing the writer fails
*/
void close() throws IOException {
@@ -201,18 +202,16 @@ class MessageWriter {
* {@link MultiLangShardRecordProcessor (String)} is called. So we follow a pattern where the attributes are
* set inside this method instead of the constructor so that this object will be initialized when all its attributes
* are known to the record processor.
- *
+ *
* @param stream Used to write messages to the subprocess.
* @param shardId The shard we're working on.
* @param objectMapper The object mapper to encode messages.
* @param executorService An executor service to run tasks in.
*/
- MessageWriter initialize(OutputStream stream,
- String shardId,
- ObjectMapper objectMapper,
- ExecutorService executorService) {
- return this.initialize(new BufferedWriter(new OutputStreamWriter(stream)), shardId, objectMapper,
- executorService);
+ MessageWriter initialize(
+ OutputStream stream, String shardId, ObjectMapper objectMapper, ExecutorService executorService) {
+ return this.initialize(
+ new BufferedWriter(new OutputStreamWriter(stream)), shardId, objectMapper, executorService);
}
/**
@@ -221,15 +220,12 @@ class MessageWriter {
* @param objectMapper The object mapper to encode messages.
* @param executorService An executor service to run tasks in.
*/
- MessageWriter initialize(BufferedWriter writer,
- String shardId,
- ObjectMapper objectMapper,
- ExecutorService executorService) {
+ MessageWriter initialize(
+ BufferedWriter writer, String shardId, ObjectMapper objectMapper, ExecutorService executorService) {
this.writer = writer;
this.shardId = shardId;
this.objectMapper = objectMapper;
this.executorService = executorService;
return this;
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemon.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemon.java
index b056e21f..4588b246 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemon.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemon.java
@@ -26,20 +26,18 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import lombok.Data;
+import lombok.experimental.Accessors;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
-
-import com.beust.jcommander.JCommander;
-import com.beust.jcommander.Parameter;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.core.joran.spi.JoranException;
-import lombok.Data;
-import lombok.experimental.Accessors;
-import lombok.extern.slf4j.Slf4j;
import software.amazon.kinesis.coordinator.Scheduler;
/**
@@ -75,11 +73,14 @@ public class MultiLangDaemon {
@Parameter
List parameters = new ArrayList<>();
- @Parameter(names = { "-p", "--properties-file" }, description = "Properties file to be used with the KCL")
+ @Parameter(
+ names = {"-p", "--properties-file"},
+ description = "Properties file to be used with the KCL")
String propertiesFile;
- @Parameter(names = { "-l",
- "--log-configuration" }, description = "File location of logback.xml to be override the default")
+ @Parameter(
+ names = {"-l", "--log-configuration"},
+ description = "File location of logback.xml to be override the default")
String logConfiguration;
}
@@ -102,7 +103,8 @@ public class MultiLangDaemon {
}
JCommander buildJCommanderAndParseArgs(final MultiLangDaemonArguments arguments, final String[] args) {
- JCommander jCommander = JCommander.newBuilder().programName("amazon-kinesis-client MultiLangDaemon")
+ JCommander jCommander = JCommander.newBuilder()
+ .programName("amazon-kinesis-client MultiLangDaemon")
.addObject(arguments)
.build();
jCommander.parse(args);
@@ -128,8 +130,8 @@ public class MultiLangDaemon {
}
}
- void configureLogging(final String logConfiguration, final LoggerContext loggerContext,
- final JoranConfigurator configurator) {
+ void configureLogging(
+ final String logConfiguration, final LoggerContext loggerContext, final JoranConfigurator configurator) {
loggerContext.reset();
try (InputStream inputStream = FileUtils.openInputStream(new File(logConfiguration))) {
configurator.setContext(loggerContext);
@@ -146,9 +148,8 @@ public class MultiLangDaemon {
if (arguments.parameters.size() == 1) {
propertiesFile = arguments.parameters.get(0);
} else {
- throw new RuntimeException(
- "Expected a single argument, but found multiple arguments. Arguments: "
- + String.join(", ", arguments.parameters));
+ throw new RuntimeException("Expected a single argument, but found multiple arguments. Arguments: "
+ + String.join(", ", arguments.parameters));
}
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemonConfig.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemonConfig.java
index c7f77c19..aaba66f0 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemonConfig.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangDaemonConfig.java
@@ -26,10 +26,9 @@ import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import software.amazon.kinesis.multilang.config.KinesisClientLibConfigurator;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
import lombok.extern.slf4j.Slf4j;
+import software.amazon.kinesis.multilang.config.KinesisClientLibConfigurator;
import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
import software.amazon.kinesis.retrieval.RetrievalConfig;
@@ -53,7 +52,7 @@ public class MultiLangDaemonConfig {
/**
* Constructor.
- *
+ *
* @param propertiesFile
* The location of the properties file.
* @throws IOException
@@ -66,7 +65,7 @@ public class MultiLangDaemonConfig {
}
/**
- *
+ *
* @param propertiesFile
* The location of the properties file.
* @param classLoader
@@ -82,7 +81,7 @@ public class MultiLangDaemonConfig {
}
/**
- *
+ *
* @param propertiesFile
* The location of the properties file.
* @param classLoader
@@ -94,8 +93,9 @@ public class MultiLangDaemonConfig {
* @throws IllegalArgumentException
* Thrown when the contents of the properties file are not as expected.
*/
- public MultiLangDaemonConfig(String propertiesFile, ClassLoader classLoader,
- KinesisClientLibConfigurator configurator) throws IOException, IllegalArgumentException {
+ public MultiLangDaemonConfig(
+ String propertiesFile, ClassLoader classLoader, KinesisClientLibConfigurator configurator)
+ throws IOException, IllegalArgumentException {
Properties properties = loadProperties(classLoader, propertiesFile);
if (!validateProperties(properties)) {
throw new IllegalArgumentException(
@@ -107,11 +107,14 @@ public class MultiLangDaemonConfig {
multiLangDaemonConfiguration = configurator.getConfiguration(properties);
executorService = buildExecutorService(properties);
- recordProcessorFactory = new MultiLangRecordProcessorFactory(executableName, executorService,
- multiLangDaemonConfiguration);
+ recordProcessorFactory =
+ new MultiLangRecordProcessorFactory(executableName, executorService, multiLangDaemonConfiguration);
- log.info("Running {} to process stream {} with executable {}", multiLangDaemonConfiguration.getApplicationName(),
- multiLangDaemonConfiguration.getStreamName(), executableName);
+ log.info(
+ "Running {} to process stream {} with executable {}",
+ multiLangDaemonConfiguration.getApplicationName(),
+ multiLangDaemonConfiguration.getStreamName(),
+ executableName);
prepare(processingLanguage);
}
@@ -138,7 +141,7 @@ public class MultiLangDaemonConfig {
}
log.info("MultiLangDaemon is adding the following fields to the User Agent: {}", userAgent.toString());
-// multiLangDaemonConfiguration.withUserAgent(userAgent.toString());
+ // multiLangDaemonConfiguration.withUserAgent(userAgent.toString());
}
private static Properties loadProperties(ClassLoader classLoader, String propertiesFileName) throws IOException {
@@ -181,17 +184,22 @@ public class MultiLangDaemonConfig {
log.debug("Value for {} property is {}", PROP_MAX_ACTIVE_THREADS, maxActiveThreads);
if (maxActiveThreads <= 0) {
log.info("Using a cached thread pool.");
- return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(),
- builder.build());
+ return new ThreadPoolExecutor(
+ 0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), builder.build());
} else {
log.info("Using a fixed thread pool with {} max active threads.", maxActiveThreads);
- return new ThreadPoolExecutor(maxActiveThreads, maxActiveThreads, 0L, TimeUnit.MILLISECONDS,
- new LinkedBlockingQueue<>(), builder.build());
+ return new ThreadPoolExecutor(
+ maxActiveThreads,
+ maxActiveThreads,
+ 0L,
+ TimeUnit.MILLISECONDS,
+ new LinkedBlockingQueue<>(),
+ builder.build());
}
}
/**
- *
+ *
* @return A KinesisClientLibConfiguration object based on the properties file provided.
*/
public MultiLangDaemonConfiguration getMultiLangDaemonConfiguration() {
@@ -199,7 +207,7 @@ public class MultiLangDaemonConfig {
}
/**
- *
+ *
* @return An executor service based on the properties file provided.
*/
public ExecutorService getExecutorService() {
@@ -207,7 +215,7 @@ public class MultiLangDaemonConfig {
}
/**
- *
+ *
* @return A MultiLangRecordProcessorFactory based on the properties file provided.
*/
public MultiLangRecordProcessorFactory getRecordProcessorFactory() {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangProtocol.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangProtocol.java
index 66a6ae9a..46ede873 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangProtocol.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangProtocol.java
@@ -61,8 +61,11 @@ class MultiLangProtocol {
* @param initializationInput
* information about the shard this processor is starting to process
*/
- MultiLangProtocol(MessageReader messageReader, MessageWriter messageWriter,
- InitializationInput initializationInput, MultiLangDaemonConfiguration configuration) {
+ MultiLangProtocol(
+ MessageReader messageReader,
+ MessageWriter messageWriter,
+ InitializationInput initializationInput,
+ MultiLangDaemonConfiguration configuration) {
this.messageReader = messageReader;
this.messageWriter = messageWriter;
this.initializationInput = initializationInput;
@@ -82,7 +85,6 @@ class MultiLangProtocol {
*/
Future writeFuture = messageWriter.writeInitializeMessage(initializationInput);
return waitForStatusMessage(InitializeMessage.ACTION, null, writeFuture);
-
}
/**
@@ -100,7 +102,7 @@ class MultiLangProtocol {
/**
* Notifies the client process that the lease has been lost, and it needs to shutdown.
- *
+ *
* @param leaseLostInput
* the lease lost input that is passed to the {@link MessageWriter}
* @return true if the message was successfully writtem
@@ -115,7 +117,9 @@ class MultiLangProtocol {
* @return
*/
boolean shardEnded(ShardEndedInput shardEndedInput) {
- return waitForStatusMessage(ShardEndedMessage.ACTION, shardEndedInput.checkpointer(),
+ return waitForStatusMessage(
+ ShardEndedMessage.ACTION,
+ shardEndedInput.checkpointer(),
messageWriter.writeShardEndedMessage(shardEndedInput));
}
@@ -147,8 +151,8 @@ class MultiLangProtocol {
* The writing task.
* @return Whether or not this operation succeeded.
*/
- private boolean waitForStatusMessage(String action, RecordProcessorCheckpointer checkpointer,
- Future writeFuture) {
+ private boolean waitForStatusMessage(
+ String action, RecordProcessorCheckpointer checkpointer, Future writeFuture) {
boolean statusWasCorrect = waitForStatusMessage(action, checkpointer);
// Examine whether or not we failed somewhere along the line.
@@ -194,7 +198,7 @@ class MultiLangProtocol {
return false;
}
- statusMessage = message.filter(m -> m instanceof StatusMessage).map(m -> (StatusMessage) m );
+ statusMessage = message.filter(m -> m instanceof StatusMessage).map(m -> (StatusMessage) m);
}
return this.validateStatusMessage(statusMessage.get(), action);
}
@@ -207,13 +211,17 @@ class MultiLangProtocol {
try {
return Optional.of(fm.get());
} catch (InterruptedException e) {
- log.error("Interrupted while waiting for {} message for shard {}", action,
- initializationInput.shardId(), e);
+ log.error(
+ "Interrupted while waiting for {} message for shard {}", action, initializationInput.shardId(), e);
} catch (ExecutionException e) {
- log.error("Failed to get status message for {} action for shard {}", action,
- initializationInput.shardId(), e);
+ log.error(
+ "Failed to get status message for {} action for shard {}",
+ action,
+ initializationInput.shardId(),
+ e);
} catch (TimeoutException e) {
- log.error("Timedout to get status message for {} action for shard {}. Terminating...",
+ log.error(
+ "Timedout to get status message for {} action for shard {}. Terminating...",
action,
initializationInput.shardId(),
e);
@@ -240,11 +248,14 @@ class MultiLangProtocol {
* @return Whether or not this operation succeeded.
*/
private boolean validateStatusMessage(StatusMessage statusMessage, String action) {
- log.info("Received response {} from subprocess while waiting for {}"
- + " while processing shard {}", statusMessage, action, initializationInput.shardId());
- return !(statusMessage == null || statusMessage.getResponseFor() == null || !statusMessage.getResponseFor()
- .equals(action));
-
+ log.info(
+ "Received response {} from subprocess while waiting for {}" + " while processing shard {}",
+ statusMessage,
+ action,
+ initializationInput.shardId());
+ return !(statusMessage == null
+ || statusMessage.getResponseFor() == null
+ || !statusMessage.getResponseFor().equals(action));
}
/**
@@ -274,13 +285,12 @@ class MultiLangProtocol {
}
return this.messageWriter.writeCheckpointMessageWithError(sequenceNumber, subSequenceNumber, null);
} else {
- String message =
- String.format("Was asked to checkpoint at %s but no checkpointer was provided for shard %s",
- sequenceNumber, initializationInput.shardId());
+ String message = String.format(
+ "Was asked to checkpoint at %s but no checkpointer was provided for shard %s",
+ sequenceNumber, initializationInput.shardId());
log.error(message);
- return this.messageWriter.writeCheckpointMessageWithError(sequenceNumber, subSequenceNumber,
- new InvalidStateException(
- message));
+ return this.messageWriter.writeCheckpointMessageWithError(
+ sequenceNumber, subSequenceNumber, new InvalidStateException(message));
}
} catch (Throwable t) {
return this.messageWriter.writeCheckpointMessageWithError(sequenceNumber, subSequenceNumber, t);
@@ -288,8 +298,8 @@ class MultiLangProtocol {
}
private String logCheckpointMessage(String sequenceNumber, Long subSequenceNumber) {
- return String.format("Attempting to checkpoint shard %s @ sequence number %s, and sub sequence number %s",
+ return String.format(
+ "Attempting to checkpoint shard %s @ sequence number %s, and sub sequence number %s",
initializationInput.shardId(), sequenceNumber, subSequenceNumber);
}
-
}
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 c4aab958..56c555d7 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
@@ -17,11 +17,10 @@ package software.amazon.kinesis.multilang;
import java.util.concurrent.ExecutorService;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import lombok.extern.slf4j.Slf4j;
import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
-import software.amazon.kinesis.processor.ShardRecordProcessorFactory;
import software.amazon.kinesis.processor.ShardRecordProcessor;
+import software.amazon.kinesis.processor.ShardRecordProcessorFactory;
/**
* Creates {@link MultiLangShardRecordProcessor}'s.
@@ -43,8 +42,8 @@ public class MultiLangRecordProcessorFactory implements ShardRecordProcessorFact
* @param command The command that will do processing for this factory's record processors.
* @param executorService An executor service to use while processing inputs and outputs of the child process.
*/
- public MultiLangRecordProcessorFactory(String command, ExecutorService executorService,
- MultiLangDaemonConfiguration configuration) {
+ public MultiLangRecordProcessorFactory(
+ String command, ExecutorService executorService, MultiLangDaemonConfiguration configuration) {
this(command, executorService, new ObjectMapper(), configuration);
}
@@ -53,8 +52,11 @@ public class MultiLangRecordProcessorFactory implements ShardRecordProcessorFact
* @param executorService An executor service to use while processing inputs and outputs of the child process.
* @param objectMapper An object mapper used to convert messages to json to be written to the child process
*/
- public MultiLangRecordProcessorFactory(String command, ExecutorService executorService, ObjectMapper objectMapper,
- MultiLangDaemonConfiguration configuration) {
+ public MultiLangRecordProcessorFactory(
+ String command,
+ ExecutorService executorService,
+ ObjectMapper objectMapper,
+ MultiLangDaemonConfiguration configuration) {
this.command = command;
this.commandArray = command.split(COMMAND_DELIMETER_REGEX);
this.executorService = executorService;
@@ -68,8 +70,8 @@ public class MultiLangRecordProcessorFactory implements ShardRecordProcessorFact
/*
* Giving ProcessBuilder the command as an array of Strings allows users to specify command line arguments.
*/
- return new MultiLangShardRecordProcessor(new ProcessBuilder(commandArray), executorService, this.objectMapper,
- this.configuration);
+ return new MultiLangShardRecordProcessor(
+ new ProcessBuilder(commandArray), executorService, this.objectMapper, this.configuration);
}
String[] getCommandArray() {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangShardRecordProcessor.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangShardRecordProcessor.java
index 241ea8ee..c6569cb9 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangShardRecordProcessor.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/MultiLangShardRecordProcessor.java
@@ -22,7 +22,6 @@ import java.util.concurrent.Future;
import java.util.function.Function;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import lombok.extern.slf4j.Slf4j;
import software.amazon.kinesis.lifecycle.events.InitializationInput;
import software.amazon.kinesis.lifecycle.events.LeaseLostInput;
@@ -156,8 +155,10 @@ public class MultiLangShardRecordProcessor implements ShardRecordProcessor {
if (ProcessState.ACTIVE.equals(this.state)) {
stopProcessing("Encountered an error while trying to shutdown child process", t);
} else {
- stopProcessing("Encountered an error during shutdown,"
- + " but it appears the processor has already been shutdown", t);
+ stopProcessing(
+ "Encountered an error during shutdown,"
+ + " but it appears the processor has already been shutdown",
+ t);
}
}
}
@@ -166,12 +167,13 @@ public class MultiLangShardRecordProcessor implements ShardRecordProcessor {
* Used to tell whether the processor has been shutdown already.
*/
private enum ProcessState {
- ACTIVE, SHUTDOWN
+ ACTIVE,
+ SHUTDOWN
}
/**
* Constructor.
- *
+ *
* @param processBuilder
* Provides process builder functionality.
* @param executorService
@@ -179,15 +181,24 @@ public class MultiLangShardRecordProcessor implements ShardRecordProcessor {
* @param objectMapper
* An obejct mapper.
*/
- MultiLangShardRecordProcessor(ProcessBuilder processBuilder, ExecutorService executorService,
- ObjectMapper objectMapper, MultiLangDaemonConfiguration configuration) {
- this(processBuilder, executorService, objectMapper, new MessageWriter(), new MessageReader(),
- new DrainChildSTDERRTask(), configuration);
+ MultiLangShardRecordProcessor(
+ ProcessBuilder processBuilder,
+ ExecutorService executorService,
+ ObjectMapper objectMapper,
+ MultiLangDaemonConfiguration configuration) {
+ this(
+ processBuilder,
+ executorService,
+ objectMapper,
+ new MessageWriter(),
+ new MessageReader(),
+ new DrainChildSTDERRTask(),
+ configuration);
}
/**
* Note: This constructor has package level access solely for testing purposes.
- *
+ *
* @param processBuilder
* Provides the child process for this record processor
* @param executorService
@@ -201,9 +212,14 @@ public class MultiLangShardRecordProcessor implements ShardRecordProcessor {
* @param readSTDERRTask
* Error reader to read from child process's stderr
*/
- MultiLangShardRecordProcessor(ProcessBuilder processBuilder, ExecutorService executorService, ObjectMapper objectMapper,
- MessageWriter messageWriter, MessageReader messageReader, DrainChildSTDERRTask readSTDERRTask,
- MultiLangDaemonConfiguration configuration) {
+ MultiLangShardRecordProcessor(
+ ProcessBuilder processBuilder,
+ ExecutorService executorService,
+ ObjectMapper objectMapper,
+ MessageWriter messageWriter,
+ MessageReader messageReader,
+ DrainChildSTDERRTask readSTDERRTask,
+ MultiLangDaemonConfiguration configuration) {
this.executorService = executorService;
this.processBuilder = processBuilder;
this.objectMapper = objectMapper;
@@ -268,7 +284,7 @@ public class MultiLangShardRecordProcessor implements ShardRecordProcessor {
/**
* Convenience method used by {@link #childProcessShutdownSequence()} to drain the STDIN and STDERR of the child
* process.
- *
+ *
* @param future A future to wait on.
* @param whatThisFutureIsDoing What that future is doing while we wait.
*/
@@ -283,7 +299,7 @@ public class MultiLangShardRecordProcessor implements ShardRecordProcessor {
/**
* Convenience method for logging and safely shutting down so that we don't throw an exception up to the KCL on
* accident.
- *
+ *
* @param message The reason we are stopping processing.
* @param reason An exception that caused us to want to stop processing.
*/
@@ -309,7 +325,7 @@ public class MultiLangShardRecordProcessor implements ShardRecordProcessor {
/**
* The {@link ProcessBuilder} class is final so not easily mocked. We wrap the only interaction we have with it in
* this package level method to permit unit testing.
- *
+ *
* @return The process started by processBuilder
* @throws IOException If the process can't be started.
*/
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyKey.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyKey.java
index ea3db8c3..19211822 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyKey.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyKey.java
@@ -19,7 +19,6 @@ import java.util.Map;
import com.amazonaws.regions.Regions;
import com.google.common.base.CaseFormat;
-
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -91,7 +90,6 @@ public enum NestedPropertyKey {
processor.acceptExternalId(externalId);
}
},
-
;
/**
@@ -141,5 +139,4 @@ public enum NestedPropertyKey {
}
}
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyProcessor.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyProcessor.java
index d3dd7a6f..f7587297 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyProcessor.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/NestedPropertyProcessor.java
@@ -50,5 +50,4 @@ public interface NestedPropertyProcessor {
* @param externalId external id used in the service call used to retrieve session credentials
*/
void acceptExternalId(String externalId);
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProvider.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProvider.java
index 3b196b94..b5b9f924 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProvider.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProvider.java
@@ -24,7 +24,6 @@ import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient;
-
import software.amazon.kinesis.multilang.NestedPropertyKey;
import software.amazon.kinesis.multilang.NestedPropertyProcessor;
@@ -47,8 +46,8 @@ public class KclSTSAssumeRoleSessionCredentialsProvider
this(params[0], params[1], Arrays.copyOfRange(params, 2, params.length));
}
- public KclSTSAssumeRoleSessionCredentialsProvider(final String roleArn, final String roleSessionName,
- final String... params) {
+ public KclSTSAssumeRoleSessionCredentialsProvider(
+ final String roleArn, final String roleSessionName, final String... params) {
builder = new Builder(roleArn, roleSessionName);
NestedPropertyKey.parse(this, params);
provider = builder.build();
@@ -75,9 +74,8 @@ public class KclSTSAssumeRoleSessionCredentialsProvider
@Override
public void acceptEndpointRegion(final Regions region) {
- final AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClient.builder()
- .withRegion(region)
- .build();
+ final AWSSecurityTokenService stsClient =
+ AWSSecurityTokenServiceClient.builder().withRegion(region).build();
builder.withStsClient(stsClient);
}
@@ -85,5 +83,4 @@ public class KclSTSAssumeRoleSessionCredentialsProvider
public void acceptExternalId(final String externalId) {
builder.withExternalId(externalId);
}
-
-}
\ No newline at end of file
+}
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 f11ac0ec..8110d4f7 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
@@ -37,8 +37,7 @@ class AWSCredentialsProviderPropertyValueDecoder implements IPropertyValueDecode
/**
* Constructor.
*/
- AWSCredentialsProviderPropertyValueDecoder() {
- }
+ AWSCredentialsProviderPropertyValueDecoder() {}
/**
* Get AWSCredentialsProvider property.
@@ -104,9 +103,8 @@ class AWSCredentialsProviderPropertyValueDecoder implements IPropertyValueDecode
if (provider == null) {
// attempt to invoke a public varargs/array constructor of FooClass(String[])
- provider = constructProvider(providerName, () ->
- clazz.getConstructor(String[].class).newInstance((Object) varargs)
- );
+ provider = constructProvider(providerName, () -> clazz.getConstructor(String[].class)
+ .newInstance((Object) varargs));
}
}
@@ -138,24 +136,26 @@ class AWSCredentialsProviderPropertyValueDecoder implements IPropertyValueDecode
private static List getPossibleFullClassNames(final String provider) {
return Stream.of(
- // Customer provides a short name of common providers in com.amazonaws.auth package
- // (e.g., any classes implementing the AWSCredentialsProvider interface)
- // @see http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/AWSCredentialsProvider.html
- "com.amazonaws.auth.",
+ // Customer provides a short name of common providers in com.amazonaws.auth package
+ // (e.g., any classes implementing the AWSCredentialsProvider interface)
+ // @see
+ // http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/AWSCredentialsProvider.html
+ "com.amazonaws.auth.",
- // Customer provides a short name of a provider offered by this multi-lang package
- "software.amazon.kinesis.multilang.auth.",
+ // Customer provides a short name of a provider offered by this multi-lang package
+ "software.amazon.kinesis.multilang.auth.",
- // Customer provides a fully-qualified provider name, or a custom credentials provider
- // (e.g., com.amazonaws.auth.ClasspathFileCredentialsProvider, org.mycompany.FooProvider)
- ""
- ).map(prefix -> prefix + provider).collect(Collectors.toList());
+ // Customer provides a fully-qualified provider name, or a custom credentials provider
+ // (e.g., com.amazonaws.auth.ClasspathFileCredentialsProvider, org.mycompany.FooProvider)
+ "")
+ .map(prefix -> prefix + provider)
+ .collect(Collectors.toList());
}
@FunctionalInterface
private interface CredentialsProviderConstructor {
- T construct() throws IllegalAccessException, InstantiationException,
- InvocationTargetException, NoSuchMethodException;
+ T construct()
+ throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException;
}
/**
@@ -179,5 +179,4 @@ class AWSCredentialsProviderPropertyValueDecoder implements IPropertyValueDecode
}
return null;
}
-
}
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 5baa47f4..927655c1 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
@@ -31,7 +31,7 @@ import org.apache.commons.lang3.StringUtils;
public class BuilderDynaBean implements DynaBean {
- private static final String[] CLASS_NAME_JOINERS = { ClassUtils.PACKAGE_SEPARATOR, ClassUtils.INNER_CLASS_SEPARATOR };
+ private static final String[] CLASS_NAME_JOINERS = {ClassUtils.PACKAGE_SEPARATOR, ClassUtils.INNER_CLASS_SEPARATOR};
static final String NO_MAP_ACCESS_SUPPORT = "Map access isn't supported";
private Class> destinedClass;
@@ -51,13 +51,19 @@ public class BuilderDynaBean implements DynaBean {
this(destinedClass, convertUtilsBean, null, Arrays.asList(classPrefixSearchList));
}
- public BuilderDynaBean(Class> destinedClass, ConvertUtilsBean convertUtilsBean,
- Function emptyPropertyHandler, String... classPrefixSearchList) {
+ public BuilderDynaBean(
+ Class> destinedClass,
+ ConvertUtilsBean convertUtilsBean,
+ Function emptyPropertyHandler,
+ String... classPrefixSearchList) {
this(destinedClass, convertUtilsBean, emptyPropertyHandler, Arrays.asList(classPrefixSearchList));
}
- public BuilderDynaBean(Class> destinedClass, ConvertUtilsBean convertUtilsBean,
- Function emptyPropertyHandler, List classPrefixSearchList) {
+ public BuilderDynaBean(
+ Class> destinedClass,
+ ConvertUtilsBean convertUtilsBean,
+ Function emptyPropertyHandler,
+ List classPrefixSearchList) {
this.convertUtilsBean = convertUtilsBean;
this.classPrefixSearchList = classPrefixSearchList;
this.emptyPropertyHandler = emptyPropertyHandler;
@@ -102,7 +108,6 @@ public class BuilderDynaBean implements DynaBean {
// Ignored
//
}
-
}
}
}
@@ -214,8 +219,10 @@ public class BuilderDynaBean implements DynaBean {
validateCanBuildOrCreate();
List types = dynaBeanBuilderSupport.getProperty(name);
if (types.size() > 1) {
- Optional arrayType = types.stream().filter(t -> t.type.isArray()).findFirst();
- return arrayType.map(t -> new DynaProperty(name, t.type, t.type.getComponentType()))
+ Optional arrayType =
+ types.stream().filter(t -> t.type.isArray()).findFirst();
+ return arrayType
+ .map(t -> new DynaProperty(name, t.type, t.type.getComponentType()))
.orElseGet(() -> new DynaProperty(name));
} else {
TypeTag type = types.get(0);
@@ -232,7 +239,8 @@ public class BuilderDynaBean implements DynaBean {
@Override
public DynaProperty[] getDynaProperties() {
validateCanBuildOrCreate();
- return dynaBeanBuilderSupport.getPropertyNames().stream().map(this::getDynaProperty)
+ return dynaBeanBuilderSupport.getPropertyNames().stream()
+ .map(this::getDynaProperty)
.toArray(DynaProperty[]::new);
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettable.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettable.java
index 381137eb..eef1e1c2 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettable.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettable.java
@@ -28,21 +28,21 @@ public @interface ConfigurationSettable {
/**
* Which builder this option applies to
- *
+ *
* @return the class of the builder to use
*/
Class> configurationClass();
/**
* The method name on the builder, defaults to the fieldName
- *
+ *
* @return the name of the method or null to use the default
*/
String methodName() default "";
/**
* If the type is actually an optional value this will enable conversions
- *
+ *
* @return true if the value should be wrapped by an optional
*/
boolean convertToOptional() default false;
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtils.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtils.java
index 390d8b15..c6d58807 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtils.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtils.java
@@ -23,13 +23,11 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import com.google.common.base.Defaults;
+import lombok.NonNull;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
-import com.google.common.base.Defaults;
-
-import lombok.NonNull;
-
public class ConfigurationSettableUtils {
public static T resolveFields(@NonNull Object source, @NonNull T configObject) {
@@ -40,8 +38,8 @@ public class ConfigurationSettableUtils {
return configObject;
}
- public static void resolveFields(Object source, Map, Object> configObjects, Set> restrictTo,
- Set> skipIf) {
+ public static void resolveFields(
+ Object source, Map, Object> configObjects, Set> restrictTo, Set> skipIf) {
for (Field field : source.getClass().getDeclaredFields()) {
for (ConfigurationSettable b : field.getAnnotationsByType(ConfigurationSettable.class)) {
if (restrictTo != null && !restrictTo.contains(b.configurationClass())) {
@@ -70,9 +68,11 @@ public class ConfigurationSettableUtils {
value = Optional.of(value);
}
if (ClassUtils.isPrimitiveOrWrapper(value.getClass())) {
- Class> primitiveType = field.getType().isPrimitive() ? field.getType()
+ Class> primitiveType = field.getType().isPrimitive()
+ ? field.getType()
: ClassUtils.wrapperToPrimitive(field.getType());
- Class> wrapperType = !field.getType().isPrimitive() ? field.getType()
+ Class> wrapperType = !field.getType().isPrimitive()
+ ? field.getType()
: ClassUtils.primitiveToWrapper(field.getType());
try {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoder.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoder.java
index fa91aa70..c2b1528e 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoder.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoder.java
@@ -26,8 +26,7 @@ public class DatePropertyValueDecoder implements IPropertyValueDecoder {
/**
* Constructor.
*/
- DatePropertyValueDecoder() {
- }
+ DatePropertyValueDecoder() {}
/**
* @param value property value as String
@@ -49,5 +48,4 @@ public class DatePropertyValueDecoder implements IPropertyValueDecoder {
public List> getSupportedTypes() {
return Arrays.asList(Date.class);
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanBuilderSupport.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanBuilderSupport.java
index 0cc0073c..97f429f1 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanBuilderSupport.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanBuilderSupport.java
@@ -29,11 +29,10 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
-import org.apache.commons.beanutils.ConvertUtilsBean;
-import org.apache.commons.lang3.ClassUtils;
-
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
+import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.lang3.ClassUtils;
class DynaBeanBuilderSupport {
@@ -48,8 +47,8 @@ class DynaBeanBuilderSupport {
private final Multimap properties = HashMultimap.create();
private final Map values = new HashMap<>();
- DynaBeanBuilderSupport(Class> destinedClass, ConvertUtilsBean convertUtilsBean,
- List classPrefixSearchList) {
+ DynaBeanBuilderSupport(
+ Class> destinedClass, ConvertUtilsBean convertUtilsBean, List classPrefixSearchList) {
this.destinedClass = destinedClass;
this.convertUtilsBean = convertUtilsBean;
this.classPrefixSearchList = classPrefixSearchList;
@@ -103,11 +102,12 @@ class DynaBeanBuilderSupport {
private Object createForProperty(String name) {
Optional type = properties.get(name).stream().findFirst();
return type.map(t -> {
- if (DynaBeanBuilderUtils.isBuilderOrCreate(t.type) || !t.hasConverter) {
- return new BuilderDynaBean(t.type, convertUtilsBean, null, classPrefixSearchList);
- }
- return null;
- }).orElse(null);
+ if (DynaBeanBuilderUtils.isBuilderOrCreate(t.type) || !t.hasConverter) {
+ return new BuilderDynaBean(t.type, convertUtilsBean, null, classPrefixSearchList);
+ }
+ return null;
+ })
+ .orElse(null);
}
boolean hasValue(String name) {
@@ -157,8 +157,11 @@ class DynaBeanBuilderSupport {
void set(String name, Object value) {
if (value instanceof String && properties.get(name).stream().anyMatch(t -> t.type.isEnum())) {
- TypeTag typeTag = properties.get(name).stream().filter(t -> t.type.isEnum()).findFirst().orElseThrow(
- () -> new IllegalStateException("Expected enum type for " + name + ", but couldn't find it."));
+ TypeTag typeTag = properties.get(name).stream()
+ .filter(t -> t.type.isEnum())
+ .findFirst()
+ .orElseThrow(() ->
+ new IllegalStateException("Expected enum type for " + name + ", but couldn't find it."));
Class extends Enum> enumClass = (Class extends Enum>) typeTag.type;
values.put(name, Enum.valueOf(enumClass, value.toString()));
} else {
@@ -174,9 +177,11 @@ class DynaBeanBuilderSupport {
private Object getArgument(Map.Entry setValue) {
Object argument = setValue.getValue();
if (argument instanceof Object[]) {
- TypeTag arrayType = properties.get(setValue.getKey()).stream().filter(t -> t.type.isArray()).findFirst()
- .orElseThrow(() -> new IllegalStateException(String
- .format("Received Object[] for %s but can't find corresponding type", setValue.getKey())));
+ TypeTag arrayType = properties.get(setValue.getKey()).stream()
+ .filter(t -> t.type.isArray())
+ .findFirst()
+ .orElseThrow(() -> new IllegalStateException(String.format(
+ "Received Object[] for %s but can't find corresponding type", setValue.getKey())));
Object[] arrayValues = (Object[]) argument;
Object[] destination = (Object[]) Array.newInstance(arrayType.type.getComponentType(), arrayValues.length);
@@ -212,10 +217,12 @@ class DynaBeanBuilderSupport {
for (Map.Entry setValue : values.entrySet()) {
Object argument = getArgument(setValue);
Method mutator = properties.get(setValue.getKey()).stream()
- .filter(t -> ClassUtils.isAssignable(argument.getClass(), t.type)).findFirst()
- .map(a -> a.builderMethod).orElseThrow(
- () -> new IllegalStateException(String.format("Unable to find mutator for %s of type %s",
- setValue.getKey(), argument.getClass().getName())));
+ .filter(t -> ClassUtils.isAssignable(argument.getClass(), t.type))
+ .findFirst()
+ .map(a -> a.builderMethod)
+ .orElseThrow(() -> new IllegalStateException(String.format(
+ "Unable to find mutator for %s of type %s",
+ setValue.getKey(), argument.getClass().getName())));
try {
source = mutator.invoke(source, argument);
} catch (IllegalAccessException | InvocationTargetException e) {
@@ -236,7 +243,6 @@ class DynaBeanBuilderSupport {
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}
-
}
Collection getPropertyNames() {
@@ -249,5 +255,4 @@ class DynaBeanBuilderSupport {
}
return new ArrayList<>(properties.get(name));
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanCreateSupport.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanCreateSupport.java
index 03c6e389..dda0b7ff 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanCreateSupport.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/DynaBeanCreateSupport.java
@@ -30,8 +30,8 @@ class DynaBeanCreateSupport {
private final List createTypes = new ArrayList<>();
private Object[] createValues = null;
- DynaBeanCreateSupport(Class> destinedClass, ConvertUtilsBean convertUtilsBean,
- List classPrefixSearchList) {
+ DynaBeanCreateSupport(
+ Class> destinedClass, ConvertUtilsBean convertUtilsBean, List classPrefixSearchList) {
this.destinedClass = destinedClass;
this.convertUtilsBean = convertUtilsBean;
this.classPrefixSearchList = classPrefixSearchList;
@@ -58,8 +58,8 @@ class DynaBeanCreateSupport {
Object build() {
- Method createMethod = DynaBeanBuilderUtils.getMethod(destinedClass, "create",
- createTypes.stream().map(t -> t.type).toArray(i -> new Class>[i]));
+ Method createMethod = DynaBeanBuilderUtils.getMethod(
+ destinedClass, "create", createTypes.stream().map(t -> t.type).toArray(i -> new Class>[i]));
Object arguments[] = new Object[createValues.length];
for (int i = 0; i < createValues.length; ++i) {
if (createValues[i] instanceof BuilderDynaBean) {
@@ -77,8 +77,8 @@ class DynaBeanCreateSupport {
return createValues[index];
} else {
if (createValues[index] == null) {
- createValues[index] = new BuilderDynaBean(createTypes.get(index).type, convertUtilsBean, null,
- classPrefixSearchList);
+ createValues[index] = new BuilderDynaBean(
+ createTypes.get(index).type, convertUtilsBean, null, classPrefixSearchList);
}
return createValues[index];
}
@@ -89,13 +89,11 @@ class DynaBeanCreateSupport {
public void set(String name, int index, Object value) {
if (StringUtils.isEmpty(name)) {
if (index >= createValues.length) {
- throw new IllegalArgumentException(
- String.format("%d exceeds the maximum number of arguments (%d) for %s", index,
- createValues.length, destinedClass.getName()));
+ throw new IllegalArgumentException(String.format(
+ "%d exceeds the maximum number of arguments (%d) for %s",
+ index, createValues.length, destinedClass.getName()));
}
createValues[index] = value;
}
-
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/FanoutConfigBean.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/FanoutConfigBean.java
index f9ab7044..a7478100 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/FanoutConfigBean.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/FanoutConfigBean.java
@@ -26,21 +26,28 @@ public class FanoutConfigBean implements RetrievalConfigBuilder {
@ConfigurationSettable(configurationClass = FanOutConfig.class)
private int maxDescribeStreamSummaryRetries;
+
@ConfigurationSettable(configurationClass = FanOutConfig.class)
private String consumerArn;
+
@ConfigurationSettable(configurationClass = FanOutConfig.class)
private String consumerName;
+
@ConfigurationSettable(configurationClass = FanOutConfig.class)
private int maxDescribeStreamConsumerRetries;
+
@ConfigurationSettable(configurationClass = FanOutConfig.class)
private int registerStreamConsumerRetries;
+
@ConfigurationSettable(configurationClass = FanOutConfig.class)
private long retryBackoffMillis;
@Override
public FanOutConfig build(KinesisAsyncClient kinesisAsyncClient, MultiLangDaemonConfiguration parent) {
- return ConfigurationSettableUtils.resolveFields(this, new FanOutConfig(kinesisAsyncClient).applicationName(parent.getApplicationName())
- .streamName(parent.getStreamName()));
+ return ConfigurationSettableUtils.resolveFields(
+ this,
+ new FanOutConfig(kinesisAsyncClient)
+ .applicationName(parent.getApplicationName())
+ .streamName(parent.getStreamName()));
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IPropertyValueDecoder.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IPropertyValueDecoder.java
index 111d4c63..0498874d 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IPropertyValueDecoder.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IPropertyValueDecoder.java
@@ -18,13 +18,13 @@ import java.util.List;
/**
* This class captures the concept of decoding a property value to a particular Java type.
- *
+ *
* @param
*/
interface IPropertyValueDecoder {
/**
* Get the value that was read from a configuration file and convert it to some type.
- *
+ *
* @param propertyValue property string value that needs to be decoded.
* @return property value in type T
*/
@@ -32,7 +32,7 @@ interface IPropertyValueDecoder {
/**
* Get a list of supported types for this class.
- *
+ *
* @return list of supported classes.
*/
List> getSupportedTypes();
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IntegerPropertyValueDecoder.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IntegerPropertyValueDecoder.java
index 88775cee..eb9fd0b8 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IntegerPropertyValueDecoder.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/IntegerPropertyValueDecoder.java
@@ -25,8 +25,7 @@ class IntegerPropertyValueDecoder implements IPropertyValueDecoder {
/**
* Constructor.
*/
- IntegerPropertyValueDecoder() {
- }
+ IntegerPropertyValueDecoder() {}
/**
* @param value property value as String
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 49856aa6..42b617a0 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
@@ -19,10 +19,9 @@ import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
+import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtilsBean;
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.kinesis.common.StreamIdentifier;
@@ -71,16 +70,21 @@ public class KinesisClientLibConfigurator {
Validate.notBlank(configuration.getApplicationName(), "Application name is required");
- if (configuration.getStreamArn() != null && !configuration.getStreamArn().trim().isEmpty()) {
+ 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)
+ // 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");
+ 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;
}
@@ -106,5 +110,4 @@ public class KinesisClientLibConfigurator {
}
return getConfiguration(properties);
}
-
}
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 8b6bc5e6..08c11d26 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
@@ -27,17 +27,16 @@ import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
-import org.apache.commons.beanutils.BeanUtilsBean;
-import org.apache.commons.beanutils.ConvertUtilsBean;
-import org.apache.commons.beanutils.Converter;
-import org.apache.commons.beanutils.converters.ArrayConverter;
-import org.apache.commons.beanutils.converters.StringConverter;
-
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.beanutils.Converter;
+import org.apache.commons.beanutils.converters.ArrayConverter;
+import org.apache.commons.beanutils.converters.StringConverter;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
@@ -74,7 +73,6 @@ public class MultiLangDaemonConfiguration {
private String streamName;
private String streamArn;
-
@ConfigurationSettable(configurationClass = ConfigsBuilder.class)
private String tableName;
@@ -86,22 +84,31 @@ public class MultiLangDaemonConfiguration {
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private long failoverTimeMillis;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private Boolean enablePriorityLeaseAssignment;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private long shardSyncIntervalMillis;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private boolean cleanupLeasesUponShardCompletion;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private boolean ignoreUnexpectedChildShards;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private int maxLeasesForWorker;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private int maxLeasesToStealAtOneTime;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private int initialLeaseTableReadCapacity;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private int initialLeaseTableWriteCapacity;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class, methodName = "initialPositionInStream")
@ConfigurationSettable(configurationClass = RetrievalConfig.class)
private InitialPositionInStreamExtended initialPositionInStreamExtended;
@@ -114,14 +121,16 @@ public class MultiLangDaemonConfiguration {
}
public void setInitialPositionInStream(InitialPositionInStream initialPositionInStream) {
- this.initialPositionInStreamExtended = InitialPositionInStreamExtended
- .newInitialPosition(initialPositionInStream);
+ this.initialPositionInStreamExtended =
+ InitialPositionInStreamExtended.newInitialPosition(initialPositionInStream);
}
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private int maxLeaseRenewalThreads;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private long listShardsBackoffTimeInMillis;
+
@ConfigurationSettable(configurationClass = LeaseManagementConfig.class)
private int maxListShardsRetryAttempts;
@@ -131,10 +140,13 @@ public class MultiLangDaemonConfiguration {
@ConfigurationSettable(configurationClass = CoordinatorConfig.class)
private long parentShardPollIntervalMillis;
+
@ConfigurationSettable(configurationClass = CoordinatorConfig.class)
private ShardPrioritization shardPrioritization;
+
@ConfigurationSettable(configurationClass = CoordinatorConfig.class)
private boolean skipShardSyncAtWorkerInitializationIfLeasesExist;
+
@ConfigurationSettable(configurationClass = CoordinatorConfig.class)
private long schedulerInitializationBackoffTimeMillis;
@@ -143,12 +155,16 @@ public class MultiLangDaemonConfiguration {
@ConfigurationSettable(configurationClass = MetricsConfig.class)
private long metricsBufferTimeMillis;
+
@ConfigurationSettable(configurationClass = MetricsConfig.class)
private int metricsMaxQueueSize;
+
@ConfigurationSettable(configurationClass = MetricsConfig.class)
private MetricsLevel metricsLevel;
+
@ConfigurationSettable(configurationClass = LifecycleConfig.class, convertToOptional = true)
private Long logWarningForTaskAfterMillis;
+
@ConfigurationSettable(configurationClass = MetricsConfig.class)
private Set metricsEnabledDimensions;
@@ -163,6 +179,7 @@ public class MultiLangDaemonConfiguration {
private RetrievalMode retrievalMode = RetrievalMode.DEFAULT;
private final FanoutConfigBean fanoutConfig = new FanoutConfigBean();
+
@Delegate(types = PollingConfigBean.PollingConfigBeanDelegate.class)
private final PollingConfigBean pollingConfig = new PollingConfigBean();
@@ -200,61 +217,75 @@ public class MultiLangDaemonConfiguration {
this.utilsBean = utilsBean;
this.convertUtilsBean = convertUtilsBean;
- convertUtilsBean.register(new Converter() {
- @Override
- public T convert(Class type, Object value) {
- Date date = new Date(Long.parseLong(value.toString()) * 1000L);
- return type.cast(InitialPositionInStreamExtended.newInitialPositionAtTimestamp(date));
- }
- }, InitialPositionInStreamExtended.class);
+ convertUtilsBean.register(
+ new Converter() {
+ @Override
+ public T convert(Class type, Object value) {
+ Date date = new Date(Long.parseLong(value.toString()) * 1000L);
+ return type.cast(InitialPositionInStreamExtended.newInitialPositionAtTimestamp(date));
+ }
+ },
+ InitialPositionInStreamExtended.class);
- convertUtilsBean.register(new Converter() {
- @Override
- public T convert(Class type, Object value) {
- return type.cast(MetricsLevel.valueOf(value.toString().toUpperCase()));
- }
- }, MetricsLevel.class);
+ convertUtilsBean.register(
+ new Converter() {
+ @Override
+ public T convert(Class type, Object value) {
+ return type.cast(MetricsLevel.valueOf(value.toString().toUpperCase()));
+ }
+ },
+ MetricsLevel.class);
- convertUtilsBean.register(new Converter() {
- @Override
- public T convert(Class type, Object value) {
- return type.cast(InitialPositionInStream.valueOf(value.toString().toUpperCase()));
- }
- }, InitialPositionInStream.class);
+ convertUtilsBean.register(
+ new Converter() {
+ @Override
+ public T convert(Class type, Object value) {
+ return type.cast(
+ InitialPositionInStream.valueOf(value.toString().toUpperCase()));
+ }
+ },
+ InitialPositionInStream.class);
- convertUtilsBean.register(new Converter() {
- @Override
- public T convert(Class type, Object value) {
- return type.cast(URI.create(value.toString()));
- }
- }, URI.class);
+ convertUtilsBean.register(
+ new Converter() {
+ @Override
+ public T convert(Class type, Object value) {
+ return type.cast(URI.create(value.toString()));
+ }
+ },
+ URI.class);
- convertUtilsBean.register(new Converter() {
- @Override
- public T convert(Class type, Object value) {
- return type.cast(RetrievalMode.from(value.toString()));
- }
- }, RetrievalMode.class);
+ convertUtilsBean.register(
+ new Converter() {
+ @Override
+ public T convert(Class type, Object value) {
+ return type.cast(RetrievalMode.from(value.toString()));
+ }
+ },
+ RetrievalMode.class);
- convertUtilsBean.register(new Converter() {
- @Override
- public T convert(final Class type, final Object value) {
- return type.cast(Region.of(value.toString()));
- }
- }, Region.class);
+ convertUtilsBean.register(
+ new Converter() {
+ @Override
+ public T convert(final Class type, final Object value) {
+ return type.cast(Region.of(value.toString()));
+ }
+ },
+ Region.class);
ArrayConverter arrayConverter = new ArrayConverter(String[].class, new StringConverter());
arrayConverter.setDelimiter(',');
convertUtilsBean.register(arrayConverter, String[].class);
- AWSCredentialsProviderPropertyValueDecoder oldCredentialsDecoder = new AWSCredentialsProviderPropertyValueDecoder();
+ AWSCredentialsProviderPropertyValueDecoder oldCredentialsDecoder =
+ new AWSCredentialsProviderPropertyValueDecoder();
Function converter = s -> new V2CredentialWrapper(oldCredentialsDecoder.decodeValue(s));
- this.kinesisCredentialsProvider = new BuilderDynaBean(AwsCredentialsProvider.class, convertUtilsBean,
- converter, CREDENTIALS_DEFAULT_SEARCH_PATH);
- this.dynamoDBCredentialsProvider = new BuilderDynaBean(AwsCredentialsProvider.class, convertUtilsBean,
- converter, CREDENTIALS_DEFAULT_SEARCH_PATH);
- this.cloudWatchCredentialsProvider = new BuilderDynaBean(AwsCredentialsProvider.class, convertUtilsBean,
- converter, CREDENTIALS_DEFAULT_SEARCH_PATH);
+ this.kinesisCredentialsProvider = new BuilderDynaBean(
+ AwsCredentialsProvider.class, convertUtilsBean, converter, CREDENTIALS_DEFAULT_SEARCH_PATH);
+ this.dynamoDBCredentialsProvider = new BuilderDynaBean(
+ AwsCredentialsProvider.class, convertUtilsBean, converter, CREDENTIALS_DEFAULT_SEARCH_PATH);
+ this.cloudWatchCredentialsProvider = new BuilderDynaBean(
+ AwsCredentialsProvider.class, convertUtilsBean, converter, CREDENTIALS_DEFAULT_SEARCH_PATH);
this.kinesisClient = new BuilderDynaBean(KinesisAsyncClient.class, convertUtilsBean);
this.dynamoDbClient = new BuilderDynaBean(DynamoDbAsyncClient.class, convertUtilsBean);
@@ -300,8 +331,8 @@ public class MultiLangDaemonConfiguration {
return credsBuilder.build(AwsCredentialsProvider.class);
}
- private void updateCredentials(BuilderDynaBean toUpdate, AwsCredentialsProvider primary,
- AwsCredentialsProvider secondary) {
+ private void updateCredentials(
+ BuilderDynaBean toUpdate, AwsCredentialsProvider primary, AwsCredentialsProvider secondary) {
if (toUpdate.hasValue("credentialsProvider")) {
return;
@@ -329,8 +360,8 @@ public class MultiLangDaemonConfiguration {
}
private void handleRetrievalConfig(RetrievalConfig retrievalConfig, ConfigsBuilder configsBuilder) {
- retrievalConfig
- .retrievalSpecificConfig(retrievalMode.builder(this).build(configsBuilder.kinesisClient(), this));
+ retrievalConfig.retrievalSpecificConfig(
+ retrievalMode.builder(this).build(configsBuilder.kinesisClient(), this));
}
private Object adjustKinesisHttpConfiguration(Object builderObj) {
@@ -353,8 +384,14 @@ public class MultiLangDaemonConfiguration {
final RetrievalConfig retrievalConfig;
public Scheduler build() {
- return new Scheduler(checkpointConfig, coordinatorConfig, leaseManagementConfig, lifecycleConfig,
- metricsConfig, processorConfig, retrievalConfig);
+ return new Scheduler(
+ checkpointConfig,
+ coordinatorConfig,
+ leaseManagementConfig,
+ lifecycleConfig,
+ metricsConfig,
+ processorConfig,
+ retrievalConfig);
}
}
@@ -367,19 +404,25 @@ public class MultiLangDaemonConfiguration {
updateCredentials(dynamoDbClient, dynamoDbCreds, kinesisCreds);
updateCredentials(cloudWatchClient, cloudwatchCreds, kinesisCreds);
- KinesisAsyncClient kinesisAsyncClient = kinesisClient.build(KinesisAsyncClient.class,
- this::adjustKinesisHttpConfiguration);
+ KinesisAsyncClient kinesisAsyncClient =
+ kinesisClient.build(KinesisAsyncClient.class, this::adjustKinesisHttpConfiguration);
DynamoDbAsyncClient dynamoDbAsyncClient = dynamoDbClient.build(DynamoDbAsyncClient.class);
CloudWatchAsyncClient cloudWatchAsyncClient = cloudWatchClient.build(CloudWatchAsyncClient.class);
- ConfigsBuilder configsBuilder = new ConfigsBuilder(streamName, applicationName, kinesisAsyncClient,
- dynamoDbAsyncClient, cloudWatchAsyncClient, workerIdentifier, shardRecordProcessorFactory);
+ ConfigsBuilder configsBuilder = new ConfigsBuilder(
+ streamName,
+ applicationName,
+ kinesisAsyncClient,
+ dynamoDbAsyncClient,
+ cloudWatchAsyncClient,
+ workerIdentifier,
+ shardRecordProcessorFactory);
Map, Object> configObjects = new HashMap<>();
addConfigObjects(configObjects, configsBuilder);
- resolveFields(configObjects, Collections.singleton(ConfigsBuilder.class),
- Collections.singleton(PollingConfig.class));
+ resolveFields(
+ configObjects, Collections.singleton(ConfigsBuilder.class), Collections.singleton(PollingConfig.class));
CoordinatorConfig coordinatorConfig = configsBuilder.coordinatorConfig();
CheckpointConfig checkpointConfig = configsBuilder.checkpointConfig();
@@ -389,19 +432,31 @@ public class MultiLangDaemonConfiguration {
ProcessorConfig processorConfig = configsBuilder.processorConfig();
RetrievalConfig retrievalConfig = configsBuilder.retrievalConfig();
- addConfigObjects(configObjects, coordinatorConfig, checkpointConfig, leaseManagementConfig, lifecycleConfig,
- metricsConfig, processorConfig, retrievalConfig);
+ addConfigObjects(
+ configObjects,
+ coordinatorConfig,
+ checkpointConfig,
+ leaseManagementConfig,
+ lifecycleConfig,
+ metricsConfig,
+ processorConfig,
+ retrievalConfig);
handleRetrievalConfig(retrievalConfig, configsBuilder);
resolveFields(configObjects, null, new HashSet<>(Arrays.asList(ConfigsBuilder.class, PollingConfig.class)));
- return new ResolvedConfiguration(coordinatorConfig, checkpointConfig, leaseManagementConfig, lifecycleConfig,
- metricsConfig, processorConfig, retrievalConfig);
+ return new ResolvedConfiguration(
+ coordinatorConfig,
+ checkpointConfig,
+ leaseManagementConfig,
+ lifecycleConfig,
+ metricsConfig,
+ processorConfig,
+ retrievalConfig);
}
public Scheduler build(ShardRecordProcessorFactory shardRecordProcessorFactory) {
return resolvedConfiguration(shardRecordProcessorFactory).build();
}
-
-}
\ No newline at end of file
+}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/PollingConfigBean.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/PollingConfigBean.java
index 176efbad..64f24b16 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/PollingConfigBean.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/PollingConfigBean.java
@@ -30,34 +30,44 @@ public class PollingConfigBean implements RetrievalConfigBuilder {
interface PollingConfigBeanDelegate {
Integer getRetryGetRecordsInSeconds();
+
void setRetryGetRecordsInSeconds(Integer value);
Integer getMaxGetRecordsThreadPool();
+
void setMaxGetRecordsThreadPool(Integer value);
long getIdleTimeBetweenReadsInMillis();
+
void setIdleTimeBetweenReadsInMillis(long value);
int getMaxRecords();
+
void setMaxRecords(int value);
}
@ConfigurationSettable(configurationClass = PollingConfig.class, convertToOptional = true)
private Integer retryGetRecordsInSeconds;
+
@ConfigurationSettable(configurationClass = PollingConfig.class, convertToOptional = true)
private Integer maxGetRecordsThreadPool;
+
@ConfigurationSettable(configurationClass = PollingConfig.class)
private long idleTimeBetweenReadsInMillis;
+
@ConfigurationSettable(configurationClass = PollingConfig.class)
private int maxRecords;
public boolean anyPropertiesSet() {
- return retryGetRecordsInSeconds != null || maxGetRecordsThreadPool != null || idleTimeBetweenReadsInMillis != 0 || maxRecords != 0;
+ return retryGetRecordsInSeconds != null
+ || maxGetRecordsThreadPool != null
+ || idleTimeBetweenReadsInMillis != 0
+ || maxRecords != 0;
}
@Override
public PollingConfig build(KinesisAsyncClient kinesisAsyncClient, MultiLangDaemonConfiguration parent) {
- return ConfigurationSettableUtils.resolveFields(this, new PollingConfig(parent.getStreamName(), kinesisAsyncClient));
+ return ConfigurationSettableUtils.resolveFields(
+ this, new PollingConfig(parent.getStreamName(), kinesisAsyncClient));
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalConfigBuilder.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalConfigBuilder.java
index 36794a99..7fa9ff9d 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalConfigBuilder.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalConfigBuilder.java
@@ -21,7 +21,7 @@ import software.amazon.kinesis.retrieval.RetrievalSpecificConfig;
public interface RetrievalConfigBuilder {
/**
* Creates a retrieval specific configuration using the supplied parameters, and internal class parameters
- *
+ *
* @param kinesisAsyncClient
* the client that will be provided to the RetrievalSpecificConfig constructor
* @param parent
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalMode.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalMode.java
index bf65fffb..ebe6dcd1 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalMode.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/RetrievalMode.java
@@ -19,14 +19,14 @@ import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;
-import org.apache.commons.lang3.Validate;
-
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.Validate;
@Slf4j
public enum RetrievalMode {
- FANOUT(MultiLangDaemonConfiguration::getFanoutConfig), POLLING(
- MultiLangDaemonConfiguration::getPollingConfig), DEFAULT(RetrievalMode::decideForDefault);
+ FANOUT(MultiLangDaemonConfiguration::getFanoutConfig),
+ POLLING(MultiLangDaemonConfiguration::getPollingConfig),
+ DEFAULT(RetrievalMode::decideForDefault);
private final Function builderFor;
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/TypeTag.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/TypeTag.java
index ee630ecf..dc359b91 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/TypeTag.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/TypeTag.java
@@ -15,14 +15,13 @@
package software.amazon.kinesis.multilang.config;
-import lombok.Data;
-
import java.lang.reflect.Method;
+import lombok.Data;
+
@Data
class TypeTag {
final Class> type;
final boolean hasConverter;
final Method builderMethod;
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/credentials/V2CredentialWrapper.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/credentials/V2CredentialWrapper.java
index 50880a83..e1b6072a 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/credentials/V2CredentialWrapper.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/config/credentials/V2CredentialWrapper.java
@@ -32,7 +32,9 @@ public class V2CredentialWrapper implements AwsCredentialsProvider {
public AwsCredentials resolveCredentials() {
AWSCredentials current = oldCredentialsProvider.getCredentials();
if (current instanceof AWSSessionCredentials) {
- return AwsSessionCredentials.create(current.getAWSAccessKeyId(), current.getAWSSecretKey(),
+ return AwsSessionCredentials.create(
+ current.getAWSAccessKeyId(),
+ current.getAWSSecretKey(),
((AWSSessionCredentials) current).getSessionToken());
}
return new AwsCredentials() {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/CheckpointMessage.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/CheckpointMessage.java
index b738dcd7..6413d161 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/CheckpointMessage.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/CheckpointMessage.java
@@ -36,6 +36,7 @@ public class CheckpointMessage extends Message {
* The checkpoint this message is about.
*/
private String sequenceNumber;
+
private Long subSequenceNumber;
/**
@@ -45,7 +46,7 @@ public class CheckpointMessage extends Message {
/**
* Convenience constructor.
- *
+ *
* @param sequenceNumber
* The sequence number that this message is about.
* @param subSequenceNumber
@@ -61,5 +62,4 @@ public class CheckpointMessage extends Message {
this.setError(throwable.getClass().getSimpleName());
}
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/InitializeMessage.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/InitializeMessage.java
index a04c639e..b6b12955 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/InitializeMessage.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/InitializeMessage.java
@@ -33,29 +33,29 @@ public class InitializeMessage extends Message {
* The shard id that this processor is getting initialized for.
*/
private String shardId;
+
private String sequenceNumber;
private Long subSequenceNumber;
/**
* Default constructor.
*/
- public InitializeMessage() {
- }
+ public InitializeMessage() {}
/**
* Convenience constructor.
- *
+ *
* @param initializationInput {@link InitializationInput}
*/
public InitializeMessage(InitializationInput initializationInput) {
this.shardId = initializationInput.shardId();
if (initializationInput.extendedSequenceNumber() != null) {
this.sequenceNumber = initializationInput.extendedSequenceNumber().sequenceNumber();
- this.subSequenceNumber = initializationInput.extendedSequenceNumber().subSequenceNumber();
+ this.subSequenceNumber =
+ initializationInput.extendedSequenceNumber().subSequenceNumber();
} else {
this.sequenceNumber = null;
this.subSequenceNumber = null;
}
}
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecord.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecord.java
index ca020825..a3a09f22 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecord.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecord.java
@@ -15,7 +15,6 @@
package software.amazon.kinesis.multilang.messages;
import com.fasterxml.jackson.annotation.JsonProperty;
-
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -54,10 +53,11 @@ public class JsonFriendlyRecord {
data = new byte[record.data().limit()];
record.data().get(data);
}
- Long approximateArrival = record.approximateArrivalTimestamp() == null ? null
+ Long approximateArrival = record.approximateArrivalTimestamp() == null
+ ? null
: record.approximateArrivalTimestamp().toEpochMilli();
- return new JsonFriendlyRecord(data, record.partitionKey(), record.sequenceNumber(),
- approximateArrival, record.subSequenceNumber());
+ return new JsonFriendlyRecord(
+ data, record.partitionKey(), record.sequenceNumber(), approximateArrival, record.subSequenceNumber());
}
@JsonProperty
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/LeaseLostMessage.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/LeaseLostMessage.java
index aea0677f..ccf269b5 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/LeaseLostMessage.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/LeaseLostMessage.java
@@ -21,5 +21,4 @@ package software.amazon.kinesis.multilang.messages;
public class LeaseLostMessage extends Message {
public static final String ACTION = "leaseLost";
-
}
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/Message.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/Message.java
index bdb89181..75fc1c68 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/Message.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/Message.java
@@ -23,15 +23,15 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* Abstract class for all messages that are sent to the client's process.
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "action")
-@JsonSubTypes({
- @Type(value = CheckpointMessage.class, name = CheckpointMessage.ACTION),
- @Type(value = InitializeMessage.class, name = InitializeMessage.ACTION),
- @Type(value = ProcessRecordsMessage.class, name = ProcessRecordsMessage.ACTION),
- @Type(value = ShutdownMessage.class, name = ShutdownMessage.ACTION),
- @Type(value = StatusMessage.class, name = StatusMessage.ACTION),
- @Type(value = ShutdownRequestedMessage.class, name = ShutdownRequestedMessage.ACTION),
- @Type(value = LeaseLostMessage.class, name = LeaseLostMessage.ACTION),
- @Type(value = ShardEndedMessage.class, name = ShardEndedMessage.ACTION),
+@JsonSubTypes({
+ @Type(value = CheckpointMessage.class, name = CheckpointMessage.ACTION),
+ @Type(value = InitializeMessage.class, name = InitializeMessage.ACTION),
+ @Type(value = ProcessRecordsMessage.class, name = ProcessRecordsMessage.ACTION),
+ @Type(value = ShutdownMessage.class, name = ShutdownMessage.ACTION),
+ @Type(value = StatusMessage.class, name = StatusMessage.ACTION),
+ @Type(value = ShutdownRequestedMessage.class, name = ShutdownRequestedMessage.ACTION),
+ @Type(value = LeaseLostMessage.class, name = LeaseLostMessage.ACTION),
+ @Type(value = ShardEndedMessage.class, name = ShardEndedMessage.ACTION),
})
public abstract class Message {
@@ -40,11 +40,10 @@ public abstract class Message {
/**
* Default constructor.
*/
- public Message() {
- }
+ public Message() {}
/**
- *
+ *
* @param objectMapper An object mapper.
* @return this
*/
@@ -54,7 +53,7 @@ public abstract class Message {
}
/**
- *
+ *
* @return A JSON representation of this object.
*/
public String toString() {
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/ProcessRecordsMessage.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/ProcessRecordsMessage.java
index 95601b2b..50eed164 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/ProcessRecordsMessage.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/messages/ProcessRecordsMessage.java
@@ -37,17 +37,17 @@ public class ProcessRecordsMessage extends Message {
* The records that the client's process needs to handle.
*/
private List records;
+
private Long millisBehindLatest;
/**
* Default constructor.
*/
- public ProcessRecordsMessage() {
- }
+ public ProcessRecordsMessage() {}
/**
* Convenience constructor.
- *
+ *
* @param processRecordsInput
* the process records input to be sent to the child
*/
diff --git a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/package-info.java b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/package-info.java
index af905f90..a1b4561a 100644
--- a/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/package-info.java
+++ b/amazon-kinesis-client-multilang/src/main/java/software/amazon/kinesis/multilang/package-info.java
@@ -142,7 +142,6 @@
* Jackson doc for more details) MIME is the basis of most base64 encoding variants including RFC 3548 which is the standard used by Python's base64 module.
- *
+ *
*/
package software.amazon.kinesis.multilang;
-
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/Matchers.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/Matchers.java
index b357c16b..2fd4fcb7 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/Matchers.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/Matchers.java
@@ -14,15 +14,14 @@
*/
package software.amazon.kinesis.multilang;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
-
-import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
import software.amazon.kinesis.lifecycle.events.InitializationInput;
+import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
public class Matchers {
@@ -58,8 +57,12 @@ public class Matchers {
@Override
public void describeTo(Description description) {
- description.appendText("An InitializationInput matching: { shardId: ").appendDescriptionOf(shardIdMatcher)
- .appendText(", sequenceNumber: ").appendDescriptionOf(sequenceNumberMatcher).appendText(" }");
+ description
+ .appendText("An InitializationInput matching: { shardId: ")
+ .appendDescriptionOf(shardIdMatcher)
+ .appendText(", sequenceNumber: ")
+ .appendDescriptionOf(sequenceNumberMatcher)
+ .appendText(" }");
}
}
@@ -98,10 +101,11 @@ public class Matchers {
@Override
public void describeTo(Description description) {
- description.appendText("An ExtendedSequenceNumber matching: { sequenceNumber: ")
- .appendDescriptionOf(sequenceNumberMatcher).appendText(", subSequenceNumber: ")
+ description
+ .appendText("An ExtendedSequenceNumber matching: { sequenceNumber: ")
+ .appendDescriptionOf(sequenceNumberMatcher)
+ .appendText(", subSequenceNumber: ")
.appendDescriptionOf(subSequenceNumberMatcher);
}
}
-
}
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 f6fab4c1..3ffcac14 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
@@ -22,15 +22,14 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-
import software.amazon.kinesis.multilang.messages.Message;
import software.amazon.kinesis.multilang.messages.StatusMessage;
-import com.fasterxml.jackson.databind.ObjectMapper;
public class MessageReaderTest {
@@ -75,8 +74,8 @@ public class MessageReaderTest {
@Test
public void runLoopGoodInputTest() {
- String[] sequenceNumbers = new String[] { "123", "456", "789" };
- String[] responseFors = new String[] { "initialize", "processRecords", "processRecords", "shutdown" };
+ String[] sequenceNumbers = new String[] {"123", "456", "789"};
+ String[] responseFors = new String[] {"initialize", "processRecords", "processRecords", "shutdown"};
InputStream stream = buildInputStreamOfGoodInput(sequenceNumbers, responseFors);
MessageReader reader =
new MessageReader().initialize(stream, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool());
@@ -85,7 +84,9 @@ public class MessageReaderTest {
try {
Message message = reader.getNextMessageFromSTDOUT().get();
if (message instanceof StatusMessage) {
- Assert.assertEquals("The status message's responseFor field should have been correct", responseFor,
+ Assert.assertEquals(
+ "The status message's responseFor field should have been correct",
+ responseFor,
((StatusMessage) message).getResponseFor());
}
} catch (InterruptedException | ExecutionException e) {
@@ -96,8 +97,8 @@ public class MessageReaderTest {
@Test
public void drainInputTest() throws InterruptedException, ExecutionException {
- String[] sequenceNumbers = new String[] { "123", "456", "789" };
- String[] responseFors = new String[] { "initialize", "processRecords", "processRecords", "shutdown" };
+ String[] sequenceNumbers = new String[] {"123", "456", "789"};
+ String[] responseFors = new String[] {"initialize", "processRecords", "processRecords", "shutdown"};
InputStream stream = buildInputStreamOfGoodInput(sequenceNumbers, responseFors);
MessageReader reader =
@@ -116,25 +117,26 @@ public class MessageReaderTest {
BufferedReader bufferReader = Mockito.mock(BufferedReader.class);
try {
Mockito.doAnswer(new Answer() {
- private boolean returnedOnce = false;
+ private boolean returnedOnce = false;
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- if (returnedOnce) {
- return "{\"action\":\"status\",\"responseFor\":\"processRecords\"}";
- } else {
- returnedOnce = true;
- return "{\"action\":\"shutdown\",\"reason\":\"ZOMBIE\"}";
- }
- }
- }).when(bufferReader).readLine();
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ if (returnedOnce) {
+ return "{\"action\":\"status\",\"responseFor\":\"processRecords\"}";
+ } else {
+ returnedOnce = true;
+ return "{\"action\":\"shutdown\",\"reason\":\"ZOMBIE\"}";
+ }
+ }
+ })
+ .when(bufferReader)
+ .readLine();
} catch (IOException e) {
Assert.fail("There shouldn't be an exception while setting up this mock.");
}
- MessageReader reader =
- new MessageReader().initialize(bufferReader, SHARD_ID, new ObjectMapper(),
- Executors.newCachedThreadPool());
+ MessageReader reader = new MessageReader()
+ .initialize(bufferReader, SHARD_ID, new ObjectMapper(), Executors.newCachedThreadPool());
try {
reader.getNextMessageFromSTDOUT().get();
@@ -165,7 +167,8 @@ public class MessageReaderTest {
readTask.get();
Assert.fail("The reading task should have failed due to an IOException.");
} catch (InterruptedException e) {
- Assert.fail("The reading task should not have been interrupted. It should have failed due to an IOException.");
+ Assert.fail(
+ "The reading task should not have been interrupted. It should have failed due to an IOException.");
} catch (ExecutionException e) {
// Yay!!
}
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 588f6140..90481b6c 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
@@ -23,21 +23,19 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
-
+import software.amazon.kinesis.lifecycle.events.InitializationInput;
import software.amazon.kinesis.lifecycle.events.LeaseLostInput;
+import software.amazon.kinesis.lifecycle.events.ProcessRecordsInput;
import software.amazon.kinesis.lifecycle.events.ShardEndedInput;
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.retrieval.KinesisClientRecord;
import static org.mockito.Mockito.verify;
@@ -65,8 +63,7 @@ public class MessageWriterTest {
public void writeCheckpointMessageNoErrorTest() throws IOException, InterruptedException, ExecutionException {
Future future = this.messageWriter.writeCheckpointMessageWithError("1234", 0L, null);
future.get();
- verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(),
- Mockito.anyInt());
+ verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());
verify(this.stream, Mockito.atLeastOnce()).flush();
}
@@ -74,42 +71,43 @@ public class MessageWriterTest {
public void writeCheckpointMessageWithErrorTest() throws IOException, InterruptedException, ExecutionException {
Future future = this.messageWriter.writeCheckpointMessageWithError("1234", 0L, new Throwable());
future.get();
- verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(),
- Mockito.anyInt());
+ verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());
verify(this.stream, Mockito.atLeastOnce()).flush();
}
@Test
public void writeInitializeMessageTest() throws IOException, InterruptedException, ExecutionException {
- Future future = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(SHARD_ID).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());
+ verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());
verify(this.stream, Mockito.atLeastOnce()).flush();
}
@Test
public void writeProcessRecordsMessageTest() throws IOException, InterruptedException, ExecutionException {
List records = Arrays.asList(
- KinesisClientRecord.builder().data(ByteBuffer.wrap("kitten".getBytes())).partitionKey("some cats")
- .sequenceNumber("357234807854789057805").build(),
- KinesisClientRecord.builder().build()
- );
- Future future = this.messageWriter.writeProcessRecordsMessage(ProcessRecordsInput.builder().records(records).build());
+ KinesisClientRecord.builder()
+ .data(ByteBuffer.wrap("kitten".getBytes()))
+ .partitionKey("some cats")
+ .sequenceNumber("357234807854789057805")
+ .build(),
+ KinesisClientRecord.builder().build());
+ Future future = this.messageWriter.writeProcessRecordsMessage(
+ ProcessRecordsInput.builder().records(records).build());
future.get();
- verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(),
- Mockito.anyInt());
+ verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());
verify(this.stream, Mockito.atLeastOnce()).flush();
}
@Test
public void writeShutdownMessageTest() throws IOException, InterruptedException, ExecutionException {
- Future future = this.messageWriter.writeShardEndedMessage(ShardEndedInput.builder().build());
+ Future future = this.messageWriter.writeShardEndedMessage(
+ ShardEndedInput.builder().build());
future.get();
- verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(),
- Mockito.anyInt());
+ verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());
verify(this.stream, Mockito.atLeastOnce()).flush();
}
@@ -118,15 +116,15 @@ public class MessageWriterTest {
Future future = this.messageWriter.writeShutdownRequestedMessage();
future.get();
- verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(),
- Mockito.anyInt());
+ verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());
verify(this.stream, Mockito.atLeastOnce()).flush();
}
@Test
public void streamIOExceptionTest() throws IOException, InterruptedException, ExecutionException {
Mockito.doThrow(IOException.class).when(stream).flush();
- Future initializeTask = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(SHARD_ID).build());
+ Future initializeTask = this.messageWriter.writeInitializeMessage(
+ InitializationInput.builder().shardId(SHARD_ID).build());
Boolean result = initializeTask.get();
Assert.assertNotNull(result);
Assert.assertFalse(result);
@@ -152,7 +150,8 @@ public class MessageWriterTest {
Assert.assertFalse(this.messageWriter.isOpen());
try {
// Any message should fail
- this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(SHARD_ID).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 aa46f431..de5a1405 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,26 +14,25 @@
*/
package software.amazon.kinesis.multilang;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.when;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import software.amazon.awssdk.regions.Region;
+import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-
-import junit.framework.Assert;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
import software.amazon.kinesis.multilang.config.KinesisClientLibConfigurator;
import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class MultiLangDaemonConfigTest {
private static final String FILENAME = "multilang.properties";
@@ -49,6 +48,7 @@ public class MultiLangDaemonConfigTest {
@Mock
private AwsCredentialsProvider credentialsProvider;
+
@Mock
private AwsCredentials creds;
@@ -62,14 +62,13 @@ public class MultiLangDaemonConfigTest {
* @throws IOException
*/
public void setup(String streamName, String streamArn) throws IOException {
- String properties = String.format("executableName = %s\n"
+ 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");
+ EXE, APPLICATION_NAME, "us-east-1");
if (streamName != null) {
properties += String.format("streamName = %s\n", streamName);
@@ -79,7 +78,8 @@ public class MultiLangDaemonConfigTest {
}
classLoader = Mockito.mock(ClassLoader.class);
- Mockito.doReturn(new ByteArrayInputStream(properties.getBytes())).when(classLoader)
+ Mockito.doReturn(new ByteArrayInputStream(properties.getBytes()))
+ .when(classLoader)
.getResourceAsStream(FILENAME);
when(credentialsProvider.resolveCredentials()).thenReturn(creds);
@@ -185,7 +185,8 @@ public class MultiLangDaemonConfigTest {
+ "AWSCredentialsProvider = DefaultAWSCredentialsProviderChain\n" + "processingLanguage = malbolge";
ClassLoader classLoader = Mockito.mock(ClassLoader.class);
- Mockito.doReturn(new ByteArrayInputStream(propertiesNoExecutableName.getBytes())).when(classLoader)
+ Mockito.doReturn(new ByteArrayInputStream(propertiesNoExecutableName.getBytes()))
+ .when(classLoader)
.getResourceAsStream(FILENAME);
try {
@@ -207,5 +208,4 @@ public class MultiLangDaemonConfigTest {
public void testActualPropertiesFile() throws Exception {
new MultiLangDaemonConfig(FILENAME);
}
-
-}
\ 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 3229e2b8..3e689437 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
@@ -14,6 +14,28 @@
*/
package software.amazon.kinesis.multilang;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.slf4j.LoggerFactory;
+import software.amazon.kinesis.coordinator.Scheduler;
+import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
+
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
@@ -27,46 +49,29 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.slf4j.LoggerFactory;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import software.amazon.kinesis.coordinator.Scheduler;
-import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
-
@RunWith(MockitoJUnitRunner.class)
public class MultiLangDaemonTest {
@Mock
private Scheduler scheduler;
+
@Mock
private MultiLangDaemonConfig config;
+
@Mock
private ExecutorService executorService;
+
@Mock
private Future futureInteger;
+
@Mock
private MultiLangDaemonConfiguration multiLangDaemonConfiguration;
+
@Mock
private Runtime runtime;
@Rule
public ExpectedException expectedException = ExpectedException.none();
+
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -86,7 +91,7 @@ public class MultiLangDaemonTest {
public void testSuccessfulNoOptionsJCommanderBuild() {
String testPropertiesFile = "/test/properties/file";
MultiLangDaemon.MultiLangDaemonArguments arguments = new MultiLangDaemon.MultiLangDaemonArguments();
- daemon.buildJCommanderAndParseArgs(arguments, new String[] { testPropertiesFile });
+ daemon.buildJCommanderAndParseArgs(arguments, new String[] {testPropertiesFile});
assertThat(arguments.propertiesFile, nullValue());
assertThat(arguments.logConfiguration, nullValue());
@@ -98,7 +103,7 @@ public class MultiLangDaemonTest {
public void testSuccessfulOptionsJCommanderBuild() {
String propertiesOption = "/test/properties/file/option";
String propertiesFileArgs = "/test/properties/args";
- String[] args = new String[] { "-p", propertiesOption, propertiesFileArgs };
+ String[] args = new String[] {"-p", propertiesOption, propertiesFileArgs};
MultiLangDaemon.MultiLangDaemonArguments arguments = new MultiLangDaemon.MultiLangDaemonArguments();
daemon.buildJCommanderAndParseArgs(arguments, args);
@@ -124,7 +129,8 @@ public class MultiLangDaemonTest {
LoggerContext loggerContext = spy((LoggerContext) LoggerFactory.getILoggerFactory());
JoranConfigurator configurator = spy(new JoranConfigurator());
- String logConfiguration = this.getClass().getClassLoader().getResource("logback.xml").getPath();
+ String logConfiguration =
+ this.getClass().getClassLoader().getResource("logback.xml").getPath();
daemon.configureLogging(logConfiguration, loggerContext, configurator);
verify(loggerContext).reset();
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 5320aec5..bed6b6f6 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
@@ -14,6 +14,42 @@
*/
package software.amazon.kinesis.multilang;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import com.google.common.util.concurrent.SettableFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+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;
+import software.amazon.kinesis.lifecycle.events.ProcessRecordsInput;
+import software.amazon.kinesis.lifecycle.events.ShardEndedInput;
+import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
+import software.amazon.kinesis.multilang.messages.CheckpointMessage;
+import software.amazon.kinesis.multilang.messages.LeaseLostMessage;
+import software.amazon.kinesis.multilang.messages.Message;
+import software.amazon.kinesis.multilang.messages.ProcessRecordsMessage;
+import software.amazon.kinesis.multilang.messages.ShardEndedMessage;
+import software.amazon.kinesis.multilang.messages.StatusMessage;
+import software.amazon.kinesis.processor.RecordProcessorCheckpointer;
+import software.amazon.kinesis.retrieval.KinesisClientRecord;
+
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -27,65 +63,35 @@ import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
-
-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.LeaseLostInput;
-import software.amazon.kinesis.lifecycle.events.ShardEndedInput;
-import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
-import software.amazon.kinesis.multilang.messages.CheckpointMessage;
-import software.amazon.kinesis.multilang.messages.LeaseLostMessage;
-import software.amazon.kinesis.multilang.messages.Message;
-import software.amazon.kinesis.multilang.messages.ProcessRecordsMessage;
-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.lifecycle.events.InitializationInput;
-import software.amazon.kinesis.lifecycle.events.ProcessRecordsInput;
-import software.amazon.kinesis.processor.RecordProcessorCheckpointer;
-import software.amazon.kinesis.retrieval.KinesisClientRecord;
-
@RunWith(MockitoJUnitRunner.class)
public class MultiLangProtocolTest {
private static final List EMPTY_RECORD_LIST = Collections.emptyList();
@Mock
private MultiLangProtocol protocol;
+
@Mock
private MessageWriter messageWriter;
+
@Mock
private MessageReader messageReader;
+
private String shardId;
+
@Mock
private RecordProcessorCheckpointer checkpointer;
+
@Mock
private MultiLangDaemonConfiguration configuration;
@Before
public void setup() {
this.shardId = "shard-id-123";
- protocol = new MultiLangProtocolForTesting(messageReader, messageWriter,
- InitializationInput.builder().shardId(shardId).build(), configuration);
+ protocol = new MultiLangProtocolForTesting(
+ messageReader,
+ messageWriter,
+ InitializationInput.builder().shardId(shardId).build(),
+ configuration);
when(configuration.getTimeoutInSeconds()).thenReturn(null);
}
@@ -104,28 +110,32 @@ public class MultiLangProtocolTest {
@Test
public void testInitialize() {
- when(messageWriter
- .writeInitializeMessage(argThat(Matchers.withInit(InitializationInput.builder()
- .shardId(shardId).build())))).thenReturn(buildFuture(true));
- when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(
- new StatusMessage("initialize"), Message.class));
+ when(messageWriter.writeInitializeMessage(argThat(Matchers.withInit(
+ InitializationInput.builder().shardId(shardId).build()))))
+ .thenReturn(buildFuture(true));
+ when(messageReader.getNextMessageFromSTDOUT())
+ .thenReturn(buildFuture(new StatusMessage("initialize"), Message.class));
assertThat(protocol.initialize(), equalTo(true));
}
@Test
public void testProcessRecords() {
- when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
- when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(
- new StatusMessage("processRecords"), Message.class));
+ when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class)))
+ .thenReturn(buildFuture(true));
+ when(messageReader.getNextMessageFromSTDOUT())
+ .thenReturn(buildFuture(new StatusMessage("processRecords"), Message.class));
- assertThat(protocol.processRecords(ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST).build()),
+ assertThat(
+ protocol.processRecords(
+ ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST).build()),
equalTo(true));
}
@Test
public void leaseLostTest() {
when(messageWriter.writeLeaseLossMessage(any(LeaseLostInput.class))).thenReturn(buildFuture(true));
- when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(new StatusMessage(LeaseLostMessage.ACTION), Message.class));
+ when(messageReader.getNextMessageFromSTDOUT())
+ .thenReturn(buildFuture(new StatusMessage(LeaseLostMessage.ACTION), Message.class));
assertThat(protocol.leaseLost(LeaseLostInput.builder().build()), equalTo(true));
}
@@ -133,7 +143,8 @@ public class MultiLangProtocolTest {
@Test
public void shardEndedTest() {
when(messageWriter.writeShardEndedMessage(any(ShardEndedInput.class))).thenReturn(buildFuture(true));
- when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(new StatusMessage(ShardEndedMessage.ACTION)));
+ when(messageReader.getNextMessageFromSTDOUT())
+ .thenReturn(buildFuture(new StatusMessage(ShardEndedMessage.ACTION)));
assertThat(protocol.shardEnded(ShardEndedInput.builder().build()), equalTo(true));
}
@@ -141,12 +152,12 @@ public class MultiLangProtocolTest {
@Test
public void shutdownRequestedTest() {
when(messageWriter.writeShutdownRequestedMessage()).thenReturn(buildFuture(true));
- when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(
- new StatusMessage("shutdownRequested"), Message.class));
- Mockito.doReturn(buildFuture(true)).when(messageWriter)
- .writeShutdownRequestedMessage();
+ when(messageReader.getNextMessageFromSTDOUT())
+ .thenReturn(buildFuture(new StatusMessage("shutdownRequested"), Message.class));
+ Mockito.doReturn(buildFuture(true)).when(messageWriter).writeShutdownRequestedMessage();
Mockito.doReturn(buildFuture(new StatusMessage("shutdownRequested")))
- .when(messageReader).getNextMessageFromSTDOUT();
+ .when(messageReader)
+ .getNextMessageFromSTDOUT();
assertThat(protocol.shutdownRequested(null), equalTo(true));
}
@@ -168,16 +179,17 @@ public class MultiLangProtocolTest {
}
return buildFuture(message);
}
-
}.init(messages);
}
@Test
- public void testProcessRecordsWithCheckpoints() throws
- KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
+ public void testProcessRecordsWithCheckpoints()
+ throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
- when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
- when(messageWriter.writeCheckpointMessageWithError(anyString(), anyLong(), any(Throwable.class))).thenReturn(buildFuture(true));
+ when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class)))
+ .thenReturn(buildFuture(true));
+ when(messageWriter.writeCheckpointMessageWithError(anyString(), anyLong(), any(Throwable.class)))
+ .thenReturn(buildFuture(true));
when(messageReader.getNextMessageFromSTDOUT()).thenAnswer(buildMessageAnswers(new ArrayList() {
{
this.add(new CheckpointMessage("123", 0L, null));
@@ -192,8 +204,10 @@ public class MultiLangProtocolTest {
}
}));
- boolean result = protocol.processRecords(ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST)
- .checkpointer(checkpointer).build());
+ boolean result = protocol.processRecords(ProcessRecordsInput.builder()
+ .records(EMPTY_RECORD_LIST)
+ .checkpointer(checkpointer)
+ .build());
assertThat(result, equalTo(true));
@@ -203,41 +217,52 @@ public class MultiLangProtocolTest {
@Test
public void testProcessRecordsWithABadCheckpoint() {
- when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
- when(messageWriter.writeCheckpointMessageWithError(anyString(), anyLong(), any(Throwable.class))).thenReturn(buildFuture(false));
+ 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() {
{
this.add(new CheckpointMessage("456", 0L, null));
this.add(new StatusMessage("processRecords"));
}
}));
- assertThat(protocol.processRecords(ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST)
- .checkpointer(checkpointer).build()), equalTo(false));
+ assertThat(
+ protocol.processRecords(ProcessRecordsInput.builder()
+ .records(EMPTY_RECORD_LIST)
+ .checkpointer(checkpointer)
+ .build()),
+ equalTo(false));
}
@Test(expected = NullPointerException.class)
public void waitForStatusMessageTimeoutTest() throws InterruptedException, TimeoutException, ExecutionException {
- when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
+ when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class)))
+ .thenReturn(buildFuture(true));
Future future = Mockito.mock(Future.class);
when(messageReader.getNextMessageFromSTDOUT()).thenReturn(future);
when(configuration.getTimeoutInSeconds()).thenReturn(5);
when(future.get(anyInt(), eq(TimeUnit.SECONDS))).thenThrow(TimeoutException.class);
- protocol = new MultiLangProtocolForTesting(messageReader,
+ protocol = new MultiLangProtocolForTesting(
+ messageReader,
messageWriter,
InitializationInput.builder().shardId(shardId).build(),
configuration);
- protocol.processRecords(ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST).build());
+ protocol.processRecords(
+ ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST).build());
}
@Test
public void waitForStatusMessageSuccessTest() {
- when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(buildFuture(true));
- when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(
- new StatusMessage("processRecords"), Message.class));
+ when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class)))
+ .thenReturn(buildFuture(true));
+ when(messageReader.getNextMessageFromSTDOUT())
+ .thenReturn(buildFuture(new StatusMessage("processRecords"), Message.class));
when(configuration.getTimeoutInSeconds()).thenReturn(5);
- assertTrue(protocol.processRecords(ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST).build()));
+ assertTrue(protocol.processRecords(
+ ProcessRecordsInput.builder().records(EMPTY_RECORD_LIST).build()));
}
private class MultiLangProtocolForTesting extends MultiLangProtocol {
@@ -249,10 +274,11 @@ public class MultiLangProtocolTest {
* @param initializationInput
* @param configuration
*/
- MultiLangProtocolForTesting(final MessageReader messageReader,
- final MessageWriter messageWriter,
- final InitializationInput initializationInput,
- final MultiLangDaemonConfiguration configuration) {
+ MultiLangProtocolForTesting(
+ final MessageReader messageReader,
+ final MessageWriter messageWriter,
+ final InitializationInput initializationInput,
+ final MultiLangDaemonConfiguration configuration) {
super(messageReader, messageWriter, initializationInput, configuration);
}
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/NestedPropertyKeyTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/NestedPropertyKeyTest.java
index 3f61db7a..fbffee81 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/NestedPropertyKeyTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/NestedPropertyKeyTest.java
@@ -15,6 +15,10 @@
package software.amazon.kinesis.multilang;
import com.amazonaws.regions.Regions;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
@@ -24,11 +28,6 @@ import static software.amazon.kinesis.multilang.NestedPropertyKey.ENDPOINT_REGIO
import static software.amazon.kinesis.multilang.NestedPropertyKey.EXTERNAL_ID;
import static software.amazon.kinesis.multilang.NestedPropertyKey.parse;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
@RunWith(MockitoJUnitRunner.class)
public class NestedPropertyKeyTest {
@@ -95,11 +94,11 @@ public class NestedPropertyKeyTest {
@Test
public void testNonmatchingParameters() {
final String[] params = new String[] {
- null,
- "",
- "hello world", // no nested key
- "foo=bar", // nested key, but is not a recognized key
- createKey(EXTERNAL_ID, "eid") + "=extra", // valid key made invalid by second '='
+ null,
+ "",
+ "hello world", // no nested key
+ "foo=bar", // nested key, but is not a recognized key
+ createKey(EXTERNAL_ID, "eid") + "=extra", // valid key made invalid by second '='
};
parse(mockProcessor, params);
verifyZeroInteractions(mockProcessor);
@@ -108,5 +107,4 @@ public class NestedPropertyKeyTest {
private static String createKey(final NestedPropertyKey key, final String value) {
return key.getNestedKey() + "=" + value;
}
-
-}
\ No newline at end of file
+}
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 45ff3052..9876fd21 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
@@ -72,7 +72,8 @@ public class ReadSTDERRTaskTest {
try {
finishedCleanly = result.get();
} catch (InterruptedException | ExecutionException e) {
- Assert.fail("Should have been able to get a result. The error should be handled during the call and result in false.");
+ Assert.fail(
+ "Should have been able to get a result. The error should be handled during the call and result in false.");
}
Assert.assertFalse("Reading a line should have thrown an exception", finishedCleanly);
}
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 1954cf91..d1f67ad8 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
@@ -16,12 +16,11 @@ package software.amazon.kinesis.multilang;
import org.junit.Assert;
import org.junit.Test;
-
-import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
-import software.amazon.kinesis.processor.ShardRecordProcessor;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
+import software.amazon.kinesis.processor.ShardRecordProcessor;
@RunWith(MockitoJUnitRunner.class)
public class StreamingShardRecordProcessorFactoryTest {
@@ -31,10 +30,13 @@ public class StreamingShardRecordProcessorFactoryTest {
@Test
public void createProcessorTest() {
- MultiLangRecordProcessorFactory factory = new MultiLangRecordProcessorFactory("somecommand", null, configuration);
+ MultiLangRecordProcessorFactory factory =
+ new MultiLangRecordProcessorFactory("somecommand", null, configuration);
ShardRecordProcessor processor = factory.shardRecordProcessor();
- Assert.assertEquals("Should have constructed a StreamingRecordProcessor", MultiLangShardRecordProcessor.class,
+ Assert.assertEquals(
+ "Should have constructed a StreamingRecordProcessor",
+ MultiLangShardRecordProcessor.class,
processor.getClass());
}
}
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 caa925b0..4eb66db1 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
@@ -14,15 +14,6 @@
*/
package software.amazon.kinesis.multilang;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
@@ -32,6 +23,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -41,9 +33,6 @@ import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
import software.amazon.awssdk.services.kinesis.model.Record;
import software.amazon.kinesis.exceptions.KinesisClientLibDependencyException;
import software.amazon.kinesis.exceptions.ThrottlingException;
@@ -61,6 +50,15 @@ import software.amazon.kinesis.processor.PreparedCheckpointer;
import software.amazon.kinesis.processor.RecordProcessorCheckpointer;
import software.amazon.kinesis.retrieval.KinesisClientRecord;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
@RunWith(MockitoJUnitRunner.class)
public class StreamingShardRecordProcessorTest {
@@ -70,6 +68,7 @@ public class StreamingShardRecordProcessorTest {
@Mock
private Future messageFuture;
+
@Mock
private Future trueFuture;
@@ -81,14 +80,13 @@ public class StreamingShardRecordProcessorTest {
}
@Override
- public void checkpoint(String sequenceNumber) throws KinesisClientLibDependencyException,
- ThrottlingException, IllegalArgumentException {
+ public void checkpoint(String sequenceNumber)
+ throws KinesisClientLibDependencyException, ThrottlingException, IllegalArgumentException {
throw new UnsupportedOperationException();
}
@Override
- public void checkpoint(Record record)
- throws KinesisClientLibDependencyException, ThrottlingException {
+ public void checkpoint(Record record) throws KinesisClientLibDependencyException, ThrottlingException {
throw new UnsupportedOperationException();
}
@@ -141,7 +139,8 @@ public class StreamingShardRecordProcessorTest {
}
@Override
- public PreparedCheckpointer prepareCheckpoint(String sequenceNumber, long subSequenceNumber, byte[] applicationState)
+ public PreparedCheckpointer prepareCheckpoint(
+ String sequenceNumber, long subSequenceNumber, byte[] applicationState)
throws KinesisClientLibDependencyException, ThrottlingException, IllegalArgumentException {
throw new UnsupportedOperationException();
}
@@ -178,8 +177,14 @@ public class StreamingShardRecordProcessorTest {
when(configuration.getTimeoutInSeconds()).thenReturn(null);
recordProcessor =
- new MultiLangShardRecordProcessor(new ProcessBuilder(), executor, new ObjectMapper(), messageWriter,
- messageReader, errorReader, configuration) {
+ new MultiLangShardRecordProcessor(
+ new ProcessBuilder(),
+ executor,
+ new ObjectMapper(),
+ messageWriter,
+ messageReader,
+ errorReader,
+ configuration) {
// Just don't do anything when we exit.
void exit() {
@@ -203,9 +208,12 @@ public class StreamingShardRecordProcessorTest {
Mockito.doReturn(Mockito.mock(Future.class)).when(messageReader).drainSTDOUT();
Mockito.doReturn(true).when(trueFuture).get();
- when(messageWriter.writeInitializeMessage(any(InitializationInput.class))).thenReturn(trueFuture);
- when(messageWriter.writeCheckpointMessageWithError(anyString(), anyLong(), any(Throwable.class))).thenReturn(trueFuture);
- when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class))).thenReturn(trueFuture);
+ when(messageWriter.writeInitializeMessage(any(InitializationInput.class)))
+ .thenReturn(trueFuture);
+ when(messageWriter.writeCheckpointMessageWithError(anyString(), anyLong(), any(Throwable.class)))
+ .thenReturn(trueFuture);
+ when(messageWriter.writeProcessRecordsMessage(any(ProcessRecordsInput.class)))
+ .thenReturn(trueFuture);
when(messageWriter.writeLeaseLossMessage(any(LeaseLostInput.class))).thenReturn(trueFuture);
}
@@ -223,11 +231,16 @@ public class StreamingShardRecordProcessorTest {
List testRecords = Collections.emptyList();
- recordProcessor.initialize(InitializationInput.builder().shardId(SHARD_ID).build());
- recordProcessor.processRecords(ProcessRecordsInput.builder().records(testRecords)
- .checkpointer(unimplementedCheckpointer).build());
- recordProcessor.processRecords(ProcessRecordsInput.builder().records(testRecords)
- .checkpointer(unimplementedCheckpointer).build());
+ recordProcessor.initialize(
+ InitializationInput.builder().shardId(SHARD_ID).build());
+ recordProcessor.processRecords(ProcessRecordsInput.builder()
+ .records(testRecords)
+ .checkpointer(unimplementedCheckpointer)
+ .build());
+ recordProcessor.processRecords(ProcessRecordsInput.builder()
+ .records(testRecords)
+ .checkpointer(unimplementedCheckpointer)
+ .build());
recordProcessor.leaseLost(LeaseLostInput.builder().build());
}
@@ -235,9 +248,12 @@ public class StreamingShardRecordProcessorTest {
public void processorPhasesTest() throws InterruptedException, ExecutionException {
Answer answer = new Answer() {
- StatusMessage[] answers = new StatusMessage[] { new StatusMessage(InitializeMessage.ACTION),
- new StatusMessage(ProcessRecordsMessage.ACTION), new StatusMessage(ProcessRecordsMessage.ACTION),
- new StatusMessage(ShutdownMessage.ACTION) };
+ StatusMessage[] answers = new StatusMessage[] {
+ new StatusMessage(InitializeMessage.ACTION),
+ new StatusMessage(ProcessRecordsMessage.ACTION),
+ new StatusMessage(ProcessRecordsMessage.ACTION),
+ new StatusMessage(ShutdownMessage.ACTION)
+ };
int callCount = 0;
@@ -268,9 +284,12 @@ public class StreamingShardRecordProcessorTest {
* This bad message will cause shutdown to not attempt to send a message. i.e. avoid encountering an
* exception.
*/
- StatusMessage[] answers = new StatusMessage[] { new StatusMessage("Bad"),
- new StatusMessage(ProcessRecordsMessage.ACTION), new StatusMessage(ProcessRecordsMessage.ACTION),
- new StatusMessage(ShutdownMessage.ACTION) };
+ StatusMessage[] answers = new StatusMessage[] {
+ new StatusMessage("Bad"),
+ new StatusMessage(ProcessRecordsMessage.ACTION),
+ new StatusMessage(ProcessRecordsMessage.ACTION),
+ new StatusMessage(ShutdownMessage.ACTION)
+ };
int callCount = 0;
@@ -286,8 +305,9 @@ public class StreamingShardRecordProcessorTest {
phases(answer);
- verify(messageWriter).writeInitializeMessage(argThat(Matchers.withInit(InitializationInput.builder()
- .shardId(SHARD_ID).build())));
+ verify(messageWriter)
+ .writeInitializeMessage(argThat(Matchers.withInit(
+ InitializationInput.builder().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-multilang/src/test/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProviderTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProviderTest.java
index 1c9e6bca..c27a425d 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProviderTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/auth/KclSTSAssumeRoleSessionCredentialsProviderTest.java
@@ -16,10 +16,10 @@ package software.amazon.kinesis.multilang.auth;
import java.util.Arrays;
-import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class KclSTSAssumeRoleSessionCredentialsProviderTest {
private static final String ARN = "arn";
@@ -31,7 +31,7 @@ public class KclSTSAssumeRoleSessionCredentialsProviderTest {
*/
@Test
public void testConstructorWithoutOptionalParams() {
- new KclSTSAssumeRoleSessionCredentialsProvider(new String[] { ARN, SESSION_NAME });
+ new KclSTSAssumeRoleSessionCredentialsProvider(new String[] {ARN, SESSION_NAME});
}
@Test
@@ -46,9 +46,8 @@ public class KclSTSAssumeRoleSessionCredentialsProviderTest {
@Test
public void testVarArgs() {
for (final String[] varargs : Arrays.asList(
- new String[] { ARN, SESSION_NAME, "externalId=eid", "foo"},
- new String[] { ARN, SESSION_NAME, "foo", "externalId=eid"}
- )) {
+ new String[] {ARN, SESSION_NAME, "externalId=eid", "foo"},
+ new String[] {ARN, SESSION_NAME, "foo", "externalId=eid"})) {
final VarArgsSpy provider = new VarArgsSpy(varargs);
assertEquals("eid", provider.externalId);
}
@@ -68,4 +67,4 @@ public class KclSTSAssumeRoleSessionCredentialsProviderTest {
super.acceptExternalId(externalId);
}
}
-}
\ No newline at end of file
+}
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 80e67d26..ba5a0925 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
@@ -14,14 +14,11 @@
*/
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.assertNotNull;
-import static org.junit.Assert.assertThat;
-
import java.util.Arrays;
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.AWSCredentialsProvider;
+import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.BasicAWSCredentials;
import lombok.ToString;
import org.hamcrest.Description;
@@ -30,9 +27,11 @@ import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.Test;
import software.amazon.kinesis.multilang.auth.KclSTSAssumeRoleSessionCredentialsProvider;
-import com.amazonaws.auth.AWSCredentials;
-import com.amazonaws.auth.AWSCredentialsProvider;
-import com.amazonaws.auth.AWSCredentialsProviderChain;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
public class AWSCredentialsProviderPropertyValueDecoderTest {
@@ -79,10 +78,10 @@ public class AWSCredentialsProviderPropertyValueDecoderTest {
@Override
public void describeTo(Description description) {
- description.appendText("An AWSCredentialsProvider that provides an AWSCredential matching: ")
+ description
+ .appendText("An AWSCredentialsProvider that provides an AWSCredential matching: ")
.appendList("(", ", ", ")", Arrays.asList(classMatcher, akidMatcher, secretMatcher));
}
-
}
private static AWSCredentialsMatcher hasCredentials(String akid, String secret) {
@@ -121,7 +120,7 @@ public class AWSCredentialsProviderPropertyValueDecoderTest {
for (final String className : Arrays.asList(
KclSTSAssumeRoleSessionCredentialsProvider.class.getName(), // fully-qualified name
KclSTSAssumeRoleSessionCredentialsProvider.class.getSimpleName() // name-only; needs prefix
- )) {
+ )) {
final AWSCredentialsProvider provider = decoder.decodeValue(className + "|arn|sessionName");
assertNotNull(className, provider);
}
@@ -132,7 +131,7 @@ public class AWSCredentialsProviderPropertyValueDecoderTest {
*/
@Test
public void testVarArgAuthProvider() {
- final String[] args = new String[] { "arg1", "arg2", "arg3" };
+ final String[] args = new String[] {"arg1", "arg2", "arg3"};
final String className = VarArgCredentialsProvider.class.getName();
final String encodedValue = className + "|" + String.join("|", args);
@@ -151,9 +150,7 @@ public class AWSCredentialsProviderPropertyValueDecoderTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
/**
@@ -180,9 +177,7 @@ public class AWSCredentialsProviderPropertyValueDecoderTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
private static class VarArgCredentialsProvider implements AWSCredentialsProvider {
@@ -201,8 +196,6 @@ public class AWSCredentialsProviderPropertyValueDecoderTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
}
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/BuilderDynaBeanTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/BuilderDynaBeanTest.java
index 9038453a..ac687b82 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/BuilderDynaBeanTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/BuilderDynaBeanTest.java
@@ -15,16 +15,14 @@
package software.amazon.kinesis.multilang.config;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
import java.util.function.Consumer;
import java.util.function.Supplier;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import lombok.experimental.Accessors;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtilsBean;
import org.junit.Before;
@@ -32,11 +30,12 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import lombok.Builder;
-import lombok.EqualsAndHashCode;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
-import lombok.experimental.Accessors;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
public class BuilderDynaBeanTest {
@@ -109,8 +108,8 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexCreateAllParameters() throws Exception {
- TestComplexCreate expected = TestComplexCreate.create("real",
- TestSimpleBuilder.builder().stringL1("l1").longVal(10L).build());
+ TestComplexCreate expected = TestComplexCreate.create(
+ "real", TestSimpleBuilder.builder().stringL1("l1").longVal(10L).build());
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestComplexCreate.class, convertUtilsBean);
utilsBean.setProperty(builderDynaBean, "[0]", expected.realName);
@@ -136,8 +135,8 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexCreateComplexParameterOnly() throws Exception {
- TestComplexCreate expected = TestComplexCreate.create(null,
- TestSimpleBuilder.builder().stringL1("l1").longVal(10L).build());
+ TestComplexCreate expected = TestComplexCreate.create(
+ null, TestSimpleBuilder.builder().stringL1("l1").longVal(10L).build());
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestComplexCreate.class, convertUtilsBean);
utilsBean.setProperty(builderDynaBean, "[1].stringL1", expected.test1.stringL1);
@@ -161,7 +160,8 @@ public class BuilderDynaBeanTest {
@Test
public void testSimpleBuilderAllParameters() throws Exception {
- TestSimpleBuilder expected = TestSimpleBuilder.builder().stringL1("l1").longVal(10L).build();
+ TestSimpleBuilder expected =
+ TestSimpleBuilder.builder().stringL1("l1").longVal(10L).build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestSimpleBuilder.class, convertUtilsBean);
utilsBean.setProperty(builderDynaBean, "stringL1", expected.stringL1);
@@ -213,12 +213,14 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexCreateSimpleBuilderVariantAllParameters() throws Exception {
- TestSimpleBuilder variant = TestSimpleBuilder.builder().longVal(10L).stringL1("variant").build();
+ TestSimpleBuilder variant =
+ TestSimpleBuilder.builder().longVal(10L).stringL1("variant").build();
TestComplexCreateVariance expected = TestComplexCreateVariance.create("simple-builder", variant);
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestComplexCreateVariance.class, convertUtilsBean);
utilsBean.setProperty(builderDynaBean, "[0]", expected.varianceName);
- utilsBean.setProperty(builderDynaBean, "[1].class", expected.variant.getClass().getName());
+ utilsBean.setProperty(
+ builderDynaBean, "[1].class", expected.variant.getClass().getName());
utilsBean.setProperty(builderDynaBean, "[1].longVal", variant.longVal);
utilsBean.setProperty(builderDynaBean, "[1].stringL1", variant.stringL1);
@@ -229,8 +231,11 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexCreateVariantBuilderAllParameters() throws Exception {
- TestVariantBuilder variant = TestVariantBuilder.builder().variantBuilderName("variant-build").intClass(20)
- .testEnum(TestEnum.Blue).build();
+ TestVariantBuilder variant = TestVariantBuilder.builder()
+ .variantBuilderName("variant-build")
+ .intClass(20)
+ .testEnum(TestEnum.Blue)
+ .build();
TestComplexCreateVariance expected = TestComplexCreateVariance.create("builder-variant", variant);
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestComplexCreateVariance.class, convertUtilsBean);
@@ -264,13 +269,16 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexCreateVariantBuilderAllParametersPrefixWithJoiner() throws Exception {
- TestVariantBuilder variant = TestVariantBuilder.builder().variantBuilderName("variant-build").intClass(20)
- .testEnum(TestEnum.Blue).build();
+ TestVariantBuilder variant = TestVariantBuilder.builder()
+ .variantBuilderName("variant-build")
+ .intClass(20)
+ .testEnum(TestEnum.Blue)
+ .build();
TestComplexCreateVariance expected = TestComplexCreateVariance.create("builder-variant-prefix", variant);
String prefix = variant.getClass().getEnclosingClass().getName() + "$";
- BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestComplexCreateVariance.class, convertUtilsBean,
- prefix);
+ BuilderDynaBean builderDynaBean =
+ new BuilderDynaBean(TestComplexCreateVariance.class, convertUtilsBean, prefix);
utilsBean.setProperty(builderDynaBean, "[0]", expected.varianceName);
utilsBean.setProperty(builderDynaBean, "[1].class", variant.getClass().getSimpleName());
utilsBean.setProperty(builderDynaBean, "[1].variantBuilderName", variant.variantBuilderName);
@@ -284,13 +292,16 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexCreateVariantBuilderAllParametersPrefixWithOutJoiner() throws Exception {
- TestVariantBuilder variant = TestVariantBuilder.builder().variantBuilderName("variant-build").intClass(20)
- .testEnum(TestEnum.Blue).build();
+ TestVariantBuilder variant = TestVariantBuilder.builder()
+ .variantBuilderName("variant-build")
+ .intClass(20)
+ .testEnum(TestEnum.Blue)
+ .build();
TestComplexCreateVariance expected = TestComplexCreateVariance.create("builder-variant-prefix", variant);
String prefix = variant.getClass().getEnclosingClass().getName();
- BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestComplexCreateVariance.class, convertUtilsBean,
- prefix);
+ BuilderDynaBean builderDynaBean =
+ new BuilderDynaBean(TestComplexCreateVariance.class, convertUtilsBean, prefix);
utilsBean.setProperty(builderDynaBean, "[0]", expected.varianceName);
utilsBean.setProperty(builderDynaBean, "[1].class", variant.getClass().getSimpleName());
utilsBean.setProperty(builderDynaBean, "[1].variantBuilderName", variant.variantBuilderName);
@@ -330,11 +341,21 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexRootAllParameters() throws Exception {
- TestSimpleBuilder simpleBuilder = TestSimpleBuilder.builder().stringL1("simple-l1").longVal(20L).build();
- TestRootClass expected = TestRootClass.builder().intVal(10).stringVal("root").testEnum(TestEnum.Red)
- .testComplexCreate(TestComplexCreate.create("real",
- TestSimpleBuilder.builder().stringL1("complex-l1").longVal(10L).build()))
- .testSimpleBuilder(simpleBuilder).testSimpleCreate(TestSimpleCreate.create("first", "last")).build();
+ TestSimpleBuilder simpleBuilder =
+ TestSimpleBuilder.builder().stringL1("simple-l1").longVal(20L).build();
+ TestRootClass expected = TestRootClass.builder()
+ .intVal(10)
+ .stringVal("root")
+ .testEnum(TestEnum.Red)
+ .testComplexCreate(TestComplexCreate.create(
+ "real",
+ TestSimpleBuilder.builder()
+ .stringL1("complex-l1")
+ .longVal(10L)
+ .build()))
+ .testSimpleBuilder(simpleBuilder)
+ .testSimpleCreate(TestSimpleCreate.create("first", "last"))
+ .build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestRootClass.class, convertUtilsBean);
@@ -342,10 +363,10 @@ public class BuilderDynaBeanTest {
utilsBean.setProperty(builderDynaBean, "stringVal", expected.stringVal);
utilsBean.setProperty(builderDynaBean, "testEnum", expected.testEnum);
utilsBean.setProperty(builderDynaBean, "testComplexCreate.[0]", expected.testComplexCreate.realName);
- utilsBean.setProperty(builderDynaBean, "testComplexCreate.[1].stringL1",
- expected.testComplexCreate.test1.stringL1);
- utilsBean.setProperty(builderDynaBean, "testComplexCreate.[1].longVal",
- expected.testComplexCreate.test1.longVal);
+ utilsBean.setProperty(
+ builderDynaBean, "testComplexCreate.[1].stringL1", expected.testComplexCreate.test1.stringL1);
+ utilsBean.setProperty(
+ builderDynaBean, "testComplexCreate.[1].longVal", expected.testComplexCreate.test1.longVal);
utilsBean.setProperty(builderDynaBean, "testSimpleBuilder.class", TestSimpleBuilder.class.getName());
utilsBean.setProperty(builderDynaBean, "testSimpleBuilder.stringL1", simpleBuilder.stringL1);
utilsBean.setProperty(builderDynaBean, "testSimpleBuilder.longVal", simpleBuilder.longVal);
@@ -370,7 +391,11 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexRootTopLevelOnly() throws Exception {
- TestRootClass expected = TestRootClass.builder().intVal(10).stringVal("root").testEnum(TestEnum.Red).build();
+ TestRootClass expected = TestRootClass.builder()
+ .intVal(10)
+ .stringVal("root")
+ .testEnum(TestEnum.Red)
+ .build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestRootClass.class, convertUtilsBean);
@@ -385,12 +410,17 @@ public class BuilderDynaBeanTest {
@Test
public void testSupplierNotUsed() throws Exception {
- TestVariantBuilder variant = TestVariantBuilder.builder().testEnum(TestEnum.Green).intClass(10)
- .variantBuilderName("variant-supplier").build();
- TestSupplierClass expected = TestSupplierClass.builder().variantClass(variant).build();
+ TestVariantBuilder variant = TestVariantBuilder.builder()
+ .testEnum(TestEnum.Green)
+ .intClass(10)
+ .variantBuilderName("variant-supplier")
+ .build();
+ TestSupplierClass expected =
+ TestSupplierClass.builder().variantClass(variant).build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestSupplierClass.class, convertUtilsBean);
- utilsBean.setProperty(builderDynaBean, "variantClass.class", variant.getClass().getName());
+ utilsBean.setProperty(
+ builderDynaBean, "variantClass.class", variant.getClass().getName());
utilsBean.setProperty(builderDynaBean, "variantClass.testEnum", variant.testEnum);
utilsBean.setProperty(builderDynaBean, "variantClass.intClass", variant.intClass);
utilsBean.setProperty(builderDynaBean, "variantClass.variantBuilderName", variant.variantBuilderName);
@@ -422,8 +452,11 @@ public class BuilderDynaBeanTest {
@Test
public void testVariantBuildsToSuperType() throws Exception {
- TestVariantBuilder expected = TestVariantBuilder.builder().intClass(10).testEnum(TestEnum.Green)
- .variantBuilderName("variant-super").build();
+ TestVariantBuilder expected = TestVariantBuilder.builder()
+ .intClass(10)
+ .testEnum(TestEnum.Green)
+ .variantBuilderName("variant-super")
+ .build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestInterface.class, convertUtilsBean);
utilsBean.setProperty(builderDynaBean, "class", expected.getClass().getName());
@@ -439,9 +472,11 @@ public class BuilderDynaBeanTest {
@Test
public void testEmptyPropertyHandler() throws Exception {
String emptyPropertyValue = "test-property";
- TestVariantCreate expected = TestVariantCreate.create(emptyPropertyValue, (long) emptyPropertyValue.length(),
- emptyPropertyValue + "-vary");
- BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestInterface.class, convertUtilsBean,
+ TestVariantCreate expected = TestVariantCreate.create(
+ emptyPropertyValue, (long) emptyPropertyValue.length(), emptyPropertyValue + "-vary");
+ BuilderDynaBean builderDynaBean = new BuilderDynaBean(
+ TestInterface.class,
+ convertUtilsBean,
s -> TestVariantCreate.create(s, (long) s.length(), s + "-vary"));
utilsBean.setProperty(builderDynaBean, "", emptyPropertyValue);
@@ -455,8 +490,8 @@ public class BuilderDynaBeanTest {
thrown.expect(IllegalStateException.class);
thrown.expectMessage(containsString("When a property handler is resolved further properties may not be set."));
- BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestInterface.class, convertUtilsBean,
- s -> TestVariantCreate.create("test", 10, "test"));
+ BuilderDynaBean builderDynaBean = new BuilderDynaBean(
+ TestInterface.class, convertUtilsBean, s -> TestVariantCreate.create("test", 10, "test"));
utilsBean.setProperty(builderDynaBean, "", "test");
utilsBean.setProperty(builderDynaBean, "[0]", "test");
}
@@ -468,8 +503,8 @@ public class BuilderDynaBeanTest {
thrown.expectMessage(containsString(TestInterface.class.getName()));
thrown.expectMessage(containsString("cannot be assigned to"));
- BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestInterface.class, convertUtilsBean,
- s -> TestEnum.Green);
+ BuilderDynaBean builderDynaBean =
+ new BuilderDynaBean(TestInterface.class, convertUtilsBean, s -> TestEnum.Green);
utilsBean.setProperty(builderDynaBean, "", "test");
@@ -478,8 +513,11 @@ public class BuilderDynaBeanTest {
@Test
public void testSimpleArrayValues() throws Exception {
- SimpleArrayClassVariant expected = SimpleArrayClassVariant.builder().ints(new Integer[] { 1, 2, 3 })
- .variantName("simple-array").longs(new Long[] { 1L, 2L, 3L }).strings(new String[] { "a", "b", "c" })
+ SimpleArrayClassVariant expected = SimpleArrayClassVariant.builder()
+ .ints(new Integer[] {1, 2, 3})
+ .variantName("simple-array")
+ .longs(new Long[] {1L, 2L, 3L})
+ .strings(new String[] {"a", "b", "c"})
.build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(SimpleArrayClassVariant.class, convertUtilsBean);
@@ -503,12 +541,20 @@ public class BuilderDynaBeanTest {
@Test
public void testComplexArrayValuesBuilder() throws Exception {
- TestVariantBuilder variant1 = TestVariantBuilder.builder().variantBuilderName("variant-1")
- .testEnum(TestEnum.Green).intClass(10).build();
- TestVariantBuilder variant2 = TestVariantBuilder.builder().variantBuilderName("variant-2")
- .testEnum(TestEnum.Blue).intClass(20).build();
- ComplexArrayClassVariant expected = ComplexArrayClassVariant.builder().variantName("complex-test")
- .tests(new TestInterface[] { variant1, variant2 }).build();
+ TestVariantBuilder variant1 = TestVariantBuilder.builder()
+ .variantBuilderName("variant-1")
+ .testEnum(TestEnum.Green)
+ .intClass(10)
+ .build();
+ TestVariantBuilder variant2 = TestVariantBuilder.builder()
+ .variantBuilderName("variant-2")
+ .testEnum(TestEnum.Blue)
+ .intClass(20)
+ .build();
+ ComplexArrayClassVariant expected = ComplexArrayClassVariant.builder()
+ .variantName("complex-test")
+ .tests(new TestInterface[] {variant1, variant2})
+ .build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(ComplexArrayClassVariant.class, convertUtilsBean);
@@ -533,18 +579,22 @@ public class BuilderDynaBeanTest {
TestVariantCreate variant1 = TestVariantCreate.create("variant-1", 10L, "vary-1");
TestVariantCreate variant2 = TestVariantCreate.create("variant-2", 20L, "vary-2");
- ComplexArrayClassVariant expected = ComplexArrayClassVariant.builder().variantName("create-test")
- .tests(new TestInterface[] { variant1, variant2 }).build();
+ ComplexArrayClassVariant expected = ComplexArrayClassVariant.builder()
+ .variantName("create-test")
+ .tests(new TestInterface[] {variant1, variant2})
+ .build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(ComplexArrayClassVariant.class, convertUtilsBean);
utilsBean.setProperty(builderDynaBean, "variantName", expected.variantName);
- utilsBean.setProperty(builderDynaBean, "tests[0].class", variant1.getClass().getName());
+ utilsBean.setProperty(
+ builderDynaBean, "tests[0].class", variant1.getClass().getName());
utilsBean.setProperty(builderDynaBean, "tests[0].[0]", variant1.variantCreateName);
utilsBean.setProperty(builderDynaBean, "tests[0].[1]", variant1.longClass);
utilsBean.setProperty(builderDynaBean, "tests[0].[2]", variant1.varyString);
- utilsBean.setProperty(builderDynaBean, "tests[1].class", variant2.getClass().getName());
+ utilsBean.setProperty(
+ builderDynaBean, "tests[1].class", variant2.getClass().getName());
utilsBean.setProperty(builderDynaBean, "tests[1].[0]", variant2.variantCreateName);
utilsBean.setProperty(builderDynaBean, "tests[1].[1]", variant2.longClass);
utilsBean.setProperty(builderDynaBean, "tests[1].[2]", variant2.varyString);
@@ -552,7 +602,6 @@ public class BuilderDynaBeanTest {
ComplexArrayClassVariant actual = builderDynaBean.build(ComplexArrayClassVariant.class);
assertThat(actual, equalTo(expected));
-
}
@Test
@@ -562,13 +611,18 @@ public class BuilderDynaBeanTest {
if (i % 2 == 0) {
variants[i] = TestVariantCreate.create("create-variant-" + i, i + 5, "vary-" + i);
} else {
- variants[i] = TestVariantBuilder.builder().testEnum(TestEnum.values()[i % TestEnum.values().length])
- .intClass(i).variantBuilderName("builder-variant-" + i).build();
+ variants[i] = TestVariantBuilder.builder()
+ .testEnum(TestEnum.values()[i % TestEnum.values().length])
+ .intClass(i)
+ .variantBuilderName("builder-variant-" + i)
+ .build();
}
}
- ComplexArrayClassVariant expected = ComplexArrayClassVariant.builder().variantName("large-complex")
- .tests(variants).build();
+ ComplexArrayClassVariant expected = ComplexArrayClassVariant.builder()
+ .variantName("large-complex")
+ .tests(variants)
+ .build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(ComplexArrayClassVariant.class, convertUtilsBean);
@@ -578,13 +632,15 @@ public class BuilderDynaBeanTest {
TestInterface variant = variants[i];
if (variant instanceof TestVariantCreate) {
TestVariantCreate create = (TestVariantCreate) variant;
- utilsBean.setProperty(builderDynaBean, prefix + "class", create.getClass().getName());
+ utilsBean.setProperty(
+ builderDynaBean, prefix + "class", create.getClass().getName());
utilsBean.setProperty(builderDynaBean, prefix + "[0]", create.variantCreateName);
utilsBean.setProperty(builderDynaBean, prefix + "[1]", create.longClass);
utilsBean.setProperty(builderDynaBean, prefix + "[2]", create.varyString);
} else if (variant instanceof TestVariantBuilder) {
TestVariantBuilder builder = (TestVariantBuilder) variant;
- utilsBean.setProperty(builderDynaBean, prefix + "class", builder.getClass().getName());
+ utilsBean.setProperty(
+ builderDynaBean, prefix + "class", builder.getClass().getName());
utilsBean.setProperty(builderDynaBean, prefix + "variantBuilderName", builder.variantBuilderName);
utilsBean.setProperty(builderDynaBean, prefix + "intClass", builder.intClass);
utilsBean.setProperty(builderDynaBean, prefix + "testEnum", builder.testEnum);
@@ -667,25 +723,27 @@ public class BuilderDynaBeanTest {
@Test
public void testAdditionalMutators() throws Exception {
- TestSimpleBuilder expected = TestSimpleBuilder.builder().stringL1("test").longVal(10L).build();
+ TestSimpleBuilder expected =
+ TestSimpleBuilder.builder().stringL1("test").longVal(10L).build();
BuilderDynaBean builderDynaBean = new BuilderDynaBean(TestSimpleBuilder.class, convertUtilsBean);
utilsBean.setProperty(builderDynaBean, "stringL1", expected.stringL1);
- TestSimpleBuilder actual = builderDynaBean.build(TestSimpleBuilder.class,
- b -> ((TestSimpleBuilder.TestSimpleBuilderBuilder) b).longVal(expected.longVal));
+ TestSimpleBuilder actual =
+ builderDynaBean.build(TestSimpleBuilder.class, b -> ((TestSimpleBuilder.TestSimpleBuilderBuilder) b)
+ .longVal(expected.longVal));
assertThat(actual, equalTo(expected));
}
public enum TestEnum {
- Red, Green, Blue
+ Red,
+ Green,
+ Blue
}
- public interface TestInterface {
-
- }
+ public interface TestInterface {}
@Accessors(fluent = true)
@ToString
@@ -838,7 +896,5 @@ public class BuilderDynaBeanTest {
}
public String name = "default";
-
}
-
-}
\ No newline at end of file
+}
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtilsTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtilsTest.java
index 96de848e..5e0db340 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtilsTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/ConfigurationSettableUtilsTest.java
@@ -15,18 +15,17 @@
package software.amazon.kinesis.multilang.config;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
-
import java.util.Optional;
-import org.junit.Test;
-
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
public class ConfigurationSettableUtilsTest {
@@ -44,7 +43,10 @@ public class ConfigurationSettableUtilsTest {
public void testPrimitivesSet() {
ConfigResult expected = ConfigResult.builder().rawInt(10).rawLong(15L).build();
- ConfigObject configObject = ConfigObject.builder().rawInt(expected.rawInt).rawLong(expected.rawLong).build();
+ ConfigObject configObject = ConfigObject.builder()
+ .rawInt(expected.rawInt)
+ .rawLong(expected.rawLong)
+ .build();
ConfigResult actual = resolve(configObject);
assertThat(actual, equalTo(expected));
@@ -52,10 +54,14 @@ public class ConfigurationSettableUtilsTest {
@Test
public void testHeapValuesSet() {
- ConfigResult expected = ConfigResult.builder().name("test").boxedInt(10).boxedLong(15L).build();
+ ConfigResult expected =
+ ConfigResult.builder().name("test").boxedInt(10).boxedLong(15L).build();
- ConfigObject configObject = ConfigObject.builder().name(expected.name).boxedInt(expected.boxedInt.intValue())
- .boxedLong(expected.boxedLong.longValue()).build();
+ ConfigObject configObject = ConfigObject.builder()
+ .name(expected.name)
+ .boxedInt(expected.boxedInt.intValue())
+ .boxedLong(expected.boxedLong.longValue())
+ .build();
ConfigResult actual = resolve(configObject);
assertThat(actual, equalTo(expected));
@@ -63,27 +69,39 @@ public class ConfigurationSettableUtilsTest {
@Test
public void testComplexValuesSet() {
- ComplexValue complexValue = ComplexValue.builder().name("complex").value(10).build();
- ConfigResult expected = ConfigResult.builder().complexValue(complexValue).build();
+ ComplexValue complexValue =
+ ComplexValue.builder().name("complex").value(10).build();
+ ConfigResult expected =
+ ConfigResult.builder().complexValue(complexValue).build();
ConfigObject configObject = ConfigObject.builder()
- .complexValue(ComplexValue.builder().name(complexValue.name).value(complexValue.value).build()).build();
+ .complexValue(ComplexValue.builder()
+ .name(complexValue.name)
+ .value(complexValue.value)
+ .build())
+ .build();
ConfigResult actual = resolve(configObject);
assertThat(actual, equalTo(expected));
-
}
@Test
public void testOptionalValuesSet() {
- ComplexValue complexValue = ComplexValue.builder().name("optional-complex").value(20).build();
- ConfigResult expected = ConfigResult.builder().optionalString(Optional.of("test"))
- .optionalInteger(Optional.of(10)).optionalLong(Optional.of(15L))
- .optionalComplexValue(Optional.of(complexValue)).build();
+ ComplexValue complexValue =
+ ComplexValue.builder().name("optional-complex").value(20).build();
+ ConfigResult expected = ConfigResult.builder()
+ .optionalString(Optional.of("test"))
+ .optionalInteger(Optional.of(10))
+ .optionalLong(Optional.of(15L))
+ .optionalComplexValue(Optional.of(complexValue))
+ .build();
- ConfigObject configObject = ConfigObject.builder().optionalString(expected.optionalString.get())
- .optionalInteger(expected.optionalInteger.get()).optionalLong(expected.optionalLong.get())
- .optionalComplexValue(expected.optionalComplexValue.get()).build();
+ ConfigObject configObject = ConfigObject.builder()
+ .optionalString(expected.optionalString.get())
+ .optionalInteger(expected.optionalInteger.get())
+ .optionalLong(expected.optionalLong.get())
+ .optionalComplexValue(expected.optionalComplexValue.get())
+ .build();
ConfigResult actual = resolve(configObject);
assertThat(actual, equalTo(expected));
@@ -91,20 +109,29 @@ public class ConfigurationSettableUtilsTest {
@Test
public void testRenamedRawValues() {
- ComplexValue complexValue = ComplexValue.builder().name("renamed-complex").value(20).build();
- ConfigResult expected = ConfigResult.builder().renamedString("renamed").renamedInt(10)
- .renamedOptionalString(Optional.of("renamed-optional")).renamedComplexValue(complexValue).build();
+ ComplexValue complexValue =
+ ComplexValue.builder().name("renamed-complex").value(20).build();
+ ConfigResult expected = ConfigResult.builder()
+ .renamedString("renamed")
+ .renamedInt(10)
+ .renamedOptionalString(Optional.of("renamed-optional"))
+ .renamedComplexValue(complexValue)
+ .build();
- ConfigObject configObject = ConfigObject.builder().toRenameString(expected.renamedString)
- .toRenameInt(expected.renamedInt).toRenameComplexValue(complexValue)
- .optionalToRename(expected.renamedOptionalString.get()).build();
+ ConfigObject configObject = ConfigObject.builder()
+ .toRenameString(expected.renamedString)
+ .toRenameInt(expected.renamedInt)
+ .toRenameComplexValue(complexValue)
+ .optionalToRename(expected.renamedOptionalString.get())
+ .build();
ConfigResult actual = resolve(configObject);
assertThat(actual, equalTo(expected));
}
private ConfigResult resolve(ConfigObject configObject) {
- return ConfigurationSettableUtils.resolveFields(configObject, ConfigResult.builder().build());
+ return ConfigurationSettableUtils.resolveFields(
+ configObject, ConfigResult.builder().build());
}
@Accessors(fluent = true)
@@ -129,7 +156,6 @@ public class ConfigurationSettableUtilsTest {
private int renamedInt;
private Optional renamedOptionalString;
private ComplexValue renamedComplexValue;
-
}
@Accessors(fluent = true)
@@ -145,35 +171,47 @@ public class ConfigurationSettableUtilsTest {
@ConfigurationSettable(configurationClass = ConfigResult.class)
private String name;
+
@ConfigurationSettable(configurationClass = ConfigResult.class)
private int rawInt;
+
@ConfigurationSettable(configurationClass = ConfigResult.class)
private Integer boxedInt;
+
@ConfigurationSettable(configurationClass = ConfigResult.class)
private long rawLong;
+
@ConfigurationSettable(configurationClass = ConfigResult.class)
private Long boxedLong;
+
@ConfigurationSettable(configurationClass = ConfigResult.class)
private ComplexValue complexValue;
@ConfigurationSettable(configurationClass = ConfigResult.class, convertToOptional = true)
private String optionalString;
+
@ConfigurationSettable(configurationClass = ConfigResult.class, convertToOptional = true)
private Integer optionalInteger;
+
@ConfigurationSettable(configurationClass = ConfigResult.class, convertToOptional = true)
private Long optionalLong;
+
@ConfigurationSettable(configurationClass = ConfigResult.class, convertToOptional = true)
private ComplexValue optionalComplexValue;
@ConfigurationSettable(configurationClass = ConfigResult.class, methodName = "renamedString")
private String toRenameString;
+
@ConfigurationSettable(configurationClass = ConfigResult.class, methodName = "renamedInt")
private int toRenameInt;
- @ConfigurationSettable(configurationClass = ConfigResult.class, methodName = "renamedOptionalString", convertToOptional = true)
+
+ @ConfigurationSettable(
+ configurationClass = ConfigResult.class,
+ methodName = "renamedOptionalString",
+ convertToOptional = true)
private String optionalToRename;
+
@ConfigurationSettable(configurationClass = ConfigResult.class, methodName = "renamedComplexValue")
private ComplexValue toRenameComplexValue;
-
}
-
-}
\ No newline at end of file
+}
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoderTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoderTest.java
index a3aace72..d274f9f2 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoderTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/DatePropertyValueDecoderTest.java
@@ -14,12 +14,12 @@
*/
package software.amazon.kinesis.multilang.config;
-import static org.junit.Assert.assertEquals;
-
import java.util.Date;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class DatePropertyValueDecoderTest {
private DatePropertyValueDecoder decoder = new DatePropertyValueDecoder();
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/FanoutConfigBeanTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/FanoutConfigBeanTest.java
index 11b12588..255a07ff 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/FanoutConfigBeanTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/FanoutConfigBeanTest.java
@@ -21,7 +21,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
import software.amazon.kinesis.retrieval.fanout.FanOutConfig;
@@ -50,18 +49,22 @@ public class FanoutConfigBeanTest {
MultiLangDaemonConfiguration configuration = new MultiLangDaemonConfiguration(utilsBean, convertUtilsBean);
configuration.setStreamName("test-stream");
configuration.setApplicationName("test-application");
- FanOutConfig fanOutConfig =fanoutConfigBean.build(kinesisAsyncClient, configuration);
+ FanOutConfig fanOutConfig = fanoutConfigBean.build(kinesisAsyncClient, configuration);
assertThat(fanOutConfig.kinesisClient(), equalTo(kinesisAsyncClient));
assertThat(fanOutConfig.streamName(), equalTo(configuration.getStreamName()));
assertThat(fanOutConfig.applicationName(), equalTo(configuration.getApplicationName()));
assertThat(fanOutConfig.consumerArn(), equalTo(fanoutConfigBean.getConsumerArn()));
assertThat(fanOutConfig.consumerName(), equalTo(fanoutConfigBean.getConsumerName()));
- assertThat(fanOutConfig.maxDescribeStreamConsumerRetries(), equalTo(fanoutConfigBean.getMaxDescribeStreamConsumerRetries()));
- assertThat(fanOutConfig.maxDescribeStreamSummaryRetries(), equalTo(fanoutConfigBean.getMaxDescribeStreamSummaryRetries()));
- assertThat(fanOutConfig.registerStreamConsumerRetries(), equalTo(fanoutConfigBean.getRegisterStreamConsumerRetries()));
+ assertThat(
+ fanOutConfig.maxDescribeStreamConsumerRetries(),
+ equalTo(fanoutConfigBean.getMaxDescribeStreamConsumerRetries()));
+ assertThat(
+ fanOutConfig.maxDescribeStreamSummaryRetries(),
+ equalTo(fanoutConfigBean.getMaxDescribeStreamSummaryRetries()));
+ assertThat(
+ fanOutConfig.registerStreamConsumerRetries(),
+ equalTo(fanoutConfigBean.getRegisterStreamConsumerRetries()));
assertThat(fanOutConfig.retryBackoffMillis(), equalTo(fanoutConfigBean.getRetryBackoffMillis()));
-
}
-
-}
\ No newline at end of file
+}
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 2b02ea43..b0e3b870 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
@@ -14,15 +14,6 @@
*/
package software.amazon.kinesis.multilang.config;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
@@ -34,18 +25,25 @@ import java.util.Set;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
+import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.junit.Test;
-
-import com.google.common.collect.ImmutableSet;
-
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.kinesis.common.InitialPositionInStream;
import software.amazon.kinesis.metrics.MetricsLevel;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
@RunWith(MockitoJUnitRunner.class)
public class KinesisClientLibConfiguratorTest {
@@ -58,8 +56,14 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithBasicSetup() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = " + credentialName1, "workerId = 123" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialName1,
+ "workerId = 123"
+ },
+ '\n'));
assertEquals(config.getApplicationName(), "b");
assertEquals(config.getStreamName(), "a");
assertEquals(config.getWorkerIdentifier(), "123");
@@ -69,9 +73,16 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithLongVariables() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "applicationName = app",
- "streamName = 123", "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
- "workerId = 123", "failoverTimeMillis = 100", "shardSyncIntervalMillis = 500" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "applicationName = app",
+ "streamName = 123",
+ "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
+ "workerId = 123",
+ "failoverTimeMillis = 100",
+ "shardSyncIntervalMillis = 500"
+ },
+ '\n'));
assertEquals(config.getApplicationName(), "app");
assertEquals(config.getStreamName(), "123");
@@ -83,9 +94,14 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithInitialPositionInStreamExtended() {
long epochTimeInSeconds = 1617406032;
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "applicationName = app",
- "streamName = 123", "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
- "initialPositionInStreamExtended = " + epochTimeInSeconds}, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "applicationName = app",
+ "streamName = 123",
+ "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
+ "initialPositionInStreamExtended = " + epochTimeInSeconds
+ },
+ '\n'));
assertEquals(config.getInitialPositionInStreamExtended().getTimestamp(), new Date(epochTimeInSeconds * 1000L));
assertEquals(config.getInitialPositionInStream(), InitialPositionInStream.AT_TIMESTAMP);
@@ -96,9 +112,14 @@ public class KinesisClientLibConfiguratorTest {
// AT_TIMESTAMP cannot be used as initialPositionInStream. If a user wants to specify AT_TIMESTAMP,
// they must specify the time with initialPositionInStreamExtended.
try {
- getConfiguration(StringUtils.join(new String[] { "applicationName = app",
- "streamName = 123", "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
- "initialPositionInStream = AT_TIMESTAMP"}, '\n'));
+ getConfiguration(StringUtils.join(
+ new String[] {
+ "applicationName = app",
+ "streamName = 123",
+ "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
+ "initialPositionInStream = AT_TIMESTAMP"
+ },
+ '\n'));
fail("Should have thrown when initialPositionInStream is set to AT_TIMESTAMP");
} catch (Exception e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
@@ -111,9 +132,14 @@ public class KinesisClientLibConfiguratorTest {
// initialPositionInStreamExtended takes a long value indicating seconds since epoch. If a non-long
// value is provided, the constructor should throw an IllegalArgumentException exception.
try {
- getConfiguration(StringUtils.join(new String[] { "applicationName = app",
- "streamName = 123", "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
- "initialPositionInStreamExtended = null"}, '\n'));
+ getConfiguration(StringUtils.join(
+ new String[] {
+ "applicationName = app",
+ "streamName = 123",
+ "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
+ "initialPositionInStreamExtended = null"
+ },
+ '\n'));
fail("Should have thrown when initialPositionInStreamExtended is set to null");
} catch (Exception e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
@@ -124,8 +150,13 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithUnsupportedClientConfigurationVariables() {
MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
- new String[] { "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2, "workerId = id",
- "kinesisClientConfig = {}", "streamName = stream", "applicationName = b" },
+ new String[] {
+ "AWSCredentialsProvider = " + credentialName1 + ", " + credentialName2,
+ "workerId = id",
+ "kinesisClientConfig = {}",
+ "streamName = stream",
+ "applicationName = b"
+ },
'\n'));
assertEquals(config.getApplicationName(), "b");
@@ -136,10 +167,18 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithIntVariables() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = kinesis",
- "AWSCredentialsProvider = " + credentialName2 + ", " + credentialName1, "workerId = w123",
- "maxRecords = 10", "metricsMaxQueueSize = 20", "applicationName = kinesis",
- "retryGetRecordsInSeconds = 2", "maxGetRecordsThreadPool = 1" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = kinesis",
+ "AWSCredentialsProvider = " + credentialName2 + ", " + credentialName1,
+ "workerId = w123",
+ "maxRecords = 10",
+ "metricsMaxQueueSize = 20",
+ "applicationName = kinesis",
+ "retryGetRecordsInSeconds = 2",
+ "maxGetRecordsThreadPool = 1"
+ },
+ '\n'));
assertEquals(config.getApplicationName(), "kinesis");
assertEquals(config.getStreamName(), "kinesis");
@@ -152,9 +191,15 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithBooleanVariables() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = ABCD, " + credentialName1, "workerId = 0",
- "cleanupLeasesUponShardCompletion = false", "validateSequenceNumberBeforeCheckpointing = true" },
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD, " + credentialName1,
+ "workerId = 0",
+ "cleanupLeasesUponShardCompletion = false",
+ "validateSequenceNumberBeforeCheckpointing = true"
+ },
'\n'));
assertEquals(config.getApplicationName(), "b");
@@ -166,9 +211,16 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithStringVariables() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = ABCD," + credentialName1, "workerId = 1",
- "kinesisEndpoint = https://kinesis", "metricsLevel = SUMMARY" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD," + credentialName1,
+ "workerId = 1",
+ "kinesisEndpoint = https://kinesis",
+ "metricsLevel = SUMMARY"
+ },
+ '\n'));
assertEquals(config.getWorkerIdentifier(), "1");
assertEquals(config.getKinesisClient().get("endpointOverride"), URI.create("https://kinesis"));
@@ -177,38 +229,66 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithSetVariables() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = ABCD," + credentialName1, "workerId = 1",
- "metricsEnabledDimensions = ShardId, WorkerIdentifier" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD," + credentialName1,
+ "workerId = 1",
+ "metricsEnabledDimensions = ShardId, WorkerIdentifier"
+ },
+ '\n'));
- Set expectedMetricsEnabledDimensions = ImmutableSet. builder()
- .add("ShardId", "WorkerIdentifier").build();
- assertThat(new HashSet<>(Arrays.asList(config.getMetricsEnabledDimensions())), equalTo(expectedMetricsEnabledDimensions));
+ Set expectedMetricsEnabledDimensions = ImmutableSet.builder()
+ .add("ShardId", "WorkerIdentifier")
+ .build();
+ assertThat(
+ new HashSet<>(Arrays.asList(config.getMetricsEnabledDimensions())),
+ equalTo(expectedMetricsEnabledDimensions));
}
@Test
public void testWithInitialPositionInStreamTrimHorizon() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = ABCD," + credentialName1, "workerId = 123",
- "initialPositionInStream = TriM_Horizon" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD," + credentialName1,
+ "workerId = 123",
+ "initialPositionInStream = TriM_Horizon"
+ },
+ '\n'));
assertEquals(config.getInitialPositionInStream(), InitialPositionInStream.TRIM_HORIZON);
}
@Test
public void testWithInitialPositionInStreamLatest() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = ABCD," + credentialName1, "workerId = 123",
- "initialPositionInStream = LateSt" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD," + credentialName1,
+ "workerId = 123",
+ "initialPositionInStream = LateSt"
+ },
+ '\n'));
assertEquals(config.getInitialPositionInStream(), InitialPositionInStream.LATEST);
}
@Test
public void testSkippingNonKCLVariables() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = ABCD," + credentialName1, "workerId = 123",
- "initialPositionInStream = TriM_Horizon", "abc = 1" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD," + credentialName1,
+ "workerId = 123",
+ "initialPositionInStream = TriM_Horizon",
+ "abc = 1"
+ },
+ '\n'));
assertEquals(config.getApplicationName(), "b");
assertEquals(config.getStreamName(), "a");
@@ -218,33 +298,61 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testEmptyOptionalVariables() {
- MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(new String[] { "streamName = a",
- "applicationName = b", "AWSCredentialsProvider = ABCD," + credentialName1, "workerId = 123",
- "initialPositionInStream = TriM_Horizon", "maxGetRecordsThreadPool = 1" }, '\n'));
+ MultiLangDaemonConfiguration config = getConfiguration(StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD," + credentialName1,
+ "workerId = 123",
+ "initialPositionInStream = TriM_Horizon",
+ "maxGetRecordsThreadPool = 1"
+ },
+ '\n'));
assertThat(config.getMaxGetRecordsThreadPool(), equalTo(1));
assertThat(config.getRetryGetRecordsInSeconds(), nullValue());
}
@Test
public void testWithZeroValue() {
- String test = StringUtils.join(new String[] { "streamName = a", "applicationName = b",
- "AWSCredentialsProvider = ABCD," + credentialName1, "workerId = 123",
- "initialPositionInStream = TriM_Horizon", "maxGetRecordsThreadPool = 0",
- "retryGetRecordsInSeconds = 0" }, '\n');
+ String test = StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = ABCD," + credentialName1,
+ "workerId = 123",
+ "initialPositionInStream = TriM_Horizon",
+ "maxGetRecordsThreadPool = 0",
+ "retryGetRecordsInSeconds = 0"
+ },
+ '\n');
getConfiguration(test);
}
@Test
public void testWithInvalidIntValue() {
- String test = StringUtils.join(new String[] { "streamName = a", "applicationName = b",
- "AWSCredentialsProvider = " + credentialName1, "workerId = 123", "failoverTimeMillis = 100nf" }, '\n');
+ String test = StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialName1,
+ "workerId = 123",
+ "failoverTimeMillis = 100nf"
+ },
+ '\n');
getConfiguration(test);
}
@Test
public void testWithNegativeIntValue() {
- String test = StringUtils.join(new String[] { "streamName = a", "applicationName = b",
- "AWSCredentialsProvider = " + credentialName1, "workerId = 123", "failoverTimeMillis = -12" }, '\n');
+ String test = StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialName1,
+ "workerId = 123",
+ "failoverTimeMillis = -12"
+ },
+ '\n');
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
getConfiguration(test);
@@ -252,8 +360,15 @@ public class KinesisClientLibConfiguratorTest {
@Test(expected = IllegalArgumentException.class)
public void testWithMissingCredentialsProvider() {
- String test = StringUtils.join(new String[] { "streamName = a", "applicationName = b", "workerId = 123",
- "failoverTimeMillis = 100", "shardSyncIntervalMillis = 500" }, '\n');
+ String test = StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "workerId = 123",
+ "failoverTimeMillis = 100",
+ "shardSyncIntervalMillis = 500"
+ },
+ '\n');
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
getConfiguration(test);
@@ -262,8 +377,13 @@ public class KinesisClientLibConfiguratorTest {
@Test
public void testWithMissingWorkerId() {
String test = StringUtils.join(
- new String[] { "streamName = a", "applicationName = b", "AWSCredentialsProvider = " + credentialName1,
- "failoverTimeMillis = 100", "shardSyncIntervalMillis = 500" },
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialName1,
+ "failoverTimeMillis = 100",
+ "shardSyncIntervalMillis = 500"
+ },
'\n');
MultiLangDaemonConfiguration config = getConfiguration(test);
@@ -274,46 +394,63 @@ public class KinesisClientLibConfiguratorTest {
@Test(expected = NullPointerException.class)
public void testWithMissingStreamNameAndMissingStreamArn() {
- String test = StringUtils.join(new String[] {
- "applicationName = b",
- "AWSCredentialsProvider = " + credentialName1,
- "workerId = 123",
- "failoverTimeMillis = 100" },
+ String test = StringUtils.join(
+ new String[] {
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialName1,
+ "workerId = 123",
+ "failoverTimeMillis = 100"
+ },
'\n');
getConfiguration(test);
}
@Test(expected = IllegalArgumentException.class)
public void testWithEmptyStreamNameAndMissingStreamArn() {
- String test = StringUtils.join(new String[] {
- "applicationName = b",
- "AWSCredentialsProvider = " + credentialName1,
- "workerId = 123",
- "failoverTimeMillis = 100",
- "streamName = ",
- "streamArn = "},
+ String test = StringUtils.join(
+ new String[] {
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialName1,
+ "workerId = 123",
+ "failoverTimeMillis = 100",
+ "streamName = ",
+ "streamArn = "
+ },
'\n');
getConfiguration(test);
}
@Test(expected = NullPointerException.class)
public void testWithMissingApplicationName() {
- String test = StringUtils.join(new String[] { "streamName = a", "AWSCredentialsProvider = " + credentialName1,
- "workerId = 123", "failoverTimeMillis = 100" }, '\n');
+ String test = StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "AWSCredentialsProvider = " + credentialName1,
+ "workerId = 123",
+ "failoverTimeMillis = 100"
+ },
+ '\n');
getConfiguration(test);
}
@Test
public void testWithAWSCredentialsFailed() {
String test = StringUtils.join(
- new String[] { "streamName = a", "applicationName = b", "AWSCredentialsProvider = " + credentialName2,
- "failoverTimeMillis = 100", "shardSyncIntervalMillis = 500" },
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialName2,
+ "failoverTimeMillis = 100",
+ "shardSyncIntervalMillis = 500"
+ },
'\n');
MultiLangDaemonConfiguration config = getConfiguration(test);
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
try {
- config.getKinesisCredentialsProvider().build(AwsCredentialsProvider.class).resolveCredentials();
+ config.getKinesisCredentialsProvider()
+ .build(AwsCredentialsProvider.class)
+ .resolveCredentials();
fail("expect failure with wrong credentials provider");
} catch (Exception e) {
// succeed
@@ -323,39 +460,63 @@ public class KinesisClientLibConfiguratorTest {
// TODO: fix this test
@Test
public void testWithDifferentAWSCredentialsForDynamoDBAndCloudWatch() {
- String test = StringUtils.join(new String[] { "streamName = a", "applicationName = b",
- "AWSCredentialsProvider = " + credentialNameKinesis,
- "AWSCredentialsProviderDynamoDB = " + credentialNameDynamoDB,
- "AWSCredentialsProviderCloudWatch = " + credentialNameCloudWatch, "failoverTimeMillis = 100",
- "shardSyncIntervalMillis = 500" }, '\n');
+ String test = StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialNameKinesis,
+ "AWSCredentialsProviderDynamoDB = " + credentialNameDynamoDB,
+ "AWSCredentialsProviderCloudWatch = " + credentialNameCloudWatch,
+ "failoverTimeMillis = 100",
+ "shardSyncIntervalMillis = 500"
+ },
+ '\n');
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
final MultiLangDaemonConfiguration config = getConfiguration(test);
- config.getKinesisCredentialsProvider().build(AwsCredentialsProvider.class).resolveCredentials();
- config.getDynamoDBCredentialsProvider().build(AwsCredentialsProvider.class).resolveCredentials();
- config.getCloudWatchCredentialsProvider().build(AwsCredentialsProvider.class).resolveCredentials();
+ config.getKinesisCredentialsProvider()
+ .build(AwsCredentialsProvider.class)
+ .resolveCredentials();
+ config.getDynamoDBCredentialsProvider()
+ .build(AwsCredentialsProvider.class)
+ .resolveCredentials();
+ config.getCloudWatchCredentialsProvider()
+ .build(AwsCredentialsProvider.class)
+ .resolveCredentials();
}
// TODO: fix this test
@Test
public void testWithDifferentAWSCredentialsForDynamoDBAndCloudWatchFailed() {
- String test = StringUtils.join(new String[] { "streamName = a", "applicationName = b",
- "AWSCredentialsProvider = " + credentialNameKinesis,
- "AWSCredentialsProviderDynamoDB = " + credentialName2,
- "AWSCredentialsProviderCloudWatch = " + credentialName2, "failoverTimeMillis = 100",
- "shardSyncIntervalMillis = 500" }, '\n');
+ String test = StringUtils.join(
+ new String[] {
+ "streamName = a",
+ "applicationName = b",
+ "AWSCredentialsProvider = " + credentialNameKinesis,
+ "AWSCredentialsProviderDynamoDB = " + credentialName2,
+ "AWSCredentialsProviderCloudWatch = " + credentialName2,
+ "failoverTimeMillis = 100",
+ "shardSyncIntervalMillis = 500"
+ },
+ '\n');
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
final MultiLangDaemonConfiguration config = getConfiguration(test);
- config.getKinesisCredentialsProvider().build(AwsCredentialsProvider.class).resolveCredentials();
+ config.getKinesisCredentialsProvider()
+ .build(AwsCredentialsProvider.class)
+ .resolveCredentials();
try {
- config.getDynamoDBCredentialsProvider().build(AwsCredentialsProvider.class).resolveCredentials();
+ config.getDynamoDBCredentialsProvider()
+ .build(AwsCredentialsProvider.class)
+ .resolveCredentials();
fail("DynamoDB credential providers should fail.");
} catch (Exception e) {
// succeed
}
try {
- config.getCloudWatchCredentialsProvider().build(AwsCredentialsProvider.class).resolveCredentials();
+ config.getCloudWatchCredentialsProvider()
+ .build(AwsCredentialsProvider.class)
+ .resolveCredentials();
fail("CloudWatch credential providers should fail.");
} catch (Exception e) {
// succeed
@@ -373,9 +534,7 @@ public class KinesisClientLibConfiguratorTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
/**
@@ -389,9 +548,7 @@ public class KinesisClientLibConfiguratorTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
/**
@@ -405,9 +562,7 @@ public class KinesisClientLibConfiguratorTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
/**
@@ -421,9 +576,7 @@ public class KinesisClientLibConfiguratorTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
/**
@@ -437,13 +590,11 @@ public class KinesisClientLibConfiguratorTest {
}
@Override
- public void refresh() {
-
- }
+ public void refresh() {}
}
private MultiLangDaemonConfiguration getConfiguration(String configString) {
InputStream input = new ByteArrayInputStream(configString.getBytes());
return configurator.getConfiguration(input);
}
-}
\ No newline at end of file
+}
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java
index da18e659..b98db83a 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java
@@ -15,12 +15,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 static org.junit.Assert.assertTrue;
-
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtilsBean;
import org.junit.After;
@@ -31,12 +25,17 @@ import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.kinesis.processor.ShardRecordProcessorFactory;
import software.amazon.kinesis.retrieval.fanout.FanOutConfig;
import software.amazon.kinesis.retrieval.polling.PollingConfig;
+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 static org.junit.Assert.assertTrue;
+
@RunWith(MockitoJUnitRunner.class)
public class MultiLangDaemonConfigurationTest {
@@ -69,7 +68,6 @@ public class MultiLangDaemonConfigurationTest {
}
}
-
public MultiLangDaemonConfiguration baseConfiguration() {
MultiLangDaemonConfiguration configuration = new MultiLangDaemonConfiguration(utilsBean, convertUtilsBean);
configuration.setApplicationName("Test");
@@ -84,8 +82,8 @@ public class MultiLangDaemonConfigurationTest {
MultiLangDaemonConfiguration configuration = baseConfiguration();
configuration.setMaxLeasesForWorker(10);
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
assertThat(resolvedConfiguration.leaseManagementConfig.maxLeasesForWorker(), equalTo(10));
}
@@ -95,8 +93,8 @@ public class MultiLangDaemonConfigurationTest {
MultiLangDaemonConfiguration configuration = baseConfiguration();
configuration.setEnablePriorityLeaseAssignment(false);
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration.resolvedConfiguration(
- shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
assertThat(resolvedConfiguration.leaseManagementConfig.enablePriorityLeaseAssignment(), equalTo(false));
}
@@ -105,11 +103,11 @@ public class MultiLangDaemonConfigurationTest {
public void testDefaultRetrievalConfig() {
MultiLangDaemonConfiguration configuration = baseConfiguration();
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
- assertThat(resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(),
- instanceOf(FanOutConfig.class));
+ assertThat(
+ resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(), instanceOf(FanOutConfig.class));
}
@Test
@@ -118,18 +116,20 @@ public class MultiLangDaemonConfigurationTest {
configuration.setMaxRecords(10);
configuration.setIdleTimeBetweenReadsInMillis(60000);
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
- assertThat(resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(),
- instanceOf(PollingConfig.class));
- assertEquals(10,
- ((PollingConfig) resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig()).maxRecords());
- assertEquals(60000,
- ((PollingConfig) resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig())
- .idleTimeBetweenReadsInMillis());
+ assertThat(
+ resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(), instanceOf(PollingConfig.class));
+ assertEquals(
+ 10,
+ ((PollingConfig) resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig()).maxRecords());
+ assertEquals(
+ 60000,
+ ((PollingConfig) resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig())
+ .idleTimeBetweenReadsInMillis());
assertTrue(((PollingConfig) resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig())
- .usePollingConfigIdleTimeValue());
+ .usePollingConfigIdleTimeValue());
}
@Test
@@ -137,11 +137,11 @@ public class MultiLangDaemonConfigurationTest {
MultiLangDaemonConfiguration configuration = baseConfiguration();
configuration.setRetrievalMode(RetrievalMode.FANOUT);
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
- assertThat(resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(),
- instanceOf(FanOutConfig.class));
+ assertThat(
+ resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(), instanceOf(FanOutConfig.class));
}
@Test
@@ -149,37 +149,39 @@ public class MultiLangDaemonConfigurationTest {
MultiLangDaemonConfiguration configuration = baseConfiguration();
configuration.setRetrievalMode(RetrievalMode.POLLING);
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
- assertThat(resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(),
- instanceOf(PollingConfig.class));
+ assertThat(
+ resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(), instanceOf(PollingConfig.class));
}
@Test
public void testRetrievalModeSetForPollingString() throws Exception {
MultiLangDaemonConfiguration configuration = baseConfiguration();
- utilsBean.setProperty(configuration, "retrievalMode", RetrievalMode.POLLING.name().toLowerCase());
+ utilsBean.setProperty(
+ configuration, "retrievalMode", RetrievalMode.POLLING.name().toLowerCase());
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
- assertThat(resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(),
- instanceOf(PollingConfig.class));
+ assertThat(
+ resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(), instanceOf(PollingConfig.class));
}
@Test
public void testRetrievalModeSetForFanoutString() throws Exception {
MultiLangDaemonConfiguration configuration = baseConfiguration();
- utilsBean.setProperty(configuration, "retrievalMode", RetrievalMode.FANOUT.name().toLowerCase());
+ utilsBean.setProperty(
+ configuration, "retrievalMode", RetrievalMode.FANOUT.name().toLowerCase());
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
- assertThat(resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(),
- instanceOf(FanOutConfig.class));
+ assertThat(
+ resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(), instanceOf(FanOutConfig.class));
}
@Test
@@ -196,7 +198,7 @@ public class MultiLangDaemonConfigurationTest {
// TODO : Enable this test once https://github.com/awslabs/amazon-kinesis-client/issues/692 is resolved
public void testmetricsEnabledDimensions() {
MultiLangDaemonConfiguration configuration = baseConfiguration();
- configuration.setMetricsEnabledDimensions(new String[]{"Operation"});
+ configuration.setMetricsEnabledDimensions(new String[] {"Operation"});
configuration.resolvedConfiguration(shardRecordProcessorFactory);
}
@@ -209,14 +211,14 @@ public class MultiLangDaemonConfigurationTest {
configuration.setRetrievalMode(RetrievalMode.FANOUT);
configuration.getFanoutConfig().setConsumerArn(consumerArn);
- MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = configuration
- .resolvedConfiguration(shardRecordProcessorFactory);
+ MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration =
+ configuration.resolvedConfiguration(shardRecordProcessorFactory);
- assertThat(resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(),
- instanceOf(FanOutConfig.class));
- FanOutConfig fanOutConfig = (FanOutConfig) resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig();
+ assertThat(
+ resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig(), instanceOf(FanOutConfig.class));
+ FanOutConfig fanOutConfig =
+ (FanOutConfig) resolvedConfiguration.getRetrievalConfig().retrievalSpecificConfig();
assertThat(fanOutConfig.consumerArn(), equalTo(consumerArn));
}
-
-}
\ No newline at end of file
+}
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/PollingConfigBeanTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/PollingConfigBeanTest.java
index 2d032728..576e6101 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/PollingConfigBeanTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/PollingConfigBeanTest.java
@@ -15,6 +15,8 @@
package software.amazon.kinesis.multilang.config;
+import java.util.Optional;
+
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtilsBean;
import org.junit.Test;
@@ -24,8 +26,6 @@ import org.mockito.runners.MockitoJUnitRunner;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
import software.amazon.kinesis.retrieval.polling.PollingConfig;
-import java.util.Optional;
-
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
@@ -46,17 +46,23 @@ public class PollingConfigBeanTest {
ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean();
BeanUtilsBean utilsBean = new BeanUtilsBean(convertUtilsBean);
- MultiLangDaemonConfiguration multiLangDaemonConfiguration = new MultiLangDaemonConfiguration(utilsBean, convertUtilsBean);
+ MultiLangDaemonConfiguration multiLangDaemonConfiguration =
+ new MultiLangDaemonConfiguration(utilsBean, convertUtilsBean);
multiLangDaemonConfiguration.setStreamName("test-stream");
PollingConfig pollingConfig = pollingConfigBean.build(kinesisAsyncClient, multiLangDaemonConfiguration);
assertThat(pollingConfig.kinesisClient(), equalTo(kinesisAsyncClient));
assertThat(pollingConfig.streamName(), equalTo(multiLangDaemonConfiguration.getStreamName()));
- assertThat(pollingConfig.idleTimeBetweenReadsInMillis(), equalTo(pollingConfigBean.getIdleTimeBetweenReadsInMillis()));
- assertThat(pollingConfig.maxGetRecordsThreadPool(), equalTo(Optional.of(pollingConfigBean.getMaxGetRecordsThreadPool())));
+ assertThat(
+ pollingConfig.idleTimeBetweenReadsInMillis(),
+ equalTo(pollingConfigBean.getIdleTimeBetweenReadsInMillis()));
+ assertThat(
+ pollingConfig.maxGetRecordsThreadPool(),
+ equalTo(Optional.of(pollingConfigBean.getMaxGetRecordsThreadPool())));
assertThat(pollingConfig.maxRecords(), equalTo(pollingConfigBean.getMaxRecords()));
- assertThat(pollingConfig.retryGetRecordsInSeconds(), equalTo(Optional.of(pollingConfigBean.getRetryGetRecordsInSeconds())));
+ assertThat(
+ pollingConfig.retryGetRecordsInSeconds(),
+ equalTo(Optional.of(pollingConfigBean.getRetryGetRecordsInSeconds())));
}
-
-}
\ No newline at end of file
+}
diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecordTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecordTest.java
index 4aabfb33..b817da05 100644
--- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecordTest.java
+++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/messages/JsonFriendlyRecordTest.java
@@ -15,11 +15,6 @@
package software.amazon.kinesis.multilang.messages;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.junit.Assert.assertThat;
-
import java.nio.ByteBuffer;
import java.time.Instant;
import java.util.Arrays;
@@ -31,9 +26,13 @@ import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.Test;
-
import software.amazon.kinesis.retrieval.KinesisClientRecord;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.CoreMatchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
public class JsonFriendlyRecordTest {
private KinesisClientRecord kinesisClientRecord;
@@ -48,7 +47,7 @@ public class JsonFriendlyRecordTest {
@Test
public void testRecordHandlesNoByteArrayBuffer() {
- byte[] expected = new byte[] { 1, 2, 3, 4 };
+ byte[] expected = new byte[] {1, 2, 3, 4};
ByteBuffer expectedBuffer = ByteBuffer.allocateDirect(expected.length);
@@ -64,7 +63,7 @@ public class JsonFriendlyRecordTest {
@Test
public void testRecordHandlesArrayByteBuffer() {
- ByteBuffer expected = ByteBuffer.wrap(new byte[] { 1, 2, 3, 4 });
+ ByteBuffer expected = ByteBuffer.wrap(new byte[] {1, 2, 3, 4});
kinesisClientRecord = defaultRecord().data(expected).build();
JsonFriendlyRecord jsonFriendlyRecord = JsonFriendlyRecord.fromKinesisClientRecord(kinesisClientRecord);
@@ -82,14 +81,15 @@ public class JsonFriendlyRecordTest {
private RecordMatcher(KinesisClientRecord expected) {
this.matchers = Arrays.asList(
- new FieldMatcher<>("approximateArrivalTimestamp",
+ new FieldMatcher<>(
+ "approximateArrivalTimestamp",
equalTo(expected.approximateArrivalTimestamp().toEpochMilli()),
JsonFriendlyRecord::getApproximateArrivalTimestamp),
new FieldMatcher<>("partitionKey", expected::partitionKey, JsonFriendlyRecord::getPartitionKey),
- new FieldMatcher<>("sequenceNumber", expected::sequenceNumber,
- JsonFriendlyRecord::getSequenceNumber),
- new FieldMatcher<>("subSequenceNumber", expected::subSequenceNumber,
- JsonFriendlyRecord::getSubSequenceNumber),
+ new FieldMatcher<>(
+ "sequenceNumber", expected::sequenceNumber, JsonFriendlyRecord::getSequenceNumber),
+ new FieldMatcher<>(
+ "subSequenceNumber", expected::subSequenceNumber, JsonFriendlyRecord::getSubSequenceNumber),
new FieldMatcher<>("data", dataEquivalentTo(expected.data()), JsonFriendlyRecord::getData));
this.expected = expected;
@@ -97,13 +97,16 @@ public class JsonFriendlyRecordTest {
@Override
protected boolean matchesSafely(JsonFriendlyRecord item, Description mismatchDescription) {
- return matchers.stream().map(m -> {
- if (!m.matches(item)) {
- m.describeMismatch(item, mismatchDescription);
- return false;
- }
- return true;
- }).reduce((l, r) -> l && r).orElse(true);
+ return matchers.stream()
+ .map(m -> {
+ if (!m.matches(item)) {
+ m.describeMismatch(item, mismatchDescription);
+ return false;
+ }
+ return true;
+ })
+ .reduce((l, r) -> l && r)
+ .orElse(true);
}
@Override
@@ -160,8 +163,9 @@ public class JsonFriendlyRecordTest {
}
private KinesisClientRecord.KinesisClientRecordBuilder defaultRecord() {
- return KinesisClientRecord.builder().partitionKey("test-partition").sequenceNumber("123")
+ return KinesisClientRecord.builder()
+ .partitionKey("test-partition")
+ .sequenceNumber("123")
.approximateArrivalTimestamp(Instant.now());
}
-
-}
\ 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 62e5a741..adbd17fa 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
@@ -17,66 +17,65 @@ package software.amazon.kinesis.multilang.messages;
import java.nio.ByteBuffer;
import java.util.Collections;
-import org.junit.Assert;
-import org.junit.Test;
-
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-
+import org.junit.Assert;
+import org.junit.Test;
+import software.amazon.kinesis.lifecycle.ShutdownReason;
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;
public class MessageTest {
@Test
public void toStringTest() {
- Message[] messages = new Message[]{
- new CheckpointMessage("1234567890", 0L, null),
- new InitializeMessage(InitializationInput.builder().shardId("shard-123").build()),
- new ProcessRecordsMessage(ProcessRecordsInput.builder()
- .records(Collections.singletonList(
- KinesisClientRecord.builder()
- .data(ByteBuffer.wrap("cat".getBytes()))
- .partitionKey("cat")
- .sequenceNumber("555")
- .build()))
- .build()),
- new ShutdownMessage(ShutdownReason.LEASE_LOST),
- new StatusMessage("processRecords"),
- new InitializeMessage(),
- new ProcessRecordsMessage(),
- new ShutdownRequestedMessage(),
- new LeaseLostMessage(),
- new ShardEndedMessage(),
+ Message[] messages = new Message[] {
+ new CheckpointMessage("1234567890", 0L, null),
+ new InitializeMessage(
+ InitializationInput.builder().shardId("shard-123").build()),
+ new ProcessRecordsMessage(ProcessRecordsInput.builder()
+ .records(Collections.singletonList(KinesisClientRecord.builder()
+ .data(ByteBuffer.wrap("cat".getBytes()))
+ .partitionKey("cat")
+ .sequenceNumber("555")
+ .build()))
+ .build()),
+ new ShutdownMessage(ShutdownReason.LEASE_LOST),
+ new StatusMessage("processRecords"),
+ new InitializeMessage(),
+ new ProcessRecordsMessage(),
+ new ShutdownRequestedMessage(),
+ new LeaseLostMessage(),
+ new ShardEndedMessage(),
};
-// TODO: fix this
+ // TODO: fix this
for (int i = 0; i < messages.length; i++) {
System.out.println(messages[i].toString());
- Assert.assertTrue("Each message should contain the action field", messages[i].toString().contains("action"));
+ Assert.assertTrue(
+ "Each message should contain the action field",
+ messages[i].toString().contains("action"));
}
// Hit this constructor
- KinesisClientRecord defaultJsonFriendlyRecord = KinesisClientRecord.builder().build();
+ KinesisClientRecord defaultJsonFriendlyRecord =
+ KinesisClientRecord.builder().build();
Assert.assertNull(defaultJsonFriendlyRecord.partitionKey());
Assert.assertNull(defaultJsonFriendlyRecord.data());
Assert.assertNull(defaultJsonFriendlyRecord.sequenceNumber());
Assert.assertNull(new ShutdownMessage(null).getReason());
// Hit the bad object mapping path
- Message withBadMapper = new Message() {
- }.withObjectMapper(new ObjectMapper() {
+ Message withBadMapper = new Message() {}.withObjectMapper(new ObjectMapper() {
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
@Override
public String writeValueAsString(Object m) throws JsonProcessingException {
- throw new JsonProcessingException(new Throwable()) {
- };
+ throw new JsonProcessingException(new Throwable()) {};
}
});
String s = withBadMapper.toString();
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/annotations/KinesisClientInternalApi.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/annotations/KinesisClientInternalApi.java
index be137383..e10583e8 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/annotations/KinesisClientInternalApi.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/annotations/KinesisClientInternalApi.java
@@ -22,5 +22,4 @@ import java.lang.annotation.RetentionPolicy;
* Any class/method/variable marked with this annotation is subject to breaking changes between minor releases.
*/
@Retention(RetentionPolicy.CLASS)
-public @interface KinesisClientInternalApi {
-}
+public @interface KinesisClientInternalApi {}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/Checkpoint.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/Checkpoint.java
index f5af81e3..7b4de295 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/Checkpoint.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/Checkpoint.java
@@ -40,7 +40,10 @@ public class Checkpoint {
* @param pendingCheckpoint the pending checkpoint sequence number - can be null.
* @param pendingCheckpointState the pending checkpoint state - can be null.
*/
- public Checkpoint(final ExtendedSequenceNumber checkpoint, final ExtendedSequenceNumber pendingCheckpoint, byte[] pendingCheckpointState) {
+ public Checkpoint(
+ final ExtendedSequenceNumber checkpoint,
+ final ExtendedSequenceNumber pendingCheckpoint,
+ byte[] pendingCheckpointState) {
if (checkpoint == null || checkpoint.sequenceNumber().isEmpty()) {
throw new IllegalArgumentException("Checkpoint cannot be null or empty");
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/CheckpointConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/CheckpointConfig.java
index dbde3b5a..a76673ed 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/CheckpointConfig.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/CheckpointConfig.java
@@ -15,7 +15,6 @@
package software.amazon.kinesis.checkpoint;
-
import lombok.Data;
import lombok.experimental.Accessors;
import software.amazon.kinesis.checkpoint.dynamodb.DynamoDBCheckpointFactory;
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/DoesNothingPreparedCheckpointer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/DoesNothingPreparedCheckpointer.java
index 5a1e8168..2b8e547d 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/DoesNothingPreparedCheckpointer.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/DoesNothingPreparedCheckpointer.java
@@ -60,9 +60,7 @@ public class DoesNothingPreparedCheckpointer implements PreparedCheckpointer {
@Override
public void checkpoint()
throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
- IllegalArgumentException {
+ IllegalArgumentException {
// This method does nothing
}
-
}
-
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/SequenceNumberValidator.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/SequenceNumberValidator.java
index de5565bf..7b674ca4 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/SequenceNumberValidator.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/SequenceNumberValidator.java
@@ -20,10 +20,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import org.apache.commons.lang3.StringUtils;
-
import lombok.Data;
import lombok.experimental.Accessors;
+import org.apache.commons.lang3.StringUtils;
/**
* This supports extracting the shardId from a sequence number.
@@ -98,11 +97,15 @@ public class SequenceNumberValidator {
}
}
- private static final List SEQUENCE_NUMBER_READERS = Collections
- .singletonList(new V2SequenceNumberReader());
+ private static final List SEQUENCE_NUMBER_READERS =
+ Collections.singletonList(new V2SequenceNumberReader());
private Optional retrieveComponentsFor(String sequenceNumber) {
- return SEQUENCE_NUMBER_READERS.stream().map(r -> r.read(sequenceNumber)).filter(Optional::isPresent).map(Optional::get).findFirst();
+ return SEQUENCE_NUMBER_READERS.stream()
+ .map(r -> r.read(sequenceNumber))
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .findFirst();
}
/**
@@ -118,7 +121,7 @@ public class SequenceNumberValidator {
*
*
*
- *
+ *
* @param sequenceNumber
* the sequence number to extract the version from
* @return an Optional containing the version if a compatible sequence number reader can be found, an empty Optional
@@ -184,5 +187,4 @@ public class SequenceNumberValidator {
public Optional validateSequenceNumberForShard(String sequenceNumber, String shardId) {
return shardIdFor(sequenceNumber).map(s -> StringUtils.equalsIgnoreCase(s, shardId));
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardPreparedCheckpointer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardPreparedCheckpointer.java
index 63e13eaa..ea6bcaa3 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardPreparedCheckpointer.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/ShardPreparedCheckpointer.java
@@ -38,8 +38,8 @@ public class ShardPreparedCheckpointer implements PreparedCheckpointer {
* @param pendingCheckpointSequenceNumber sequence number to checkpoint at
* @param checkpointer checkpointer to use
*/
- public ShardPreparedCheckpointer(ExtendedSequenceNumber pendingCheckpointSequenceNumber,
- RecordProcessorCheckpointer checkpointer) {
+ public ShardPreparedCheckpointer(
+ ExtendedSequenceNumber pendingCheckpointSequenceNumber, RecordProcessorCheckpointer checkpointer) {
this.pendingCheckpointSequenceNumber = pendingCheckpointSequenceNumber;
this.checkpointer = checkpointer;
}
@@ -58,8 +58,8 @@ public class ShardPreparedCheckpointer implements PreparedCheckpointer {
@Override
public void checkpoint()
throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
- IllegalArgumentException {
- checkpointer.checkpoint(pendingCheckpointSequenceNumber.sequenceNumber(),
- pendingCheckpointSequenceNumber.subSequenceNumber());
+ IllegalArgumentException {
+ checkpointer.checkpoint(
+ pendingCheckpointSequenceNumber.sequenceNumber(), pendingCheckpointSequenceNumber.subSequenceNumber());
}
}
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 5fbac1d7..4de90d94 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
@@ -41,16 +41,22 @@ import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpointer {
@NonNull
private final ShardInfo shardInfo;
+
@NonNull
- @Getter @Accessors(fluent = true)
+ @Getter
+ @Accessors(fluent = true)
private final Checkpointer checkpointer;
// Set to the last value set via checkpoint().
// Sample use: verify application shutdown() invoked checkpoint() at the end of a shard.
- @Getter @Accessors(fluent = true)
+ @Getter
+ @Accessors(fluent = true)
private ExtendedSequenceNumber lastCheckpointValue;
- @Getter @Accessors(fluent = true)
+
+ @Getter
+ @Accessors(fluent = true)
private ExtendedSequenceNumber largestPermittedCheckpointValue;
+
private ExtendedSequenceNumber sequenceNumberAtShardEnd;
/**
@@ -60,8 +66,11 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
public synchronized void checkpoint()
throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
if (log.isDebugEnabled()) {
- log.debug("Checkpointing {}, token {} at largest permitted value {}", ShardInfo.getLeaseKey(shardInfo),
- shardInfo.concurrencyToken(), this.largestPermittedCheckpointValue);
+ log.debug(
+ "Checkpointing {}, token {} at largest permitted value {}",
+ ShardInfo.getLeaseKey(shardInfo),
+ shardInfo.concurrencyToken(),
+ this.largestPermittedCheckpointValue);
}
advancePosition(this.largestPermittedCheckpointValue);
}
@@ -71,15 +80,15 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
*/
@Override
public synchronized void checkpoint(Record record)
- throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
- IllegalArgumentException {
+ throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
+ IllegalArgumentException {
// TODO: UserRecord Deprecation
if (record == null) {
throw new IllegalArgumentException("Could not checkpoint a null record");
} /* else if (record instanceof UserRecord) {
- checkpoint(record.sequenceNumber(), ((UserRecord) record).subSequenceNumber());
- } */ else {
+ checkpoint(record.sequenceNumber(), ((UserRecord) record).subSequenceNumber());
+ } */ else {
checkpoint(record.sequenceNumber(), 0);
}
}
@@ -89,8 +98,8 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
*/
@Override
public synchronized void checkpoint(String sequenceNumber)
- throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
- IllegalArgumentException {
+ throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
+ IllegalArgumentException {
checkpoint(sequenceNumber, 0);
}
@@ -99,12 +108,12 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
*/
@Override
public synchronized void checkpoint(String sequenceNumber, long subSequenceNumber)
- throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
- IllegalArgumentException {
+ throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
+ IllegalArgumentException {
if (subSequenceNumber < 0) {
- throw new IllegalArgumentException("Could not checkpoint at invalid, negative subsequence number "
- + subSequenceNumber);
+ throw new IllegalArgumentException(
+ "Could not checkpoint at invalid, negative subsequence number " + subSequenceNumber);
}
/*
@@ -116,15 +125,18 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
&& newCheckpoint.compareTo(largestPermittedCheckpointValue) <= 0) {
if (log.isDebugEnabled()) {
- log.debug("Checkpointing {}, token {} at specific extended sequence number {}", ShardInfo.getLeaseKey(shardInfo),
- shardInfo.concurrencyToken(), newCheckpoint);
+ log.debug(
+ "Checkpointing {}, token {} at specific extended sequence number {}",
+ ShardInfo.getLeaseKey(shardInfo),
+ shardInfo.concurrencyToken(),
+ newCheckpoint);
}
this.advancePosition(newCheckpoint);
} else {
throw new IllegalArgumentException(String.format(
"Could not checkpoint at extended sequence number %s as it did not fall into acceptable range "
- + "between the last checkpoint %s and the greatest extended sequence number passed to this "
- + "record processor %s",
+ + "between the last checkpoint %s and the greatest extended sequence number passed to this "
+ + "record processor %s",
newCheckpoint, this.lastCheckpointValue, this.largestPermittedCheckpointValue));
}
}
@@ -161,8 +173,8 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
if (record == null) {
throw new IllegalArgumentException("Could not prepare checkpoint a null record");
} /*else if (record instanceof UserRecord) {
- return prepareCheckpoint(record.sequenceNumber(), ((UserRecord) record).subSequenceNumber());
- } */ else {
+ return prepareCheckpoint(record.sequenceNumber(), ((UserRecord) record).subSequenceNumber());
+ } */ else {
return prepareCheckpoint(record.sequenceNumber(), 0, applicationState);
}
}
@@ -190,7 +202,8 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
*/
@Override
public PreparedCheckpointer prepareCheckpoint(String sequenceNumber, byte[] applicationState)
- throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException, IllegalArgumentException {
+ throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException,
+ IllegalArgumentException {
return prepareCheckpoint(sequenceNumber, 0, applicationState);
}
@@ -207,11 +220,13 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
* {@inheritDoc}
*/
@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, InvalidStateException, ThrottlingException, ShutdownException,
+ IllegalArgumentException {
if (subSequenceNumber < 0) {
- throw new IllegalArgumentException("Could not checkpoint at invalid, negative subsequence number "
- + subSequenceNumber);
+ throw new IllegalArgumentException(
+ "Could not checkpoint at invalid, negative subsequence number " + subSequenceNumber);
}
/*
@@ -223,8 +238,11 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
&& pendingCheckpoint.compareTo(largestPermittedCheckpointValue) <= 0) {
if (log.isDebugEnabled()) {
- log.debug("Preparing checkpoint {}, token {} at specific extended sequence number {}",
- ShardInfo.getLeaseKey(shardInfo), shardInfo.concurrencyToken(), pendingCheckpoint);
+ log.debug(
+ "Preparing checkpoint {}, token {} at specific extended sequence number {}",
+ ShardInfo.getLeaseKey(shardInfo),
+ shardInfo.concurrencyToken(),
+ pendingCheckpoint);
}
return doPrepareCheckpoint(pendingCheckpoint, applicationState);
} else {
@@ -258,7 +276,6 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
this.sequenceNumberAtShardEnd = extendedSequenceNumber;
}
-
/**
* Internal API - has package level access only for testing purposes.
*
@@ -270,29 +287,35 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
* @throws InvalidStateException
*/
void advancePosition(String sequenceNumber)
- throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
+ throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
advancePosition(new ExtendedSequenceNumber(sequenceNumber));
}
void advancePosition(ExtendedSequenceNumber extendedSequenceNumber)
- throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
+ throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
ExtendedSequenceNumber checkpointToRecord = extendedSequenceNumber;
if (sequenceNumberAtShardEnd != null && sequenceNumberAtShardEnd.equals(extendedSequenceNumber)) {
// If we are about to checkpoint the very last sequence number for this shard, we might as well
// just checkpoint at SHARD_END
checkpointToRecord = ExtendedSequenceNumber.SHARD_END;
}
-
+
// Don't checkpoint a value we already successfully checkpointed
if (extendedSequenceNumber != null && !extendedSequenceNumber.equals(lastCheckpointValue)) {
try {
if (log.isDebugEnabled()) {
- log.debug("Setting {}, token {} checkpoint to {}", ShardInfo.getLeaseKey(shardInfo),
- shardInfo.concurrencyToken(), checkpointToRecord);
+ log.debug(
+ "Setting {}, token {} checkpoint to {}",
+ ShardInfo.getLeaseKey(shardInfo),
+ shardInfo.concurrencyToken(),
+ checkpointToRecord);
}
- checkpointer.setCheckpoint(ShardInfo.getLeaseKey(shardInfo), checkpointToRecord, shardInfo.concurrencyToken());
+ checkpointer.setCheckpoint(
+ ShardInfo.getLeaseKey(shardInfo), checkpointToRecord, shardInfo.concurrencyToken());
lastCheckpointValue = checkpointToRecord;
- } catch (ThrottlingException | ShutdownException | InvalidStateException
+ } catch (ThrottlingException
+ | ShutdownException
+ | InvalidStateException
| KinesisClientLibDependencyException e) {
throw e;
} catch (KinesisClientLibException e) {
@@ -325,7 +348,8 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
* @throws ThrottlingException
* @throws ShutdownException
*/
- private PreparedCheckpointer doPrepareCheckpoint(ExtendedSequenceNumber extendedSequenceNumber, byte[] applicationState)
+ private PreparedCheckpointer doPrepareCheckpoint(
+ ExtendedSequenceNumber extendedSequenceNumber, byte[] applicationState)
throws KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
ExtendedSequenceNumber newPrepareCheckpoint = extendedSequenceNumber;
@@ -343,8 +367,14 @@ public class ShardRecordProcessorCheckpointer implements RecordProcessorCheckpoi
}
try {
- checkpointer.prepareCheckpoint(ShardInfo.getLeaseKey(shardInfo), newPrepareCheckpoint, shardInfo.concurrencyToken(), applicationState);
- } catch (ThrottlingException | ShutdownException | InvalidStateException
+ checkpointer.prepareCheckpoint(
+ ShardInfo.getLeaseKey(shardInfo),
+ newPrepareCheckpoint,
+ shardInfo.concurrencyToken(),
+ applicationState);
+ } catch (ThrottlingException
+ | ShutdownException
+ | InvalidStateException
| KinesisClientLibDependencyException e) {
throw e;
} catch (KinesisClientLibException e) {
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointFactory.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointFactory.java
index d200de84..74caae9b 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointFactory.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/checkpoint/dynamodb/DynamoDBCheckpointFactory.java
@@ -29,9 +29,8 @@ import software.amazon.kinesis.processor.Checkpointer;
@KinesisClientInternalApi
public class DynamoDBCheckpointFactory implements CheckpointFactory {
@Override
- public Checkpointer createCheckpointer(final LeaseCoordinator leaseLeaseCoordinator,
- final LeaseRefresher leaseRefresher) {
+ public Checkpointer createCheckpointer(
+ final LeaseCoordinator leaseLeaseCoordinator, final LeaseRefresher leaseRefresher) {
return new DynamoDBCheckpointer(leaseLeaseCoordinator, leaseRefresher);
}
-
}
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 1aa258bb..0a6a9607 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
@@ -19,7 +19,6 @@ import java.util.Objects;
import java.util.UUID;
import com.google.common.annotations.VisibleForTesting;
-
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -48,14 +47,16 @@ import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
public class DynamoDBCheckpointer implements Checkpointer {
@NonNull
private final LeaseCoordinator leaseCoordinator;
+
@NonNull
private final LeaseRefresher leaseRefresher;
private String operation;
@Override
- public void setCheckpoint(final String leaseKey, final ExtendedSequenceNumber checkpointValue,
- final String concurrencyToken) throws KinesisClientLibException {
+ public void setCheckpoint(
+ final String leaseKey, final ExtendedSequenceNumber checkpointValue, final String concurrencyToken)
+ throws KinesisClientLibException {
try {
boolean wasSuccessful = setCheckpoint(leaseKey, checkpointValue, UUID.fromString(concurrencyToken));
if (!wasSuccessful) {
@@ -97,17 +98,22 @@ public class DynamoDBCheckpointer implements Checkpointer {
}
@Override
- public void prepareCheckpoint(final String leaseKey, final ExtendedSequenceNumber pendingCheckpoint,
- final String concurrencyToken) throws KinesisClientLibException {
+ public void prepareCheckpoint(
+ final String leaseKey, final ExtendedSequenceNumber pendingCheckpoint, final String concurrencyToken)
+ throws KinesisClientLibException {
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)
+ throws KinesisClientLibException {
try {
- boolean wasSuccessful =
- prepareCheckpoint(leaseKey, pendingCheckpoint, UUID.fromString(concurrencyToken), pendingCheckpointState);
+ boolean wasSuccessful = prepareCheckpoint(
+ leaseKey, pendingCheckpoint, UUID.fromString(concurrencyToken), pendingCheckpointState);
if (!wasSuccessful) {
throw new ShutdownException(
"Can't prepare checkpoint - instance doesn't hold the lease for this shard");
@@ -128,8 +134,10 @@ public class DynamoDBCheckpointer implements Checkpointer {
throws DependencyException, InvalidStateException, ProvisionedThroughputException {
Lease lease = leaseCoordinator.getCurrentlyHeldLease(leaseKey);
if (lease == null) {
- log.info("Worker {} could not update checkpoint for shard {} because it does not hold the lease",
- leaseCoordinator.workerIdentifier(), leaseKey);
+ log.info(
+ "Worker {} could not update checkpoint for shard {} because it does not hold the lease",
+ leaseCoordinator.workerIdentifier(),
+ leaseKey);
return false;
}
@@ -141,12 +149,18 @@ public class DynamoDBCheckpointer implements Checkpointer {
return leaseCoordinator.updateLease(lease, concurrencyToken, operation, leaseKey);
}
- boolean prepareCheckpoint(String leaseKey, ExtendedSequenceNumber pendingCheckpoint, UUID concurrencyToken, byte[] pendingCheckpointState)
+ boolean prepareCheckpoint(
+ String leaseKey,
+ ExtendedSequenceNumber pendingCheckpoint,
+ UUID concurrencyToken,
+ byte[] pendingCheckpointState)
throws DependencyException, InvalidStateException, ProvisionedThroughputException {
Lease lease = leaseCoordinator.getCurrentlyHeldLease(leaseKey);
if (lease == null) {
- log.info("Worker {} could not prepare checkpoint for shard {} because it does not hold the lease",
- leaseCoordinator.workerIdentifier(), leaseKey);
+ log.info(
+ "Worker {} could not prepare checkpoint for shard {} because it does not hold the lease",
+ leaseCoordinator.workerIdentifier(),
+ leaseKey);
return false;
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/CommonCalculations.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/CommonCalculations.java
index edb6de2e..d7f33c23 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/CommonCalculations.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/CommonCalculations.java
@@ -15,10 +15,8 @@
package software.amazon.kinesis.common;
-
public class CommonCalculations {
-
/**
* Convenience method for calculating renewer intervals in milliseconds.
*
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/ConfigsBuilder.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/ConfigsBuilder.java
index 02258950..2838d62d 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/ConfigsBuilder.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/ConfigsBuilder.java
@@ -19,12 +19,11 @@ import java.util.function.Function;
import lombok.EqualsAndHashCode;
import lombok.Getter;
+import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
-import org.apache.commons.lang3.StringUtils;
-
-import lombok.NonNull;
import lombok.experimental.Accessors;
+import org.apache.commons.lang3.StringUtils;
import software.amazon.awssdk.arns.Arn;
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
@@ -35,9 +34,9 @@ import software.amazon.kinesis.coordinator.CoordinatorConfig;
import software.amazon.kinesis.leases.LeaseManagementConfig;
import software.amazon.kinesis.lifecycle.LifecycleConfig;
import software.amazon.kinesis.metrics.MetricsConfig;
+import software.amazon.kinesis.processor.MultiStreamTracker;
import software.amazon.kinesis.processor.ProcessorConfig;
import software.amazon.kinesis.processor.ShardRecordProcessorFactory;
-import software.amazon.kinesis.processor.MultiStreamTracker;
import software.amazon.kinesis.processor.SingleStreamTracker;
import software.amazon.kinesis.processor.StreamTracker;
import software.amazon.kinesis.retrieval.RetrievalConfig;
@@ -45,7 +44,10 @@ import software.amazon.kinesis.retrieval.RetrievalConfig;
/**
* This Builder is useful to create all configurations for the KCL with default values.
*/
-@Getter @Setter @ToString @EqualsAndHashCode
+@Getter
+@Setter
+@ToString
+@EqualsAndHashCode
@Accessors(fluent = true)
public class ConfigsBuilder {
/**
@@ -139,11 +141,16 @@ public class ConfigsBuilder {
* @param workerIdentifier
* @param shardRecordProcessorFactory
*/
- public ConfigsBuilder(@NonNull String streamName, @NonNull String applicationName,
- @NonNull KinesisAsyncClient kinesisClient, @NonNull DynamoDbAsyncClient dynamoDBClient,
- @NonNull CloudWatchAsyncClient cloudWatchClient, @NonNull String workerIdentifier,
+ public ConfigsBuilder(
+ @NonNull String streamName,
+ @NonNull String applicationName,
+ @NonNull KinesisAsyncClient kinesisClient,
+ @NonNull DynamoDbAsyncClient dynamoDBClient,
+ @NonNull CloudWatchAsyncClient cloudWatchClient,
+ @NonNull String workerIdentifier,
@NonNull ShardRecordProcessorFactory shardRecordProcessorFactory) {
- this(new SingleStreamTracker(streamName),
+ this(
+ new SingleStreamTracker(streamName),
applicationName,
kinesisClient,
dynamoDBClient,
@@ -163,11 +170,16 @@ public class ConfigsBuilder {
* @param workerIdentifier
* @param shardRecordProcessorFactory
*/
- public ConfigsBuilder(@NonNull Arn streamArn, @NonNull String applicationName,
- @NonNull KinesisAsyncClient kinesisClient, @NonNull DynamoDbAsyncClient dynamoDBClient,
- @NonNull CloudWatchAsyncClient cloudWatchClient, @NonNull String workerIdentifier,
- @NonNull ShardRecordProcessorFactory shardRecordProcessorFactory) {
- this(new SingleStreamTracker(streamArn),
+ public ConfigsBuilder(
+ @NonNull Arn streamArn,
+ @NonNull String applicationName,
+ @NonNull KinesisAsyncClient kinesisClient,
+ @NonNull DynamoDbAsyncClient dynamoDBClient,
+ @NonNull CloudWatchAsyncClient cloudWatchClient,
+ @NonNull String workerIdentifier,
+ @NonNull ShardRecordProcessorFactory shardRecordProcessorFactory) {
+ this(
+ new SingleStreamTracker(streamArn),
applicationName,
kinesisClient,
dynamoDBClient,
@@ -187,9 +199,13 @@ public class ConfigsBuilder {
* @param workerIdentifier
* @param shardRecordProcessorFactory
*/
- public ConfigsBuilder(@NonNull StreamTracker streamTracker, @NonNull String applicationName,
- @NonNull KinesisAsyncClient kinesisClient, @NonNull DynamoDbAsyncClient dynamoDBClient,
- @NonNull CloudWatchAsyncClient cloudWatchClient, @NonNull String workerIdentifier,
+ public ConfigsBuilder(
+ @NonNull StreamTracker streamTracker,
+ @NonNull String applicationName,
+ @NonNull KinesisAsyncClient kinesisClient,
+ @NonNull DynamoDbAsyncClient dynamoDBClient,
+ @NonNull CloudWatchAsyncClient cloudWatchClient,
+ @NonNull String workerIdentifier,
@NonNull ShardRecordProcessorFactory shardRecordProcessorFactory) {
this.applicationName = applicationName;
this.kinesisClient = kinesisClient;
@@ -209,8 +225,11 @@ public class ConfigsBuilder {
public void streamTracker(StreamTracker streamTracker) {
this.streamTracker = streamTracker;
- this.appStreamTracker = DeprecationUtils.convert(streamTracker,
- singleStreamTracker -> singleStreamTracker.streamConfigList().get(0).streamIdentifier().streamName());
+ this.appStreamTracker = DeprecationUtils.convert(streamTracker, singleStreamTracker -> singleStreamTracker
+ .streamConfigList()
+ .get(0)
+ .streamIdentifier()
+ .streamName());
}
/**
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DeprecationUtils.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DeprecationUtils.java
index 5d8782e0..73ff0bff 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DeprecationUtils.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DeprecationUtils.java
@@ -39,8 +39,7 @@ public final class DeprecationUtils {
*/
@Deprecated
public static Either convert(
- StreamTracker streamTracker,
- Function converter) {
+ StreamTracker streamTracker, Function converter) {
if (streamTracker instanceof MultiStreamTracker) {
return Either.left((MultiStreamTracker) streamTracker);
} else if (streamTracker instanceof SingleStreamTracker) {
@@ -49,5 +48,4 @@ public final class DeprecationUtils {
throw new IllegalArgumentException("Unhandled StreamTracker: " + streamTracker);
}
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DiagnosticUtils.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DiagnosticUtils.java
index 37eea1a3..8178e4b4 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DiagnosticUtils.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/DiagnosticUtils.java
@@ -15,12 +15,12 @@
package software.amazon.kinesis.common;
-import org.slf4j.Logger;
-import software.amazon.kinesis.annotations.KinesisClientInternalApi;
-
import java.time.Duration;
import java.time.Instant;
+import org.slf4j.Logger;
+import software.amazon.kinesis.annotations.KinesisClientInternalApi;
+
import static software.amazon.kinesis.lifecycle.ShardConsumer.MAX_TIME_BETWEEN_REQUEST_RESPONSE;
@KinesisClientInternalApi
@@ -32,18 +32,22 @@ public class DiagnosticUtils {
* @param enqueueTimestamp of the event submitted to the executor service
* @param log Slf4j Logger from RecordPublisher to log the events
*/
- public static void takeDelayedDeliveryActionIfRequired(String resourceIdentifier, Instant enqueueTimestamp, Logger log) {
- final long durationBetweenEnqueueAndAckInMillis = Duration
- .between(enqueueTimestamp, Instant.now()).toMillis();
+ public static void takeDelayedDeliveryActionIfRequired(
+ String resourceIdentifier, Instant enqueueTimestamp, Logger log) {
+ final long durationBetweenEnqueueAndAckInMillis =
+ Duration.between(enqueueTimestamp, Instant.now()).toMillis();
if (durationBetweenEnqueueAndAckInMillis > MAX_TIME_BETWEEN_REQUEST_RESPONSE / 3) {
// The above condition logs the warn msg if the delivery time exceeds 11 seconds.
log.warn(
"{}: Record delivery time to shard consumer is high at {} millis. Check the ExecutorStateEvent logs"
+ " to see the state of the executor service. Also check if the RecordProcessor's processing "
+ "time is high. ",
- resourceIdentifier, durationBetweenEnqueueAndAckInMillis);
+ resourceIdentifier,
+ durationBetweenEnqueueAndAckInMillis);
} else if (log.isDebugEnabled()) {
- log.debug("{}: Record delivery time to shard consumer is {} millis", resourceIdentifier,
+ log.debug(
+ "{}: Record delivery time to shard consumer is {} millis",
+ resourceIdentifier,
durationBetweenEnqueueAndAckInMillis);
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/FutureUtils.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/FutureUtils.java
index 9410d6fd..3c104d8d 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/FutureUtils.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/FutureUtils.java
@@ -31,5 +31,4 @@ public class FutureUtils {
throw te;
}
}
-
}
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 30f8963a..8d52ec90 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
@@ -15,14 +15,14 @@
package software.amazon.kinesis.common;
+import java.math.BigInteger;
+
import lombok.NonNull;
import lombok.Value;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.Validate;
import software.amazon.awssdk.services.kinesis.model.HashKeyRange;
-import java.math.BigInteger;
-
/**
* Lease POJO to hold the starting hashkey range and ending hashkey range of kinesis shards.
*/
@@ -34,8 +34,11 @@ public class HashKeyRangeForLease {
private final BigInteger endingHashKey;
public HashKeyRangeForLease(BigInteger startingHashKey, BigInteger endingHashKey) {
- Validate.isTrue(startingHashKey.compareTo(endingHashKey) < 0,
- "StartingHashKey %s must be less than EndingHashKey %s ", startingHashKey, endingHashKey);
+ Validate.isTrue(
+ startingHashKey.compareTo(endingHashKey) < 0,
+ "StartingHashKey %s must be less than EndingHashKey %s ",
+ startingHashKey,
+ endingHashKey);
this.startingHashKey = startingHashKey;
this.endingHashKey = endingHashKey;
}
@@ -65,11 +68,15 @@ public class HashKeyRangeForLease {
* @param endingHashKeyStr
* @return HashKeyRangeForLease
*/
- public static HashKeyRangeForLease deserialize(@NonNull String startingHashKeyStr, @NonNull String endingHashKeyStr) {
+ public static HashKeyRangeForLease deserialize(
+ @NonNull String startingHashKeyStr, @NonNull String endingHashKeyStr) {
final BigInteger startingHashKey = new BigInteger(startingHashKeyStr);
final BigInteger endingHashKey = new BigInteger(endingHashKeyStr);
- Validate.isTrue(startingHashKey.compareTo(endingHashKey) < 0,
- "StartingHashKey %s must be less than EndingHashKey %s ", startingHashKeyStr, endingHashKeyStr);
+ Validate.isTrue(
+ startingHashKey.compareTo(endingHashKey) < 0,
+ "StartingHashKey %s must be less than EndingHashKey %s ",
+ startingHashKeyStr,
+ endingHashKeyStr);
return new HashKeyRangeForLease(startingHashKey, endingHashKey);
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/InitialPositionInStreamExtended.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/InitialPositionInStreamExtended.java
index b3bedd88..5c512933 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/InitialPositionInStreamExtended.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/InitialPositionInStreamExtended.java
@@ -14,16 +14,17 @@
*/
package software.amazon.kinesis.common;
+import java.util.Date;
+
import lombok.EqualsAndHashCode;
import lombok.ToString;
-import java.util.Date;
-
/**
* Class that houses the entities needed to specify the position in the stream from where a new application should
* start.
*/
-@ToString @EqualsAndHashCode
+@ToString
+@EqualsAndHashCode
public class InitialPositionInStreamExtended {
private final InitialPositionInStream position;
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisClientUtil.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisClientUtil.java
index 45bd88e2..c2f3ca7d 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisClientUtil.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisClientUtil.java
@@ -15,14 +15,14 @@
package software.amazon.kinesis.common;
+import java.time.Duration;
+
import software.amazon.awssdk.http.Protocol;
import software.amazon.awssdk.http.nio.netty.Http2Configuration;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
import software.amazon.awssdk.services.kinesis.KinesisAsyncClientBuilder;
-import java.time.Duration;
-
/**
* Utility to setup KinesisAsyncClient to be used with KCL.
*/
@@ -42,9 +42,12 @@ public class KinesisClientUtil {
}
public static KinesisAsyncClientBuilder adjustKinesisClientBuilder(KinesisAsyncClientBuilder builder) {
- return builder.httpClientBuilder(NettyNioAsyncHttpClient.builder().maxConcurrency(Integer.MAX_VALUE)
- .http2Configuration(Http2Configuration.builder().initialWindowSize(INITIAL_WINDOW_SIZE_BYTES)
- .healthCheckPingPeriod(Duration.ofMillis(HEALTH_CHECK_PING_PERIOD_MILLIS)).build())
+ return builder.httpClientBuilder(NettyNioAsyncHttpClient.builder()
+ .maxConcurrency(Integer.MAX_VALUE)
+ .http2Configuration(Http2Configuration.builder()
+ .initialWindowSize(INITIAL_WINDOW_SIZE_BYTES)
+ .healthCheckPingPeriod(Duration.ofMillis(HEALTH_CHECK_PING_PERIOD_MILLIS))
+ .build())
.protocol(Protocol.HTTP2));
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisRequestsBuilder.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisRequestsBuilder.java
index 52e16f3e..9ef43b8e 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisRequestsBuilder.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/KinesisRequestsBuilder.java
@@ -63,12 +63,11 @@ public class KinesisRequestsBuilder {
@SuppressWarnings("unchecked")
private static T appendUserAgent(final T builder) {
- return (T) builder
- .overrideConfiguration(
- AwsRequestOverrideConfiguration.builder()
- .addApiName(ApiName.builder().name(RetrievalConfig.KINESIS_CLIENT_LIB_USER_AGENT)
- .version(RetrievalConfig.KINESIS_CLIENT_LIB_USER_AGENT_VERSION).build())
+ return (T) builder.overrideConfiguration(AwsRequestOverrideConfiguration.builder()
+ .addApiName(ApiName.builder()
+ .name(RetrievalConfig.KINESIS_CLIENT_LIB_USER_AGENT)
+ .version(RetrievalConfig.KINESIS_CLIENT_LIB_USER_AGENT_VERSION)
+ .build())
.build());
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/LeaseCleanupConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/LeaseCleanupConfig.java
index b2582d45..6c29c76b 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/LeaseCleanupConfig.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/LeaseCleanupConfig.java
@@ -24,7 +24,7 @@ import lombok.experimental.Accessors;
*/
@Builder
@Getter
-@Accessors(fluent=true)
+@Accessors(fluent = true)
public class LeaseCleanupConfig {
/**
* Interval at which to run lease cleanup thread.
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/RequestDetails.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/RequestDetails.java
index 9f511123..108a12d4 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/RequestDetails.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/RequestDetails.java
@@ -15,11 +15,11 @@
package software.amazon.kinesis.common;
-import lombok.experimental.Accessors;
-
import java.util.Optional;
-@Accessors(fluent=true)
+import lombok.experimental.Accessors;
+
+@Accessors(fluent = true)
public class RequestDetails {
/**
@@ -62,6 +62,4 @@ public class RequestDetails {
public String toString() {
return String.format("request id - %s, timestamp - %s", getRequestId(), getTimestamp());
}
-
}
-
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamConfig.java
index 95ab0560..95772008 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamConfig.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/common/StreamConfig.java
@@ -28,8 +28,7 @@ import lombok.experimental.Accessors;
public class StreamConfig {
@NonNull
private final StreamIdentifier streamIdentifier;
+
private final InitialPositionInStreamExtended initialPositionInStreamExtended;
private String consumerArn;
}
-
-
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 82cef04b..2070a535 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
@@ -15,6 +15,10 @@
package software.amazon.kinesis.common;
+import java.util.Optional;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import lombok.AccessLevel;
import lombok.Builder;
import lombok.EqualsAndHashCode;
@@ -25,10 +29,6 @@ import software.amazon.awssdk.arns.Arn;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.utils.Validate;
-import java.util.Optional;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
@Builder(access = AccessLevel.PRIVATE)
@EqualsAndHashCode
@Getter
@@ -37,10 +37,13 @@ public class StreamIdentifier {
@Builder.Default
private final Optional accountIdOptional = Optional.empty();
+
@NonNull
private final String streamName;
+
@Builder.Default
private final Optional streamCreationEpochOptional = Optional.empty();
+
@Builder.Default
@EqualsAndHashCode.Exclude
private final Optional streamArnOptional = Optional.empty();
@@ -49,8 +52,8 @@ public class StreamIdentifier {
* Pattern for a serialized {@link StreamIdentifier}. The valid format is
* {@code ::}.
*/
- private static final Pattern STREAM_IDENTIFIER_PATTERN = Pattern.compile(
- "(?[0-9]+):(?[^:]+):(?[0-9]+)");
+ private static final Pattern STREAM_IDENTIFIER_PATTERN =
+ Pattern.compile("(?[0-9]+):(?[^:]+):(?[0-9]+)");
/**
* Pattern for a stream ARN. The valid format is
@@ -74,8 +77,10 @@ public class StreamIdentifier {
final char delimiter = ':';
final StringBuilder sb = new StringBuilder()
- .append(accountIdOptional.get()).append(delimiter)
- .append(streamName).append(delimiter)
+ .append(accountIdOptional.get())
+ .append(delimiter)
+ .append(streamName)
+ .append(delimiter)
.append(streamCreationEpochOptional.get());
return sb.toString();
}
@@ -146,9 +151,7 @@ public class StreamIdentifier {
public static StreamIdentifier singleStreamInstance(String streamName) {
Validate.notEmpty(streamName, "StreamName should not be empty");
- return StreamIdentifier.builder()
- .streamName(streamName)
- .build();
+ return StreamIdentifier.builder().streamName(streamName).build();
}
/**
@@ -173,7 +176,8 @@ public class StreamIdentifier {
* @param streamArn
*/
public static void validateArn(Arn streamArn) {
- if (!STREAM_ARN_PATTERN.matcher(streamArn.toString()).matches() || !streamArn.region().isPresent()) {
+ if (!STREAM_ARN_PATTERN.matcher(streamArn.toString()).matches()
+ || !streamArn.region().isPresent()) {
throw new IllegalArgumentException("Invalid streamArn " + streamArn);
}
}
@@ -185,9 +189,7 @@ public class StreamIdentifier {
*/
private static void validateCreationEpoch(long creationEpoch) {
if (creationEpoch <= 0) {
- throw new IllegalArgumentException(
- "Creation epoch must be > 0; received " + creationEpoch);
+ throw new IllegalArgumentException("Creation epoch must be > 0; received " + creationEpoch);
}
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/CoordinatorConfig.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/CoordinatorConfig.java
index d5c4dc13..e1835228 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/CoordinatorConfig.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/CoordinatorConfig.java
@@ -96,5 +96,4 @@ public class CoordinatorConfig {
* Default value: 1000L
*/
private long schedulerInitializationBackoffTimeMillis = 1000L;
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeletedStreamListProvider.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeletedStreamListProvider.java
index d0d332d9..d4057999 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeletedStreamListProvider.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeletedStreamListProvider.java
@@ -5,7 +5,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
-
import software.amazon.kinesis.common.StreamIdentifier;
/**
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDecider.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDecider.java
index b06dba39..4c7f25da 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDecider.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DeterministicShuffleShardSyncLeaderDecider.java
@@ -26,6 +26,7 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;
+
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.utils.CollectionUtils;
import software.amazon.kinesis.leases.Lease;
@@ -45,8 +46,7 @@ import software.amazon.kinesis.leases.exceptions.ProvisionedThroughputException;
* This ensures redundancy for shard-sync during host failures.
*/
@Slf4j
-class DeterministicShuffleShardSyncLeaderDecider
- implements LeaderDecider {
+class DeterministicShuffleShardSyncLeaderDecider implements LeaderDecider {
// Fixed seed so that the shuffle order is preserved across workers
static final int DETERMINISTIC_SHUFFLE_SEED = 1947;
@@ -67,13 +67,11 @@ class DeterministicShuffleShardSyncLeaderDecider
* @param leaderElectionThreadPool Thread-pool to be used for leaderElection.
* @param numPeriodicShardSyncWorkers Number of leaders that will be elected to perform periodic shard syncs.
*/
- DeterministicShuffleShardSyncLeaderDecider(LeaseRefresher leaseRefresher,
- ScheduledExecutorService leaderElectionThreadPool,
- int numPeriodicShardSyncWorkers) {
- this(leaseRefresher,
- leaderElectionThreadPool,
- numPeriodicShardSyncWorkers,
- new ReentrantReadWriteLock());
+ DeterministicShuffleShardSyncLeaderDecider(
+ LeaseRefresher leaseRefresher,
+ ScheduledExecutorService leaderElectionThreadPool,
+ int numPeriodicShardSyncWorkers) {
+ this(leaseRefresher, leaderElectionThreadPool, numPeriodicShardSyncWorkers, new ReentrantReadWriteLock());
}
/**
@@ -82,10 +80,11 @@ class DeterministicShuffleShardSyncLeaderDecider
* @param numPeriodicShardSyncWorkers Number of leaders that will be elected to perform periodic shard syncs.
* @param readWriteLock Mechanism to lock for reading and writing of critical components
*/
- DeterministicShuffleShardSyncLeaderDecider(LeaseRefresher leaseRefresher,
- ScheduledExecutorService leaderElectionThreadPool,
- int numPeriodicShardSyncWorkers,
- ReadWriteLock readWriteLock) {
+ DeterministicShuffleShardSyncLeaderDecider(
+ LeaseRefresher leaseRefresher,
+ ScheduledExecutorService leaderElectionThreadPool,
+ int numPeriodicShardSyncWorkers,
+ ReadWriteLock readWriteLock) {
this.leaseRefresher = leaseRefresher;
this.leaderElectionThreadPool = leaderElectionThreadPool;
this.numPeriodicShardSyncWorkers = numPeriodicShardSyncWorkers;
@@ -101,8 +100,12 @@ class DeterministicShuffleShardSyncLeaderDecider
try {
log.debug("Started leader election at: " + Instant.now());
List leases = leaseRefresher.listLeases();
- List uniqueHosts = leases.stream().map(Lease::leaseOwner)
- .filter(owner -> owner != null).distinct().sorted().collect(Collectors.toList());
+ List uniqueHosts = leases.stream()
+ .map(Lease::leaseOwner)
+ .filter(owner -> owner != null)
+ .distinct()
+ .sorted()
+ .collect(Collectors.toList());
Collections.shuffle(uniqueHosts, new Random(DETERMINISTIC_SHUFFLE_SEED));
int numShardSyncWorkers = Math.min(uniqueHosts.size(), numPeriodicShardSyncWorkers);
@@ -137,8 +140,11 @@ class DeterministicShuffleShardSyncLeaderDecider
// The first run will be after a minute.
// We don't need jitter since it is scheduled with a fixed delay and time taken to scan leases
// will be different at different times and on different hosts/workers.
- leaderElectionThreadPool.scheduleWithFixedDelay(this::electLeaders, ELECTION_INITIAL_DELAY_MILLIS,
- ELECTION_SCHEDULING_INTERVAL_MILLIS, TimeUnit.MILLISECONDS);
+ leaderElectionThreadPool.scheduleWithFixedDelay(
+ this::electLeaders,
+ ELECTION_INITIAL_DELAY_MILLIS,
+ ELECTION_SCHEDULING_INTERVAL_MILLIS,
+ TimeUnit.MILLISECONDS);
}
return executeConditionCheckWithReadLock(() -> isWorkerLeaderForShardSync(workerId));
@@ -152,7 +158,8 @@ class DeterministicShuffleShardSyncLeaderDecider
log.info("Successfully stopped leader election on the worker");
} else {
leaderElectionThreadPool.shutdownNow();
- log.info(String.format("Stopped leader election thread after awaiting termination for %d milliseconds",
+ log.info(String.format(
+ "Stopped leader election thread after awaiting termination for %d milliseconds",
AWAIT_TERMINATION_MILLIS));
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEventFactory.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEventFactory.java
index 316313aa..8fe61a94 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEventFactory.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEventFactory.java
@@ -15,11 +15,11 @@
package software.amazon.kinesis.coordinator;
+import java.util.concurrent.ExecutorService;
+
import lombok.NoArgsConstructor;
import software.amazon.kinesis.leases.LeaseCoordinator;
-import java.util.concurrent.ExecutorService;
-
/**
* Creates {@link DiagnosticEvent}s for logging and visibility
*/
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/ExecutorStateEvent.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/ExecutorStateEvent.java
index 33c83a5c..b0c0b55d 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/ExecutorStateEvent.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/ExecutorStateEvent.java
@@ -15,15 +15,15 @@
package software.amazon.kinesis.coordinator;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
+
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import software.amazon.kinesis.annotations.KinesisClientInternalApi;
import software.amazon.kinesis.leases.LeaseCoordinator;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ThreadPoolExecutor;
-
@Getter
@ToString(exclude = "isThreadPoolExecutor")
@Slf4j
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownContext.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownContext.java
index e0ad229b..d805d6cd 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownContext.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownContext.java
@@ -14,12 +14,12 @@
*/
package software.amazon.kinesis.coordinator;
+import java.util.concurrent.CountDownLatch;
+
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;
-import java.util.concurrent.CountDownLatch;
-
@Data
@Builder
@Accessors(fluent = true)
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinator.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinator.java
index a55ea70f..af3a2dca 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinator.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/GracefulShutdownCoordinator.java
@@ -14,13 +14,12 @@
*/
package software.amazon.kinesis.coordinator;
-
-import lombok.extern.slf4j.Slf4j;
-
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+
class GracefulShutdownCoordinator {
/**
@@ -31,8 +30,11 @@ class GracefulShutdownCoordinator {
CompletableFuture startGracefulShutdown(Callable shutdownCallable) {
CompletableFuture cf = new CompletableFuture<>();
CompletableFuture.runAsync(() -> {
- try { cf.complete(shutdownCallable.call()); }
- catch(Throwable ex) { cf.completeExceptionally(ex); }
+ try {
+ cf.complete(shutdownCallable.call());
+ } catch (Throwable ex) {
+ cf.completeExceptionally(ex);
+ }
});
return cf;
}
@@ -50,7 +52,8 @@ class GracefulShutdownCoordinator {
}
private boolean isWorkerShutdownComplete(GracefulShutdownContext context) {
- return context.scheduler().shutdownComplete() || context.scheduler().shardInfoShardConsumerMap().isEmpty();
+ return context.scheduler().shutdownComplete()
+ || context.scheduler().shardInfoShardConsumerMap().isEmpty();
}
private String awaitingLogMessage(GracefulShutdownContext context) {
@@ -92,12 +95,14 @@ class GracefulShutdownCoordinator {
throw new InterruptedException();
}
log.info(awaitingLogMessage(context));
- if (workerShutdownWithRemaining(context.shutdownCompleteLatch().getCount(), context)) {
+ if (workerShutdownWithRemaining(
+ context.shutdownCompleteLatch().getCount(), context)) {
return false;
}
}
} catch (InterruptedException ie) {
- log.warn("Interrupted while waiting for notification complete, terminating shutdown. {}",
+ log.warn(
+ "Interrupted while waiting for notification complete, terminating shutdown. {}",
awaitingLogMessage(context));
return false;
}
@@ -129,12 +134,14 @@ class GracefulShutdownCoordinator {
throw new InterruptedException();
}
log.info(awaitingFinalShutdownMessage(context));
- if (workerShutdownWithRemaining(context.shutdownCompleteLatch().getCount(), context)) {
+ if (workerShutdownWithRemaining(
+ context.shutdownCompleteLatch().getCount(), context)) {
return false;
}
}
} catch (InterruptedException ie) {
- log.warn("Interrupted while waiting for shutdown completion, terminating shutdown. {}",
+ log.warn(
+ "Interrupted while waiting for shutdown completion, terminating shutdown. {}",
awaitingFinalShutdownMessage(context));
return false;
}
@@ -152,9 +159,12 @@ class GracefulShutdownCoordinator {
private boolean workerShutdownWithRemaining(long outstanding, GracefulShutdownContext context) {
if (isWorkerShutdownComplete(context)) {
if (outstanding != 0) {
- log.info("Shutdown completed, but shutdownCompleteLatch still had outstanding {} with a current"
- + " value of {}. shutdownComplete: {} -- Consumer Map: {}", outstanding,
- context.shutdownCompleteLatch().getCount(), context.scheduler().shutdownComplete(),
+ log.info(
+ "Shutdown completed, but shutdownCompleteLatch still had outstanding {} with a current"
+ + " value of {}. shutdownComplete: {} -- Consumer Map: {}",
+ outstanding,
+ context.shutdownCompleteLatch().getCount(),
+ context.scheduler().shutdownComplete(),
context.scheduler().shardInfoShardConsumerMap().size());
return true;
}
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 ec21e4f6..8accdfcb 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
@@ -19,12 +19,8 @@ public class NoOpWorkerStateChangeListener implements WorkerStateChangeListener
/**
* Empty constructor for NoOp Worker State Change Listener
*/
- public NoOpWorkerStateChangeListener() {
-
- }
+ public NoOpWorkerStateChangeListener() {}
@Override
- public void onWorkerStateChange(WorkerState newState) {
-
- }
+ 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 30282de4..ba258bc2 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
@@ -14,6 +14,24 @@
*/
package software.amazon.kinesis.coordinator;
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ComparisonChain;
import lombok.AccessLevel;
@@ -46,24 +64,6 @@ import software.amazon.kinesis.metrics.MetricsLevel;
import software.amazon.kinesis.metrics.MetricsScope;
import software.amazon.kinesis.metrics.MetricsUtil;
-import java.io.Serializable;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
import static software.amazon.kinesis.common.HashKeyRangeForLease.fromHashKeyRange;
/**
@@ -76,10 +76,13 @@ import static software.amazon.kinesis.common.HashKeyRangeForLease.fromHashKeyRan
@KinesisClientInternalApi
class PeriodicShardSyncManager {
private static final long INITIAL_DELAY = 60 * 1000L;
+
@VisibleForTesting
static final BigInteger MIN_HASH_KEY = BigInteger.ZERO;
+
@VisibleForTesting
static final BigInteger MAX_HASH_KEY = new BigInteger("2").pow(128).subtract(BigInteger.ONE);
+
static final String PERIODIC_SHARD_SYNC_MANAGER = "PeriodicShardSyncManager";
private final Map hashRangeHoleTrackerMap = new HashMap<>();
@@ -94,30 +97,48 @@ class PeriodicShardSyncManager {
private final MetricsFactory metricsFactory;
private final long leasesRecoveryAuditorExecutionFrequencyMillis;
private final int leasesRecoveryAuditorInconsistencyConfidenceThreshold;
+
@Getter(AccessLevel.NONE)
private final AtomicBoolean leaderSynced;
+
private boolean isRunning;
- PeriodicShardSyncManager(String workerId, LeaderDecider leaderDecider, LeaseRefresher leaseRefresher,
+ PeriodicShardSyncManager(
+ String workerId,
+ LeaderDecider leaderDecider,
+ LeaseRefresher leaseRefresher,
Map currentStreamConfigMap,
Function shardSyncTaskManagerProvider,
Map streamToShardSyncTaskManagerMap,
- boolean isMultiStreamingMode, MetricsFactory metricsFactory,
+ boolean isMultiStreamingMode,
+ MetricsFactory metricsFactory,
long leasesRecoveryAuditorExecutionFrequencyMillis,
int leasesRecoveryAuditorInconsistencyConfidenceThreshold,
- AtomicBoolean leaderSynced){
- this(workerId, leaderDecider, leaseRefresher, currentStreamConfigMap, shardSyncTaskManagerProvider,
+ AtomicBoolean leaderSynced) {
+ this(
+ workerId,
+ leaderDecider,
+ leaseRefresher,
+ currentStreamConfigMap,
+ shardSyncTaskManagerProvider,
streamToShardSyncTaskManagerMap,
- Executors.newSingleThreadScheduledExecutor(), isMultiStreamingMode, metricsFactory,
- leasesRecoveryAuditorExecutionFrequencyMillis, leasesRecoveryAuditorInconsistencyConfidenceThreshold,
+ Executors.newSingleThreadScheduledExecutor(),
+ isMultiStreamingMode,
+ metricsFactory,
+ leasesRecoveryAuditorExecutionFrequencyMillis,
+ leasesRecoveryAuditorInconsistencyConfidenceThreshold,
leaderSynced);
}
- PeriodicShardSyncManager(String workerId, LeaderDecider leaderDecider, LeaseRefresher leaseRefresher,
+ PeriodicShardSyncManager(
+ String workerId,
+ LeaderDecider leaderDecider,
+ LeaseRefresher leaseRefresher,
Map currentStreamConfigMap,
Function shardSyncTaskManagerProvider,
Map streamToShardSyncTaskManagerMap,
- ScheduledExecutorService shardSyncThreadPool, boolean isMultiStreamingMode,
+ ScheduledExecutorService shardSyncThreadPool,
+ boolean isMultiStreamingMode,
MetricsFactory metricsFactory,
long leasesRecoveryAuditorExecutionFrequencyMillis,
int leasesRecoveryAuditorInconsistencyConfidenceThreshold,
@@ -134,7 +155,8 @@ class PeriodicShardSyncManager {
this.isMultiStreamingMode = isMultiStreamingMode;
this.metricsFactory = metricsFactory;
this.leasesRecoveryAuditorExecutionFrequencyMillis = leasesRecoveryAuditorExecutionFrequencyMillis;
- this.leasesRecoveryAuditorInconsistencyConfidenceThreshold = leasesRecoveryAuditorInconsistencyConfidenceThreshold;
+ this.leasesRecoveryAuditorInconsistencyConfidenceThreshold =
+ leasesRecoveryAuditorInconsistencyConfidenceThreshold;
this.leaderSynced = leaderSynced;
}
@@ -147,10 +169,12 @@ class PeriodicShardSyncManager {
log.error("Error during runShardSync.", t);
}
};
- shardSyncThreadPool.scheduleWithFixedDelay(periodicShardSyncer, INITIAL_DELAY, leasesRecoveryAuditorExecutionFrequencyMillis,
+ shardSyncThreadPool.scheduleWithFixedDelay(
+ periodicShardSyncer,
+ INITIAL_DELAY,
+ leasesRecoveryAuditorExecutionFrequencyMillis,
TimeUnit.MILLISECONDS);
isRunning = true;
-
}
return new TaskResult(null);
}
@@ -186,8 +210,8 @@ class PeriodicShardSyncManager {
if (leaderDecider.isLeader(workerId) && leaderSynced.get()) {
log.info(String.format("WorkerId %s is leader, running the periodic shard sync task", workerId));
- final MetricsScope scope = MetricsUtil.createMetricsWithOperation(metricsFactory,
- PERIODIC_SHARD_SYNC_MANAGER);
+ final MetricsScope scope =
+ MetricsUtil.createMetricsWithOperation(metricsFactory, PERIODIC_SHARD_SYNC_MANAGER);
int numStreamsWithPartialLeases = 0;
int numStreamsToSync = 0;
int numSkippedShardSyncTask = 0;
@@ -207,15 +231,17 @@ class PeriodicShardSyncManager {
log.info("Skipping shard sync task for {} as stream is purged", streamIdentifier);
continue;
}
- final ShardSyncResponse shardSyncResponse = checkForShardSync(streamIdentifier,
- streamToLeasesMap.get(streamIdentifier));
+ final ShardSyncResponse shardSyncResponse =
+ checkForShardSync(streamIdentifier, streamToLeasesMap.get(streamIdentifier));
numStreamsWithPartialLeases += shardSyncResponse.isHoleDetected() ? 1 : 0;
numStreamsToSync += shardSyncResponse.shouldDoShardSync ? 1 : 0;
if (shardSyncResponse.shouldDoShardSync()) {
- log.info("Periodic shard syncer initiating shard sync for {} due to the reason - {} ",
- streamIdentifier, shardSyncResponse.reasonForDecision());
+ log.info(
+ "Periodic shard syncer initiating shard sync for {} due to the reason - {} ",
+ streamIdentifier,
+ shardSyncResponse.reasonForDecision());
final StreamConfig streamConfig = currentStreamConfigMap.get(streamIdentifier);
if (streamConfig == null) {
log.info("Skipping shard sync task for {} as stream is purged", streamIdentifier);
@@ -223,15 +249,15 @@ class PeriodicShardSyncManager {
}
final ShardSyncTaskManager shardSyncTaskManager;
if (streamToShardSyncTaskManagerMap.containsKey(streamConfig)) {
- log.info("shardSyncTaskManager for stream {} already exists",
- streamIdentifier.streamName());
+ log.info(
+ "shardSyncTaskManager for stream {} already exists", streamIdentifier.streamName());
shardSyncTaskManager = streamToShardSyncTaskManagerMap.get(streamConfig);
- }
- else {
+ } else {
// If streamConfig of a stream has already been added to currentStreamConfigMap but
// Scheduler failed to create shardSyncTaskManager for it, then Scheduler will not try
// to create one later. So enable PeriodicShardSyncManager to do it for such cases
- log.info("Failed to get shardSyncTaskManager so creating one for stream {}.",
+ log.info(
+ "Failed to get shardSyncTaskManager so creating one for stream {}.",
streamIdentifier.streamName());
shardSyncTaskManager = streamToShardSyncTaskManagerMap.computeIfAbsent(
streamConfig, s -> shardSyncTaskManagerProvider.apply(s));
@@ -239,15 +265,24 @@ class PeriodicShardSyncManager {
if (!shardSyncTaskManager.submitShardSyncTask()) {
log.warn(
"Failed to submit shard sync task for stream {}. This could be due to the previous pending shard sync task.",
- shardSyncTaskManager.shardDetector().streamIdentifier().streamName());
+ shardSyncTaskManager
+ .shardDetector()
+ .streamIdentifier()
+ .streamName());
numSkippedShardSyncTask += 1;
} else {
- log.info("Submitted shard sync task for stream {} because of reason {}",
- shardSyncTaskManager.shardDetector().streamIdentifier().streamName(),
+ log.info(
+ "Submitted shard sync task for stream {} because of reason {}",
+ shardSyncTaskManager
+ .shardDetector()
+ .streamIdentifier()
+ .streamName(),
shardSyncResponse.reasonForDecision());
}
} else {
- log.info("Skipping shard sync for {} due to the reason - {}", streamIdentifier,
+ log.info(
+ "Skipping shard sync for {} due to the reason - {}",
+ streamIdentifier,
shardSyncResponse.reasonForDecision());
}
}
@@ -255,9 +290,14 @@ class PeriodicShardSyncManager {
} catch (Exception e) {
log.error("Caught exception while running periodic shard syncer.", e);
} finally {
- scope.addData("NumStreamsWithPartialLeases", numStreamsWithPartialLeases, StandardUnit.COUNT, MetricsLevel.SUMMARY);
+ scope.addData(
+ "NumStreamsWithPartialLeases",
+ numStreamsWithPartialLeases,
+ StandardUnit.COUNT,
+ MetricsLevel.SUMMARY);
scope.addData("NumStreamsToSync", numStreamsToSync, StandardUnit.COUNT, MetricsLevel.SUMMARY);
- scope.addData("NumSkippedShardSyncTask", numSkippedShardSyncTask, StandardUnit.COUNT, MetricsLevel.SUMMARY);
+ scope.addData(
+ "NumSkippedShardSyncTask", numSkippedShardSyncTask, StandardUnit.COUNT, MetricsLevel.SUMMARY);
MetricsUtil.addSuccessAndLatency(scope, isRunSuccess, runStartMillis, MetricsLevel.SUMMARY);
scope.end();
}
@@ -284,17 +324,18 @@ class PeriodicShardSyncManager {
} else {
final Map> streamToLeasesMap = new HashMap<>();
for (Lease lease : leases) {
- StreamIdentifier streamIdentifier = StreamIdentifier
- .multiStreamInstance(((MultiStreamLease) lease).streamIdentifier());
+ StreamIdentifier streamIdentifier =
+ StreamIdentifier.multiStreamInstance(((MultiStreamLease) lease).streamIdentifier());
if (streamIdentifiersToFilter.contains(streamIdentifier)) {
- streamToLeasesMap.computeIfAbsent(streamIdentifier, s -> new ArrayList<>()).add(lease);
+ streamToLeasesMap
+ .computeIfAbsent(streamIdentifier, s -> new ArrayList<>())
+ .add(lease);
}
}
return streamToLeasesMap;
}
}
-
/**
* Given a list of leases for a stream, determine if a shard sync is necessary.
* @param streamIdentifier
@@ -315,11 +356,13 @@ class PeriodicShardSyncManager {
// If hole is determined with high confidence return true; return false otherwise
// We are using the high confidence factor to avoid shard sync on any holes during resharding and
// lease cleanups or any intermittent issues.
- final HashRangeHoleTracker hashRangeHoleTracker = hashRangeHoleTrackerMap
- .computeIfAbsent(streamIdentifier, s -> new HashRangeHoleTracker());
- final boolean hasHoleWithHighConfidence = hashRangeHoleTracker
- .hasHighConfidenceOfHoleWith(hashRangeHoleOpt.get());
- return new ShardSyncResponse(hasHoleWithHighConfidence, true,
+ final HashRangeHoleTracker hashRangeHoleTracker =
+ hashRangeHoleTrackerMap.computeIfAbsent(streamIdentifier, s -> new HashRangeHoleTracker());
+ final boolean hasHoleWithHighConfidence =
+ hashRangeHoleTracker.hasHighConfidenceOfHoleWith(hashRangeHoleOpt.get());
+ return new ShardSyncResponse(
+ hasHoleWithHighConfidence,
+ true,
"Detected same hole for " + hashRangeHoleTracker.getNumConsecutiveHoles()
+ " times. Shard sync will be initiated when threshold reaches "
+ leasesRecoveryAuditorInconsistencyConfidenceThreshold);
@@ -355,7 +398,9 @@ class PeriodicShardSyncManager {
Optional hasHoleInLeases(StreamIdentifier streamIdentifier, List leases) {
// Filter the leases with any checkpoint other than shard end.
List activeLeases = leases.stream()
- .filter(lease -> lease.checkpoint() != null && !lease.checkpoint().isShardEnd()).collect(Collectors.toList());
+ .filter(lease ->
+ lease.checkpoint() != null && !lease.checkpoint().isShardEnd())
+ .collect(Collectors.toList());
List activeLeasesWithHashRanges = fillWithHashRangesIfRequired(streamIdentifier, activeLeases);
return checkForHoleInHashKeyRanges(streamIdentifier, activeLeasesWithHashRanges);
}
@@ -364,43 +409,49 @@ class PeriodicShardSyncManager {
// by learning from kinesis shards.
private List fillWithHashRangesIfRequired(StreamIdentifier streamIdentifier, List activeLeases) {
List activeLeasesWithNoHashRanges = activeLeases.stream()
- .filter(lease -> lease.hashKeyRangeForLease() == null).collect(Collectors.toList());
+ .filter(lease -> lease.hashKeyRangeForLease() == null)
+ .collect(Collectors.toList());
Optional minLeaseOpt = activeLeasesWithNoHashRanges.stream().min(Comparator.comparing(Lease::leaseKey));
if (minLeaseOpt.isPresent()) {
// TODO : use minLease for new ListShards with startingShardId
final Lease minLease = minLeaseOpt.get();
final ShardDetector shardDetector = shardSyncTaskManagerProvider
- .apply(currentStreamConfigMap.get(streamIdentifier)).shardDetector();
- final Map kinesisShards = shardDetector.listShards().stream()
- .collect(Collectors.toMap(Shard::shardId, shard -> shard));
- return activeLeases.stream().map(lease -> {
- if (lease.hashKeyRangeForLease() == null) {
- final String shardId = lease instanceof MultiStreamLease ?
- ((MultiStreamLease) lease).shardId() :
- lease.leaseKey();
- final Shard shard = kinesisShards.get(shardId);
- if (shard == null) {
+ .apply(currentStreamConfigMap.get(streamIdentifier))
+ .shardDetector();
+ final Map kinesisShards =
+ shardDetector.listShards().stream().collect(Collectors.toMap(Shard::shardId, shard -> shard));
+ return activeLeases.stream()
+ .map(lease -> {
+ if (lease.hashKeyRangeForLease() == null) {
+ final String shardId = lease instanceof MultiStreamLease
+ ? ((MultiStreamLease) lease).shardId()
+ : lease.leaseKey();
+ final Shard shard = kinesisShards.get(shardId);
+ if (shard == null) {
+ return lease;
+ }
+ lease.hashKeyRange(fromHashKeyRange(shard.hashKeyRange()));
+ try {
+ leaseRefresher.updateLeaseWithMetaInfo(lease, UpdateField.HASH_KEY_RANGE);
+ } catch (Exception e) {
+ log.warn(
+ "Unable to update hash range key information for lease {} of stream {}. This may result in explicit lease sync.",
+ lease.leaseKey(),
+ streamIdentifier);
+ }
+ }
return lease;
- }
- lease.hashKeyRange(fromHashKeyRange(shard.hashKeyRange()));
- try {
- leaseRefresher.updateLeaseWithMetaInfo(lease, UpdateField.HASH_KEY_RANGE);
- } catch (Exception e) {
- log.warn(
- "Unable to update hash range key information for lease {} of stream {}. This may result in explicit lease sync.",
- lease.leaseKey(), streamIdentifier);
- }
- }
- return lease;
- }).filter(lease -> lease.hashKeyRangeForLease() != null).collect(Collectors.toList());
+ })
+ .filter(lease -> lease.hashKeyRangeForLease() != null)
+ .collect(Collectors.toList());
} else {
return activeLeases;
}
}
@VisibleForTesting
- static Optional checkForHoleInHashKeyRanges(StreamIdentifier streamIdentifier,
- List leasesWithHashKeyRanges) {
+ static Optional checkForHoleInHashKeyRanges(
+ StreamIdentifier streamIdentifier, List leasesWithHashKeyRanges) {
// Sort the hash ranges by starting hash key.
List sortedLeasesWithHashKeyRanges = sortLeasesByHashRange(leasesWithHashKeyRanges);
if (sortedLeasesWithHashKeyRanges.isEmpty()) {
@@ -408,34 +459,54 @@ class PeriodicShardSyncManager {
return Optional.of(new HashRangeHole());
}
// Validate for hashranges bounds.
- if (!sortedLeasesWithHashKeyRanges.get(0).hashKeyRangeForLease().startingHashKey().equals(MIN_HASH_KEY) || !sortedLeasesWithHashKeyRanges
- .get(sortedLeasesWithHashKeyRanges.size() - 1).hashKeyRangeForLease().endingHashKey().equals(MAX_HASH_KEY)) {
- log.error("Incomplete hash range found for stream {} between {} and {}.", streamIdentifier,
+ if (!sortedLeasesWithHashKeyRanges
+ .get(0)
+ .hashKeyRangeForLease()
+ .startingHashKey()
+ .equals(MIN_HASH_KEY)
+ || !sortedLeasesWithHashKeyRanges
+ .get(sortedLeasesWithHashKeyRanges.size() - 1)
+ .hashKeyRangeForLease()
+ .endingHashKey()
+ .equals(MAX_HASH_KEY)) {
+ log.error(
+ "Incomplete hash range found for stream {} between {} and {}.",
+ streamIdentifier,
sortedLeasesWithHashKeyRanges.get(0),
sortedLeasesWithHashKeyRanges.get(sortedLeasesWithHashKeyRanges.size() - 1));
- return Optional.of(new HashRangeHole(sortedLeasesWithHashKeyRanges.get(0).hashKeyRangeForLease(),
- sortedLeasesWithHashKeyRanges.get(sortedLeasesWithHashKeyRanges.size() - 1).hashKeyRangeForLease()));
+ return Optional.of(new HashRangeHole(
+ sortedLeasesWithHashKeyRanges.get(0).hashKeyRangeForLease(),
+ sortedLeasesWithHashKeyRanges
+ .get(sortedLeasesWithHashKeyRanges.size() - 1)
+ .hashKeyRangeForLease()));
}
// Check for any holes in the sorted hashrange intervals.
if (sortedLeasesWithHashKeyRanges.size() > 1) {
Lease leftMostLeaseToReportInCaseOfHole = sortedLeasesWithHashKeyRanges.get(0);
HashKeyRangeForLease leftLeaseHashRange = leftMostLeaseToReportInCaseOfHole.hashKeyRangeForLease();
for (int i = 1; i < sortedLeasesWithHashKeyRanges.size(); i++) {
- final HashKeyRangeForLease rightLeaseHashRange = sortedLeasesWithHashKeyRanges.get(i).hashKeyRangeForLease();
- final BigInteger rangeDiff = rightLeaseHashRange.startingHashKey().subtract(leftLeaseHashRange.endingHashKey());
+ final HashKeyRangeForLease rightLeaseHashRange =
+ sortedLeasesWithHashKeyRanges.get(i).hashKeyRangeForLease();
+ final BigInteger rangeDiff =
+ rightLeaseHashRange.startingHashKey().subtract(leftLeaseHashRange.endingHashKey());
// Case of overlapping leases when the rangediff is 0 or negative.
// signum() will be -1 for negative and 0 if value is 0.
// Merge the range for further tracking.
if (rangeDiff.signum() <= 0) {
- leftLeaseHashRange = new HashKeyRangeForLease(leftLeaseHashRange.startingHashKey(),
+ leftLeaseHashRange = new HashKeyRangeForLease(
+ leftLeaseHashRange.startingHashKey(),
leftLeaseHashRange.endingHashKey().max(rightLeaseHashRange.endingHashKey()));
} else {
// Case of non overlapping leases when rangediff is positive. signum() will be 1 for positive.
// If rangeDiff is 1, then it is a case of continuous hashrange. If not, it is a hole.
if (!rangeDiff.equals(BigInteger.ONE)) {
- log.error("Incomplete hash range found for {} between {} and {}.", streamIdentifier,
- leftMostLeaseToReportInCaseOfHole, sortedLeasesWithHashKeyRanges.get(i));
- return Optional.of(new HashRangeHole(leftMostLeaseToReportInCaseOfHole.hashKeyRangeForLease(),
+ log.error(
+ "Incomplete hash range found for {} between {} and {}.",
+ streamIdentifier,
+ leftMostLeaseToReportInCaseOfHole,
+ sortedLeasesWithHashKeyRanges.get(i));
+ return Optional.of(new HashRangeHole(
+ leftMostLeaseToReportInCaseOfHole.hashKeyRangeForLease(),
sortedLeasesWithHashKeyRanges.get(i).hashKeyRangeForLease()));
}
leftMostLeaseToReportInCaseOfHole = sortedLeasesWithHashKeyRanges.get(i);
@@ -461,7 +532,9 @@ class PeriodicShardSyncManager {
hashRangeAtStartOfPossibleHole = hashRangeAtEndOfPossibleHole = null;
}
- HashRangeHole(HashKeyRangeForLease hashRangeAtStartOfPossibleHole, HashKeyRangeForLease hashRangeAtEndOfPossibleHole) {
+ HashRangeHole(
+ HashKeyRangeForLease hashRangeAtStartOfPossibleHole,
+ HashKeyRangeForLease hashRangeAtEndOfPossibleHole) {
this.hashRangeAtStartOfPossibleHole = hashRangeAtStartOfPossibleHole;
this.hashRangeAtEndOfPossibleHole = hashRangeAtEndOfPossibleHole;
}
@@ -472,6 +545,7 @@ class PeriodicShardSyncManager {
private class HashRangeHoleTracker {
private HashRangeHole hashRangeHole;
+
@Getter
private Integer numConsecutiveHoles;
@@ -500,8 +574,12 @@ class PeriodicShardSyncManager {
Validate.notNull(lease.hashKeyRangeForLease());
Validate.notNull(otherLease.hashKeyRangeForLease());
return ComparisonChain.start()
- .compare(lease.hashKeyRangeForLease().startingHashKey(), otherLease.hashKeyRangeForLease().startingHashKey())
- .compare(lease.hashKeyRangeForLease().endingHashKey(), otherLease.hashKeyRangeForLease().endingHashKey())
+ .compare(
+ lease.hashKeyRangeForLease().startingHashKey(),
+ otherLease.hashKeyRangeForLease().startingHashKey())
+ .compare(
+ lease.hashKeyRangeForLease().endingHashKey(),
+ otherLease.hashKeyRangeForLease().endingHashKey())
.result();
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/RejectedTaskEvent.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/RejectedTaskEvent.java
index 7dc8dfaf..df8445e1 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/RejectedTaskEvent.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/RejectedTaskEvent.java
@@ -25,8 +25,8 @@ import software.amazon.kinesis.annotations.KinesisClientInternalApi;
@Slf4j
@KinesisClientInternalApi
class RejectedTaskEvent implements DiagnosticEvent {
- private static final String MESSAGE = "Review your thread configuration to prevent task rejections. " +
- "Task rejections will slow down your application and some shards may stop processing. ";
+ private static final String MESSAGE = "Review your thread configuration to prevent task rejections. "
+ + "Task rejections will slow down your application and some shards may stop processing. ";
private ExecutorStateEvent executorStateEvent;
private Throwable throwable;
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 e4e63078..a163dfdc 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
@@ -15,10 +15,6 @@
package software.amazon.kinesis.coordinator;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Stopwatch;
-
-import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
@@ -45,6 +41,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Stopwatch;
+import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -188,6 +188,7 @@ public class Scheduler implements Runnable {
private final Stopwatch streamSyncWatch = Stopwatch.createUnstarted();
private boolean leasesSyncedOnAppInit = false;
+
@Getter(AccessLevel.NONE)
private final AtomicBoolean leaderSynced = new AtomicBoolean(false);
@@ -206,15 +207,23 @@ public class Scheduler implements Runnable {
@VisibleForTesting
protected boolean gracefuleShutdownStarted = false;
- public Scheduler(@NonNull final CheckpointConfig checkpointConfig,
- @NonNull final CoordinatorConfig coordinatorConfig,
- @NonNull final LeaseManagementConfig leaseManagementConfig,
- @NonNull final LifecycleConfig lifecycleConfig,
- @NonNull final MetricsConfig metricsConfig,
- @NonNull final ProcessorConfig processorConfig,
- @NonNull final RetrievalConfig retrievalConfig) {
- this(checkpointConfig, coordinatorConfig, leaseManagementConfig, lifecycleConfig, metricsConfig,
- processorConfig, retrievalConfig, new DiagnosticEventFactory());
+ public Scheduler(
+ @NonNull final CheckpointConfig checkpointConfig,
+ @NonNull final CoordinatorConfig coordinatorConfig,
+ @NonNull final LeaseManagementConfig leaseManagementConfig,
+ @NonNull final LifecycleConfig lifecycleConfig,
+ @NonNull final MetricsConfig metricsConfig,
+ @NonNull final ProcessorConfig processorConfig,
+ @NonNull final RetrievalConfig retrievalConfig) {
+ this(
+ checkpointConfig,
+ coordinatorConfig,
+ leaseManagementConfig,
+ lifecycleConfig,
+ metricsConfig,
+ processorConfig,
+ retrievalConfig,
+ new DiagnosticEventFactory());
}
/**
@@ -222,14 +231,15 @@ public class Scheduler implements Runnable {
* is desired for testing. This constructor is only used for testing to provide a mock DiagnosticEventFactory.
*/
@VisibleForTesting
- protected Scheduler(@NonNull final CheckpointConfig checkpointConfig,
- @NonNull final CoordinatorConfig coordinatorConfig,
- @NonNull final LeaseManagementConfig leaseManagementConfig,
- @NonNull final LifecycleConfig lifecycleConfig,
- @NonNull final MetricsConfig metricsConfig,
- @NonNull final ProcessorConfig processorConfig,
- @NonNull final RetrievalConfig retrievalConfig,
- @NonNull final DiagnosticEventFactory diagnosticEventFactory) {
+ protected Scheduler(
+ @NonNull final CheckpointConfig checkpointConfig,
+ @NonNull final CoordinatorConfig coordinatorConfig,
+ @NonNull final LeaseManagementConfig leaseManagementConfig,
+ @NonNull final LifecycleConfig lifecycleConfig,
+ @NonNull final MetricsConfig metricsConfig,
+ @NonNull final ProcessorConfig processorConfig,
+ @NonNull final RetrievalConfig retrievalConfig,
+ @NonNull final DiagnosticEventFactory diagnosticEventFactory) {
this.checkpointConfig = checkpointConfig;
this.coordinatorConfig = coordinatorConfig;
this.leaseManagementConfig = leaseManagementConfig;
@@ -242,16 +252,14 @@ public class Scheduler implements Runnable {
this.streamTracker = retrievalConfig.streamTracker();
this.isMultiStreamMode = streamTracker.isMultiStream();
this.formerStreamsLeasesDeletionStrategy = streamTracker.formerStreamsLeasesDeletionStrategy();
- streamTracker.streamConfigList().forEach(
- sc -> currentStreamConfigMap.put(sc.streamIdentifier(), sc));
+ streamTracker.streamConfigList().forEach(sc -> currentStreamConfigMap.put(sc.streamIdentifier(), sc));
log.info("Initial state: {}", currentStreamConfigMap.values());
this.maxInitializationAttempts = this.coordinatorConfig.maxInitializationAttempts();
this.metricsFactory = this.metricsConfig.metricsFactory();
// Determine leaseSerializer based on availability of MultiStreamTracker.
- final LeaseSerializer leaseSerializer = isMultiStreamMode ?
- new DynamoDBMultiStreamLeaseSerializer() :
- new DynamoDBLeaseSerializer();
+ final LeaseSerializer leaseSerializer =
+ isMultiStreamMode ? new DynamoDBMultiStreamLeaseSerializer() : new DynamoDBLeaseSerializer();
this.leaseCoordinator = this.leaseManagementConfig
.leaseManagementFactory(leaseSerializer, isMultiStreamMode)
.createLeaseCoordinator(this.metricsFactory);
@@ -260,8 +268,9 @@ public class Scheduler implements Runnable {
//
// TODO: Figure out what to do with lease manage <=> checkpoint relationship
//
- this.checkpoint = this.checkpointConfig.checkpointFactory().createCheckpointer(this.leaseCoordinator,
- this.leaseRefresher);
+ this.checkpoint = this.checkpointConfig
+ .checkpointFactory()
+ .createCheckpointer(this.leaseCoordinator, this.leaseRefresher);
//
// TODO: Move this configuration to lifecycle
@@ -282,38 +291,46 @@ public class Scheduler implements Runnable {
if (coordinatorConfig.gracefulShutdownCoordinator() != null) {
this.gracefulShutdownCoordinator = coordinatorConfig.gracefulShutdownCoordinator();
} else {
- this.gracefulShutdownCoordinator = this.coordinatorConfig.coordinatorFactory()
- .createGracefulShutdownCoordinator();
+ this.gracefulShutdownCoordinator =
+ this.coordinatorConfig.coordinatorFactory().createGracefulShutdownCoordinator();
}
if (coordinatorConfig.workerStateChangeListener() != null) {
this.workerStateChangeListener = coordinatorConfig.workerStateChangeListener();
} else {
- this.workerStateChangeListener = this.coordinatorConfig.coordinatorFactory()
- .createWorkerStateChangeListener();
+ this.workerStateChangeListener =
+ this.coordinatorConfig.coordinatorFactory().createWorkerStateChangeListener();
}
- this.leaderDecider = new DeterministicShuffleShardSyncLeaderDecider(leaseRefresher,
- Executors.newSingleThreadScheduledExecutor(),
- PERIODIC_SHARD_SYNC_MAX_WORKERS_DEFAULT);
+ this.leaderDecider = new DeterministicShuffleShardSyncLeaderDecider(
+ leaseRefresher, Executors.newSingleThreadScheduledExecutor(), PERIODIC_SHARD_SYNC_MAX_WORKERS_DEFAULT);
this.failoverTimeMillis = this.leaseManagementConfig.failoverTimeMillis();
this.taskBackoffTimeMillis = this.lifecycleConfig.taskBackoffTimeMillis();
this.listShardsBackoffTimeMillis = this.retrievalConfig.listShardsBackoffTimeInMillis();
this.maxListShardsRetryAttempts = this.retrievalConfig.maxListShardsRetryAttempts();
- this.shardDetectorProvider = streamConfig -> createOrGetShardSyncTaskManager(streamConfig).shardDetector();
+ this.shardDetectorProvider =
+ streamConfig -> createOrGetShardSyncTaskManager(streamConfig).shardDetector();
this.ignoreUnexpetedChildShards = this.leaseManagementConfig.ignoreUnexpectedChildShards();
this.aggregatorUtil = this.lifecycleConfig.aggregatorUtil();
- this.hierarchicalShardSyncerProvider = streamConfig -> createOrGetShardSyncTaskManager(streamConfig).hierarchicalShardSyncer();
- this.schedulerInitializationBackoffTimeMillis = this.coordinatorConfig.schedulerInitializationBackoffTimeMillis();
+ this.hierarchicalShardSyncerProvider =
+ streamConfig -> createOrGetShardSyncTaskManager(streamConfig).hierarchicalShardSyncer();
+ this.schedulerInitializationBackoffTimeMillis =
+ this.coordinatorConfig.schedulerInitializationBackoffTimeMillis();
this.leaderElectedPeriodicShardSyncManager = new PeriodicShardSyncManager(
- leaseManagementConfig.workerIdentifier(), leaderDecider, leaseRefresher, currentStreamConfigMap,
- shardSyncTaskManagerProvider, streamToShardSyncTaskManagerMap, isMultiStreamMode, metricsFactory,
+ leaseManagementConfig.workerIdentifier(),
+ leaderDecider,
+ leaseRefresher,
+ currentStreamConfigMap,
+ shardSyncTaskManagerProvider,
+ streamToShardSyncTaskManagerMap,
+ isMultiStreamMode,
+ metricsFactory,
leaseManagementConfig.leasesRecoveryAuditorExecutionFrequencyMillis(),
leaseManagementConfig.leasesRecoveryAuditorInconsistencyConfidenceThreshold(),
leaderSynced);
- this.leaseCleanupManager = this.leaseManagementConfig.leaseManagementFactory(leaseSerializer, isMultiStreamMode)
+ this.leaseCleanupManager = this.leaseManagementConfig
+ .leaseManagementFactory(leaseSerializer, isMultiStreamMode)
.createLeaseCleanupManager(metricsFactory);
- this.schemaRegistryDecoder =
- this.retrievalConfig.glueSchemaRegistryDeserializer() == null ?
- null
+ this.schemaRegistryDecoder = this.retrievalConfig.glueSchemaRegistryDeserializer() == null
+ ? null
: new SchemaRegistryDecoder(this.retrievalConfig.glueSchemaRegistryDeserializer());
}
@@ -357,9 +374,10 @@ public class Scheduler implements Runnable {
if (!skipShardSyncAtWorkerInitializationIfLeasesExist || leaseRefresher.isLeaseTableEmpty()) {
if (shouldInitiateLeaseSync()) {
- log.info("Worker {} is initiating the lease sync.", leaseManagementConfig.workerIdentifier());
+ log.info(
+ "Worker {} is initiating the lease sync.",
+ leaseManagementConfig.workerIdentifier());
leaderElectedPeriodicShardSyncManager.syncShardsOnce();
-
}
} else {
log.info("Skipping shard sync per configuration setting (and lease table is not empty)");
@@ -402,13 +420,15 @@ public class Scheduler implements Runnable {
}
@VisibleForTesting
- boolean shouldInitiateLeaseSync() throws InterruptedException,
- DependencyException, ProvisionedThroughputException, InvalidStateException {
- long waitTime = ThreadLocalRandom.current().nextLong(MIN_WAIT_TIME_FOR_LEASE_TABLE_CHECK_MILLIS, MAX_WAIT_TIME_FOR_LEASE_TABLE_CHECK_MILLIS);
+ boolean shouldInitiateLeaseSync()
+ throws InterruptedException, DependencyException, ProvisionedThroughputException, InvalidStateException {
+ long waitTime = ThreadLocalRandom.current()
+ .nextLong(MIN_WAIT_TIME_FOR_LEASE_TABLE_CHECK_MILLIS, MAX_WAIT_TIME_FOR_LEASE_TABLE_CHECK_MILLIS);
long waitUntil = System.currentTimeMillis() + waitTime;
boolean shouldInitiateLeaseSync = true;
- while (System.currentTimeMillis() < waitUntil && (shouldInitiateLeaseSync = leaseRefresher.isLeaseTableEmpty())) {
+ while (System.currentTimeMillis() < waitUntil
+ && (shouldInitiateLeaseSync = leaseRefresher.isLeaseTableEmpty())) {
// check every 3 seconds if lease table is still empty,
// to minimize contention between all workers bootstrapping at the same time
log.info("Lease table is still empty. Checking again in {} ms", LEASE_TABLE_CHECK_FREQUENCY_MILLIS);
@@ -422,8 +442,8 @@ public class Scheduler implements Runnable {
try {
Set assignedShards = new HashSet<>();
for (ShardInfo shardInfo : getShardInfoForAssignments()) {
- ShardConsumer shardConsumer = createOrGetShardConsumer(shardInfo,
- processorConfig.shardRecordProcessorFactory(), leaseCleanupManager);
+ ShardConsumer shardConsumer = createOrGetShardConsumer(
+ shardInfo, processorConfig.shardRecordProcessorFactory(), leaseCleanupManager);
shardConsumer.executeLifecycle();
assignedShards.add(shardInfo);
@@ -444,8 +464,10 @@ public class Scheduler implements Runnable {
slog.info("Sleeping ...");
Thread.sleep(shardConsumerDispatchPollIntervalMillis);
} catch (Exception e) {
- log.error("Worker.run caught exception, sleeping for {} milli seconds!",
- shardConsumerDispatchPollIntervalMillis, e);
+ log.error(
+ "Worker.run caught exception, sleeping for {} milli seconds!",
+ shardConsumerDispatchPollIntervalMillis,
+ e);
try {
Thread.sleep(shardConsumerDispatchPollIntervalMillis);
} catch (InterruptedException ex) {
@@ -470,11 +492,12 @@ public class Scheduler implements Runnable {
final Set streamsSynced = new HashSet<>();
if (shouldSyncStreamsNow()) {
- final MetricsScope metricsScope = MetricsUtil.createMetricsWithOperation(metricsFactory, MULTI_STREAM_TRACKER);
+ final MetricsScope metricsScope =
+ MetricsUtil.createMetricsWithOperation(metricsFactory, MULTI_STREAM_TRACKER);
try {
- final Map newStreamConfigMap = streamTracker.streamConfigList()
- .stream().collect(Collectors.toMap(StreamConfig::streamIdentifier, Function.identity()));
+ final Map newStreamConfigMap = streamTracker.streamConfigList().stream()
+ .collect(Collectors.toMap(StreamConfig::streamIdentifier, Function.identity()));
// This is done to ensure that we clean up the stale streams lingering in the lease table.
// Only sync from lease table again if the currentStreamConfigMap and newStreamConfigMap contain
// different set of streams and Leader has not synced the leases yet
@@ -487,12 +510,16 @@ public class Scheduler implements Runnable {
final Set streamsFromLeaseTable = leaseTableLeases.stream()
.map(lease -> StreamIdentifier.multiStreamInstance(lease.streamIdentifier()))
.collect(Collectors.toSet());
- // Remove stream from currentStreamConfigMap if this stream in not in the lease table and newStreamConfigMap.
+ // Remove stream from currentStreamConfigMap if this stream in not in the lease table and
+ // newStreamConfigMap.
// This means that the leases have already been deleted by the last leader.
currentStreamConfigMap.keySet().stream()
.filter(streamIdentifier -> !newStreamConfigMap.containsKey(streamIdentifier)
- && !streamsFromLeaseTable.contains(streamIdentifier)).forEach(stream -> {
- log.info("Removing stream {} from currentStreamConfigMap due to not being active", stream);
+ && !streamsFromLeaseTable.contains(streamIdentifier))
+ .forEach(stream -> {
+ log.info(
+ "Removing stream {} from currentStreamConfigMap due to not being active",
+ stream);
currentStreamConfigMap.remove(stream);
staleStreamDeletionMap.remove(stream);
streamsSynced.add(stream);
@@ -519,18 +546,21 @@ public class Scheduler implements Runnable {
staleStreamDeletionMap.putIfAbsent(streamIdentifier, Instant.now());
}
};
- if (formerStreamsLeasesDeletionStrategy.leaseDeletionType() == FORMER_STREAMS_AUTO_DETECTION_DEFERRED_DELETION) {
+ if (formerStreamsLeasesDeletionStrategy.leaseDeletionType()
+ == FORMER_STREAMS_AUTO_DETECTION_DEFERRED_DELETION) {
// Now, we are identifying the stale/old streams and enqueuing it for deferred deletion.
// It is assumed that all the workers will always have the latest and consistent snapshot of streams
// from the multiStreamTracker.
//
- // The following streams transition state among two workers are NOT considered safe, where Worker 2, on
+ // The following streams transition state among two workers are NOT considered safe, where Worker 2,
+ // on
// initialization learn about D from lease table and delete the leases for D, as it is not available
// in its latest MultiStreamTracker.
// Worker 1 : A,B,C -> A,B,C,D (latest)
// Worker 2 : BOOTS_UP -> A,B,C (stale)
//
- // The following streams transition state among two workers are NOT considered safe, where Worker 2 might
+ // The following streams transition state among two workers are NOT considered safe, where Worker 2
+ // might
// end up deleting the leases for A and D and lose progress made so far.
// Worker 1 : A,B,C -> A,B,C,D (latest)
// Worker 2 : A,B,C -> B,C (stale/partial)
@@ -539,13 +569,16 @@ public class Scheduler implements Runnable {
// before attempting to delete it, we will be deferring the leases deletion based on the
// defer time period.
currentStreamConfigMap.keySet().forEach(enqueueStreamLeaseDeletionOperation);
- } else if (formerStreamsLeasesDeletionStrategy.leaseDeletionType() == StreamsLeasesDeletionType.PROVIDED_STREAMS_DEFERRED_DELETION) {
- Optional.ofNullable(formerStreamsLeasesDeletionStrategy.streamIdentifiersForLeaseCleanup()).ifPresent(
- streamIdentifiers -> streamIdentifiers.forEach(enqueueStreamLeaseDeletionOperation));
+ } else if (formerStreamsLeasesDeletionStrategy.leaseDeletionType()
+ == StreamsLeasesDeletionType.PROVIDED_STREAMS_DEFERRED_DELETION) {
+ Optional.ofNullable(formerStreamsLeasesDeletionStrategy.streamIdentifiersForLeaseCleanup())
+ .ifPresent(streamIdentifiers ->
+ streamIdentifiers.forEach(enqueueStreamLeaseDeletionOperation));
} else {
// Remove the old/stale streams identified through the new and existing streams list, without
// cleaning up their leases. Disabling deprecated shard sync + lease cleanup through a flag.
- Iterator currentSetOfStreamsIter = currentStreamConfigMap.keySet().iterator();
+ Iterator currentSetOfStreamsIter =
+ currentStreamConfigMap.keySet().iterator();
while (currentSetOfStreamsIter.hasNext()) {
StreamIdentifier streamIdentifier = currentSetOfStreamsIter.next();
if (!newStreamConfigMap.containsKey(streamIdentifier)) {
@@ -553,13 +586,14 @@ public class Scheduler implements Runnable {
log.info(
"Found old/deleted stream : {}. Triggering shard sync. Removing from tracked active streams.",
streamIdentifier);
- ShardSyncTaskManager shardSyncTaskManager = createOrGetShardSyncTaskManager(
- currentStreamConfigMap.get(streamIdentifier));
+ ShardSyncTaskManager shardSyncTaskManager =
+ createOrGetShardSyncTaskManager(currentStreamConfigMap.get(streamIdentifier));
shardSyncTaskManager.submitShardSyncTask();
} else {
log.info(
"Found old/deleted stream : {}. Removing from tracked active streams, but not cleaning up leases,"
- + " as part of this workflow", streamIdentifier);
+ + " as part of this workflow",
+ streamIdentifier);
}
currentSetOfStreamsIter.remove();
streamsSynced.add(streamIdentifier);
@@ -573,22 +607,24 @@ public class Scheduler implements Runnable {
// StreamIdentifiers are eligible for deletion only when the deferment period has elapsed and
// the streamIdentifiersForLeaseCleanup are not present in the latest snapshot.
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());
+ 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());
// 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.
// Filter streams based on newStreamConfigMap so that we don't override input to KCL in any case.
- final Set deletedStreamSet = this.deletedStreamListProvider
- .purgeAllDeletedStream()
- .stream()
- .filter(streamIdentifier -> !newStreamConfigMap.containsKey(streamIdentifier))
- .collect(Collectors.toSet());
+ final Set deletedStreamSet =
+ this.deletedStreamListProvider.purgeAllDeletedStream().stream()
+ .filter(streamIdentifier -> !newStreamConfigMap.containsKey(streamIdentifier))
+ .collect(Collectors.toSet());
if (deletedStreamSet.size() > 0) {
log.info("Stale streams to delete: {}", deletedStreamSet);
staleStreamIdsToBeDeleted.addAll(deletedStreamSet);
@@ -603,18 +639,24 @@ public class Scheduler implements Runnable {
if (!staleStreamDeletionMap.isEmpty()) {
log.warn(
"Streams enqueued for deletion for lease table cleanup along with their scheduled time for deletion: {} ",
- staleStreamDeletionMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
- entry -> entry.getValue().plus(waitPeriodToDeleteOldStreams))));
+ staleStreamDeletionMap.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue()
+ .plus(waitPeriodToDeleteOldStreams))));
}
streamSyncWatch.reset().start();
- MetricsUtil.addCount(metricsScope, ACTIVE_STREAMS_COUNT, newStreamConfigMap.size(), MetricsLevel.SUMMARY);
- MetricsUtil.addCount(metricsScope, PENDING_STREAMS_DELETION_COUNT, staleStreamDeletionMap.size(),
+ MetricsUtil.addCount(
+ metricsScope, ACTIVE_STREAMS_COUNT, newStreamConfigMap.size(), MetricsLevel.SUMMARY);
+ MetricsUtil.addCount(
+ metricsScope,
+ PENDING_STREAMS_DELETION_COUNT,
+ staleStreamDeletionMap.size(),
MetricsLevel.SUMMARY);
- MetricsUtil.addCount(metricsScope, NON_EXISTING_STREAM_DELETE_COUNT, deletedStreamSet.size(),
- MetricsLevel.SUMMARY);
- MetricsUtil.addCount(metricsScope, DELETED_STREAMS_COUNT, deletedStreamsLeases.size(), MetricsLevel.SUMMARY);
+ MetricsUtil.addCount(
+ metricsScope, NON_EXISTING_STREAM_DELETE_COUNT, deletedStreamSet.size(), MetricsLevel.SUMMARY);
+ MetricsUtil.addCount(
+ metricsScope, DELETED_STREAMS_COUNT, deletedStreamsLeases.size(), MetricsLevel.SUMMARY);
} finally {
MetricsUtil.endScope(metricsScope);
}
@@ -624,8 +666,7 @@ public class Scheduler implements Runnable {
@VisibleForTesting
boolean shouldSyncStreamsNow() {
- return isMultiStreamMode &&
- (streamSyncWatch.elapsed(TimeUnit.MILLISECONDS) > NEW_STREAM_CHECK_INTERVAL_MILLIS);
+ return isMultiStreamMode && (streamSyncWatch.elapsed(TimeUnit.MILLISECONDS) > NEW_STREAM_CHECK_INTERVAL_MILLIS);
}
@VisibleForTesting
@@ -642,7 +683,8 @@ public class Scheduler implements Runnable {
private List fetchMultiStreamLeases()
throws DependencyException, ProvisionedThroughputException, InvalidStateException {
- return (List) ((List) leaseCoordinator.leaseRefresher().listLeases());
+ return (List)
+ ((List) leaseCoordinator.leaseRefresher().listLeases());
}
private void removeStreamsFromStaleStreamsList(Set streamIdentifiers) {
@@ -659,8 +701,9 @@ public class Scheduler implements Runnable {
log.info("Deleting streams: {}", streamIdentifiers);
final Set streamsSynced = new HashSet<>();
final List leases = fetchMultiStreamLeases();
- final Map> streamIdToShardsMap = leases.stream().collect(
- Collectors.groupingBy(MultiStreamLease::streamIdentifier, Collectors.toCollection(ArrayList::new)));
+ final Map> streamIdToShardsMap = leases.stream()
+ .collect(Collectors.groupingBy(
+ MultiStreamLease::streamIdentifier, Collectors.toCollection(ArrayList::new)));
for (StreamIdentifier streamIdentifier : streamIdentifiers) {
log.warn("Found old/deleted stream: {}. Directly deleting leases of this stream.", streamIdentifier);
// Removing streamIdentifier from this map so PSSM doesn't think there is a hole in the stream while
@@ -690,7 +733,8 @@ public class Scheduler implements Runnable {
} catch (DependencyException | InvalidStateException | ProvisionedThroughputException e) {
log.error(
"Unable to delete stale stream lease {}. Skipping further deletions for this stream. Will retry later.",
- lease.leaseKey(), e);
+ lease.leaseKey(),
+ e);
return false;
}
}
@@ -760,8 +804,8 @@ public class Scheduler implements Runnable {
public CompletableFuture startGracefulShutdown() {
synchronized (this) {
if (gracefulShutdownFuture == null) {
- gracefulShutdownFuture = gracefulShutdownCoordinator
- .startGracefulShutdown(createGracefulShutdownCallable());
+ gracefulShutdownFuture =
+ gracefulShutdownCoordinator.startGracefulShutdown(createGracefulShutdownCallable());
}
}
return gracefulShutdownFuture;
@@ -809,13 +853,15 @@ public class Scheduler implements Runnable {
// If there are no leases notification is already completed, but we still need to shutdown the worker.
//
this.shutdown();
- return GracefulShutdownContext.builder().finalShutdownLatch(finalShutdownLatch).build();
+ return GracefulShutdownContext.builder()
+ .finalShutdownLatch(finalShutdownLatch)
+ .build();
}
CountDownLatch shutdownCompleteLatch = new CountDownLatch(leases.size());
CountDownLatch notificationCompleteLatch = new CountDownLatch(leases.size());
for (Lease lease : leases) {
- ShutdownNotification shutdownNotification = new ShardConsumerShutdownNotification(leaseCoordinator,
- lease, notificationCompleteLatch, shutdownCompleteLatch);
+ ShutdownNotification shutdownNotification = new ShardConsumerShutdownNotification(
+ leaseCoordinator, lease, notificationCompleteLatch, shutdownCompleteLatch);
ShardInfo shardInfo = DynamoDBLeaseCoordinator.convertLeaseToAssignment(lease);
ShardConsumer consumer = shardInfoShardConsumerMap.get(shardInfo);
if (consumer != null) {
@@ -929,9 +975,10 @@ public class Scheduler implements Runnable {
* Kinesis shard info
* @return ShardConsumer for the shard
*/
- ShardConsumer createOrGetShardConsumer(@NonNull final ShardInfo shardInfo,
- @NonNull final ShardRecordProcessorFactory shardRecordProcessorFactory,
- @NonNull final LeaseCleanupManager leaseCleanupManager) {
+ ShardConsumer createOrGetShardConsumer(
+ @NonNull final ShardInfo shardInfo,
+ @NonNull final ShardRecordProcessorFactory shardRecordProcessorFactory,
+ @NonNull final LeaseCleanupManager leaseCleanupManager) {
ShardConsumer consumer = shardInfoShardConsumerMap.get(shardInfo);
// Instantiate a new consumer if we don't have one, or the one we
// had was from an earlier
@@ -948,20 +995,23 @@ public class Scheduler implements Runnable {
}
private ShardSyncTaskManager createOrGetShardSyncTaskManager(StreamConfig streamConfig) {
- return streamToShardSyncTaskManagerMap.computeIfAbsent(streamConfig, s -> shardSyncTaskManagerProvider.apply(s));
+ return streamToShardSyncTaskManagerMap.computeIfAbsent(
+ streamConfig, s -> shardSyncTaskManagerProvider.apply(s));
}
- protected ShardConsumer buildConsumer(@NonNull final ShardInfo shardInfo,
- @NonNull final ShardRecordProcessorFactory shardRecordProcessorFactory,
- @NonNull final LeaseCleanupManager leaseCleanupManager) {
- ShardRecordProcessorCheckpointer checkpointer = coordinatorConfig.coordinatorFactory().createRecordProcessorCheckpointer(shardInfo,
- checkpoint);
+ protected ShardConsumer buildConsumer(
+ @NonNull final ShardInfo shardInfo,
+ @NonNull final ShardRecordProcessorFactory shardRecordProcessorFactory,
+ @NonNull final LeaseCleanupManager leaseCleanupManager) {
+ ShardRecordProcessorCheckpointer checkpointer =
+ coordinatorConfig.coordinatorFactory().createRecordProcessorCheckpointer(shardInfo, checkpoint);
// The only case where streamName is not available will be when multistreamtracker not set. In this case,
// get the default stream name for the single stream application.
final StreamIdentifier streamIdentifier = getStreamIdentifier(shardInfo.streamIdentifierSerOpt());
// Irrespective of single stream app or multi stream app, streamConfig should always be available.
- // If we have a shardInfo, that is not present in currentStreamConfigMap for whatever reason, then return default stream config
+ // If we have a shardInfo, that is not present in currentStreamConfigMap for whatever reason, then return
+ // default stream config
// to gracefully complete the reading.
StreamConfig streamConfig = currentStreamConfigMap.get(streamIdentifier);
if (streamConfig == null) {
@@ -969,8 +1019,10 @@ public class Scheduler implements Runnable {
log.info("Created orphan {}", streamConfig);
}
Validate.notNull(streamConfig, "StreamConfig should not be null");
- RecordsPublisher cache = retrievalConfig.retrievalFactory().createGetRecordsCache(shardInfo, streamConfig, metricsFactory);
- ShardConsumerArgument argument = new ShardConsumerArgument(shardInfo,
+ RecordsPublisher cache =
+ retrievalConfig.retrievalFactory().createGetRecordsCache(shardInfo, streamConfig, metricsFactory);
+ ShardConsumerArgument argument = new ShardConsumerArgument(
+ shardInfo,
streamConfig.streamIdentifier(),
leaseCoordinator,
executorService,
@@ -993,10 +1045,15 @@ public class Scheduler implements Runnable {
hierarchicalShardSyncerProvider.apply(streamConfig),
metricsFactory,
leaseCleanupManager,
- schemaRegistryDecoder
- );
- return new ShardConsumer(cache, executorService, shardInfo, lifecycleConfig.logWarningForTaskAfterMillis(),
- argument, lifecycleConfig.taskExecutionListener(), lifecycleConfig.readTimeoutsToIgnoreBeforeWarning());
+ schemaRegistryDecoder);
+ return new ShardConsumer(
+ cache,
+ executorService,
+ shardInfo,
+ lifecycleConfig.logWarningForTaskAfterMillis(),
+ argument,
+ lifecycleConfig.taskExecutionListener(),
+ lifecycleConfig.readTimeoutsToIgnoreBeforeWarning());
}
/**
@@ -1030,16 +1087,16 @@ public class Scheduler implements Runnable {
*/
private void registerErrorHandlerForUndeliverableAsyncTaskExceptions() {
RxJavaPlugins.setErrorHandler(t -> {
- ExecutorStateEvent executorStateEvent = diagnosticEventFactory.executorStateEvent(executorService,
- leaseCoordinator);
+ ExecutorStateEvent executorStateEvent =
+ diagnosticEventFactory.executorStateEvent(executorService, leaseCoordinator);
RejectedTaskEvent rejectedTaskEvent = diagnosticEventFactory.rejectedTaskEvent(executorStateEvent, t);
rejectedTaskEvent.accept(diagnosticEventHandler);
});
}
private void logExecutorState() {
- ExecutorStateEvent executorStateEvent = diagnosticEventFactory.executorStateEvent(executorService,
- leaseCoordinator);
+ ExecutorStateEvent executorStateEvent =
+ diagnosticEventFactory.executorStateEvent(executorService, leaseCoordinator);
executorStateEvent.accept(diagnosticEventHandler);
}
@@ -1049,7 +1106,8 @@ public class Scheduler implements Runnable {
streamIdentifier = StreamIdentifier.multiStreamInstance(streamIdentifierString.get());
} else {
Validate.isTrue(!isMultiStreamMode, "Should not be in MultiStream Mode");
- streamIdentifier = this.currentStreamConfigMap.values().iterator().next().streamIdentifier();
+ streamIdentifier =
+ this.currentStreamConfigMap.values().iterator().next().streamIdentifier();
}
Validate.notNull(streamIdentifier, "Stream identifier should not be empty");
return streamIdentifier;
@@ -1070,13 +1128,16 @@ public class Scheduler implements Runnable {
*/
private static StreamConfig withStreamArn(
@NonNull final StreamConfig streamConfig, @NonNull final Region kinesisRegion) {
- Validate.isTrue(streamConfig.streamIdentifier().accountIdOptional().isPresent(),
- "accountId should not be empty");
- Validate.isTrue(streamConfig.streamIdentifier().streamCreationEpochOptional().isPresent(),
+ Validate.isTrue(
+ streamConfig.streamIdentifier().accountIdOptional().isPresent(), "accountId should not be empty");
+ Validate.isTrue(
+ streamConfig.streamIdentifier().streamCreationEpochOptional().isPresent(),
"streamCreationEpoch should not be empty");
- log.info("Constructing stream ARN for {} using the Kinesis client's configured region - {}.",
- streamConfig.streamIdentifier(), kinesisRegion);
+ log.info(
+ "Constructing stream ARN for {} using the Kinesis client's configured region - {}.",
+ streamConfig.streamIdentifier(),
+ kinesisRegion);
final StreamIdentifier streamIdentifierWithArn = StreamIdentifier.multiStreamInstance(
constructStreamArn(
@@ -1106,13 +1167,22 @@ public class Scheduler implements Runnable {
@NonNull final StreamIdentifier streamIdentifier, @NonNull final StreamConfig streamConfig) {
final Region kinesisRegion = getKinesisRegion();
- return super.put(streamIdentifier, streamConfig.streamIdentifier().streamArnOptional()
- .map(streamArn -> {
- Validate.isTrue(kinesisRegion.id().equals(streamArn.region().get()),
- "The provided streamARN " + streamArn
- + " does not match the Kinesis client's configured region - " + kinesisRegion);
- return streamConfig;
- }).orElse(isMultiStreamMode ? withStreamArn(streamConfig, kinesisRegion) : streamConfig));
+ return super.put(
+ streamIdentifier,
+ streamConfig
+ .streamIdentifier()
+ .streamArnOptional()
+ .map(streamArn -> {
+ Validate.isTrue(
+ kinesisRegion
+ .id()
+ .equals(streamArn.region().get()),
+ "The provided streamARN " + streamArn
+ + " does not match the Kinesis client's configured region - "
+ + kinesisRegion);
+ return streamConfig;
+ })
+ .orElse(isMultiStreamMode ? withStreamArn(streamConfig, kinesisRegion) : streamConfig));
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/SchedulerCoordinatorFactory.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/SchedulerCoordinatorFactory.java
index d138b84f..de17542f 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/SchedulerCoordinatorFactory.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/SchedulerCoordinatorFactory.java
@@ -22,7 +22,6 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
import lombok.Data;
import lombok.NonNull;
import software.amazon.kinesis.annotations.KinesisClientInternalApi;
@@ -41,15 +40,16 @@ public class SchedulerCoordinatorFactory implements CoordinatorFactory {
*/
@Override
public ExecutorService createExecutorService() {
- return new SchedulerThreadPoolExecutor(
- new ThreadFactoryBuilder().setNameFormat("ShardRecordProcessor-%04d").build());
+ return new SchedulerThreadPoolExecutor(new ThreadFactoryBuilder()
+ .setNameFormat("ShardRecordProcessor-%04d")
+ .build());
}
static class SchedulerThreadPoolExecutor extends ThreadPoolExecutor {
private static final long DEFAULT_KEEP_ALIVE = 60L;
+
SchedulerThreadPoolExecutor(ThreadFactory threadFactory) {
- super(0, Integer.MAX_VALUE, DEFAULT_KEEP_ALIVE, TimeUnit.SECONDS, new SynchronousQueue<>(),
- threadFactory);
+ super(0, Integer.MAX_VALUE, DEFAULT_KEEP_ALIVE, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory);
}
}
@@ -57,8 +57,8 @@ public class SchedulerCoordinatorFactory implements CoordinatorFactory {
* {@inheritDoc}
*/
@Override
- public ShardRecordProcessorCheckpointer createRecordProcessorCheckpointer(@NonNull final ShardInfo shardInfo,
- @NonNull final Checkpointer checkpoint) {
+ public ShardRecordProcessorCheckpointer createRecordProcessorCheckpointer(
+ @NonNull final ShardInfo shardInfo, @NonNull final Checkpointer checkpoint) {
return new ShardRecordProcessorCheckpointer(shardInfo, checkpoint);
}
}
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 dd7162b3..bc2a1b1c 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
@@ -29,6 +29,5 @@ public interface WorkerStateChangeListener {
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/exceptions/InvalidStateException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/InvalidStateException.java
index 97e9209d..6f2fa3a8 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/InvalidStateException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/InvalidStateException.java
@@ -19,16 +19,16 @@ package software.amazon.kinesis.exceptions;
* is not found).
*/
public class InvalidStateException extends KinesisClientLibNonRetryableException {
-
+
private static final long serialVersionUID = 1L;
-
+
/**
* @param message provides more details about the cause and potential ways to debug/address.
*/
public InvalidStateException(String message) {
super(message);
}
-
+
/**
* @param message provides more details about the cause and potential ways to debug/address.
* @param e Cause of the exception
@@ -36,5 +36,4 @@ public class InvalidStateException extends KinesisClientLibNonRetryableException
public InvalidStateException(String message, Exception e) {
super(message, e);
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibDependencyException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibDependencyException.java
index 6c7c295a..1f2092cb 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibDependencyException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibDependencyException.java
@@ -15,21 +15,21 @@
package software.amazon.kinesis.exceptions;
/**
- * This is thrown when the Amazon Kinesis Client Library encounters issues talking to its dependencies
+ * This is thrown when the Amazon Kinesis Client Library encounters issues talking to its dependencies
* (e.g. fetching data from Kinesis, DynamoDB table reads/writes, emitting metrics to CloudWatch).
- *
+ *
*/
public class KinesisClientLibDependencyException extends KinesisClientLibRetryableException {
-
+
private static final long serialVersionUID = 1L;
-
+
/**
* @param message provides more details about the cause and potential ways to debug/address.
*/
public KinesisClientLibDependencyException(String message) {
super(message);
}
-
+
/**
* @param message provides more details about the cause and potential ways to debug/address.
* @param e Cause of the exception
@@ -37,5 +37,4 @@ public class KinesisClientLibDependencyException extends KinesisClientLibRetryab
public KinesisClientLibDependencyException(String message, Exception e) {
super(message, e);
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibException.java
index a7b2e173..0da75474 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibException.java
@@ -25,7 +25,7 @@ public abstract class KinesisClientLibException extends Exception {
/**
* Constructor.
- *
+ *
* @param message Message of with details of the exception.
*/
public KinesisClientLibException(String message) {
@@ -34,12 +34,11 @@ public abstract class KinesisClientLibException extends Exception {
/**
* Constructor.
- *
+ *
* @param message Message with details of the exception.
* @param cause Cause.
*/
public KinesisClientLibException(String message, Throwable cause) {
super(message, cause);
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibNonRetryableException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibNonRetryableException.java
index 49f4bf6b..b538f048 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibNonRetryableException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibNonRetryableException.java
@@ -16,7 +16,7 @@ package software.amazon.kinesis.exceptions;
/**
* Non-retryable exceptions. Simply retrying the same request/operation is not expected to succeed.
- *
+ *
*/
public abstract class KinesisClientLibNonRetryableException extends KinesisClientLibException {
@@ -24,7 +24,7 @@ public abstract class KinesisClientLibNonRetryableException extends KinesisClien
/**
* Constructor.
- *
+ *
* @param message Message.
*/
public KinesisClientLibNonRetryableException(String message) {
@@ -33,7 +33,7 @@ public abstract class KinesisClientLibNonRetryableException extends KinesisClien
/**
* Constructor.
- *
+ *
* @param message Message.
* @param e Cause.
*/
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibRetryableException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibRetryableException.java
index 72e9b189..35d0782e 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibRetryableException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/KinesisClientLibRetryableException.java
@@ -22,7 +22,7 @@ public abstract class KinesisClientLibRetryableException extends RuntimeExceptio
/**
* Constructor.
- *
+ *
* @param message Message with details about the exception.
*/
public KinesisClientLibRetryableException(String message) {
@@ -31,7 +31,7 @@ public abstract class KinesisClientLibRetryableException extends RuntimeExceptio
/**
* Constructor.
- *
+ *
* @param message Message with details about the exception.
* @param e Cause.
*/
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ShutdownException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ShutdownException.java
index 6d7fafc0..0a530f57 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ShutdownException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ShutdownException.java
@@ -35,5 +35,4 @@ public class ShutdownException extends KinesisClientLibNonRetryableException {
public ShutdownException(String message, Exception e) {
super(message, e);
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ThrottlingException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ThrottlingException.java
index addfa58b..ef951ef6 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ThrottlingException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/ThrottlingException.java
@@ -35,5 +35,4 @@ public class ThrottlingException extends KinesisClientLibRetryableException {
public ThrottlingException(String message, Exception e) {
super(message, e);
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/BlockedOnParentShardException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/BlockedOnParentShardException.java
index 9b1db062..db979b3d 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/BlockedOnParentShardException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/BlockedOnParentShardException.java
@@ -27,7 +27,7 @@ public class BlockedOnParentShardException extends KinesisClientLibRetryableExce
/**
* Constructor.
- *
+ *
* @param message Error message.
*/
public BlockedOnParentShardException(String message) {
@@ -36,12 +36,11 @@ public class BlockedOnParentShardException extends KinesisClientLibRetryableExce
/**
* Constructor.
- *
+ *
* @param message Error message.
* @param e Cause of the exception.
*/
public BlockedOnParentShardException(String message, Exception e) {
super(message, e);
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/KinesisClientLibIOException.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/KinesisClientLibIOException.java
index 95495013..02f9c1a4 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/KinesisClientLibIOException.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/exceptions/internal/KinesisClientLibIOException.java
@@ -25,7 +25,7 @@ public class KinesisClientLibIOException extends KinesisClientLibRetryableExcept
/**
* Constructor.
- *
+ *
* @param message Error message.
*/
public KinesisClientLibIOException(String message) {
@@ -34,7 +34,7 @@ public class KinesisClientLibIOException extends KinesisClientLibRetryableExcept
/**
* Constructor.
- *
+ *
* @param message Error message.
* @param e Cause.
*/
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/DynamoUtils.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/DynamoUtils.java
index 29d6029b..34b13f64 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/DynamoUtils.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/DynamoUtils.java
@@ -14,15 +14,15 @@
*/
package software.amazon.kinesis.leases;
-import software.amazon.awssdk.core.SdkBytes;
-import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
-import software.amazon.kinesis.annotations.KinesisClientInternalApi;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+import software.amazon.kinesis.annotations.KinesisClientInternalApi;
+
/**
* Static utility functions used by our LeaseSerializers.
*/
@@ -42,7 +42,9 @@ public class DynamoUtils {
throw new IllegalArgumentException("Byte buffer attributeValues cannot be null or empty.");
}
- return AttributeValue.builder().b(SdkBytes.fromByteArray(byteBufferValue)).build();
+ return AttributeValue.builder()
+ .b(SdkBytes.fromByteArray(byteBufferValue))
+ .build();
}
public static AttributeValue createAttributeValue(String stringValue) {
@@ -97,5 +99,4 @@ public class DynamoUtils {
return av.ss();
}
}
-
}
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 6ddef3cf..053dc2a6 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
@@ -32,12 +32,11 @@ import com.google.common.annotations.VisibleForTesting;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-import org.apache.commons.lang3.StringUtils;
-
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
+import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import software.amazon.awssdk.services.kinesis.model.ChildShard;
import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
import software.amazon.awssdk.services.kinesis.model.Shard;
@@ -78,7 +77,8 @@ public class HierarchicalShardSyncer {
private final DeletedStreamListProvider deletedStreamListProvider;
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 String MAX_HASH_KEY =
+ new BigInteger("2").pow(128).subtract(BigInteger.ONE).toString();
private static final int RETRIES_FOR_COMPLETE_HASH_RANGE = 3;
private static final long DELAY_BETWEEN_LIST_SHARDS_MILLIS = 1000;
@@ -91,7 +91,9 @@ public class HierarchicalShardSyncer {
this(isMultiStreamMode, streamIdentifier, null);
}
- public HierarchicalShardSyncer(final boolean isMultiStreamMode, final String streamIdentifier,
+ public HierarchicalShardSyncer(
+ final boolean isMultiStreamMode,
+ final String streamIdentifier,
final DeletedStreamListProvider deletedStreamListProvider) {
this.isMultiStreamMode = isMultiStreamMode;
this.streamIdentifier = streamIdentifier;
@@ -99,9 +101,7 @@ public class HierarchicalShardSyncer {
}
private static String getShardIdFromLease(Lease lease, MultiStreamArgs multiStreamArgs) {
- return multiStreamArgs.isMultiStreamMode()
- ? ((MultiStreamLease) lease).shardId()
- : lease.leaseKey();
+ return multiStreamArgs.isMultiStreamMode() ? ((MultiStreamLease) lease).shardId() : lease.leaseKey();
}
/**
@@ -119,23 +119,41 @@ public class HierarchicalShardSyncer {
* @throws ProvisionedThroughputException
* @throws KinesisClientLibIOException
*/
- public synchronized boolean checkAndCreateLeaseForNewShards(@NonNull final ShardDetector shardDetector,
- final LeaseRefresher leaseRefresher, final InitialPositionInStreamExtended initialPosition,
- final MetricsScope scope, final boolean ignoreUnexpectedChildShards, final boolean isLeaseTableEmpty)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException, KinesisClientLibIOException, InterruptedException {
- final List latestShards = isLeaseTableEmpty ?
- getShardListAtInitialPosition(shardDetector, initialPosition) : getShardList(shardDetector);
- return checkAndCreateLeaseForNewShards(shardDetector, leaseRefresher, initialPosition, latestShards, ignoreUnexpectedChildShards, scope,
+ public synchronized boolean checkAndCreateLeaseForNewShards(
+ @NonNull final ShardDetector shardDetector,
+ final LeaseRefresher leaseRefresher,
+ final InitialPositionInStreamExtended initialPosition,
+ final MetricsScope scope,
+ final boolean ignoreUnexpectedChildShards,
+ final boolean isLeaseTableEmpty)
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException,
+ KinesisClientLibIOException, InterruptedException {
+ final List latestShards = isLeaseTableEmpty
+ ? getShardListAtInitialPosition(shardDetector, initialPosition)
+ : getShardList(shardDetector);
+ return checkAndCreateLeaseForNewShards(
+ shardDetector,
+ leaseRefresher,
+ initialPosition,
+ latestShards,
+ ignoreUnexpectedChildShards,
+ scope,
isLeaseTableEmpty);
}
/**
* 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)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException, KinesisClientLibIOException {
+ 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)
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException,
+ KinesisClientLibIOException {
if (!CollectionUtils.isNullOrEmpty(latestShards)) {
log.debug("{} - Num shards: {}", streamIdentifier, latestShards.size());
} else {
@@ -144,19 +162,22 @@ public class HierarchicalShardSyncer {
}
final Map shardIdToShardMap = constructShardIdToShardMap(latestShards);
- final Map> shardIdToChildShardIdsMap = constructShardIdToChildShardIdsMap(
- shardIdToShardMap);
+ final Map> shardIdToChildShardIdsMap =
+ constructShardIdToChildShardIdsMap(shardIdToShardMap);
final Set inconsistentShardIds = findInconsistentShardIds(shardIdToChildShardIdsMap, shardIdToShardMap);
if (!ignoreUnexpectedChildShards) {
assertAllParentShardsAreClosed(inconsistentShardIds);
}
- final List currentLeases = isMultiStreamMode ?
- leaseRefresher.listLeasesForStream(shardDetector.streamIdentifier()) : leaseRefresher.listLeases();
- final MultiStreamArgs multiStreamArgs = new MultiStreamArgs(isMultiStreamMode, shardDetector.streamIdentifier());
- final LeaseSynchronizer leaseSynchronizer = isLeaseTableEmpty ? new EmptyLeaseTableSynchronizer() :
- new NonEmptyLeaseTableSynchronizer(shardDetector, shardIdToShardMap, shardIdToChildShardIdsMap);
- final List newLeasesToCreate = determineNewLeasesToCreate(leaseSynchronizer, latestShards, currentLeases,
- initialPosition, inconsistentShardIds, multiStreamArgs);
+ final List currentLeases = isMultiStreamMode
+ ? leaseRefresher.listLeasesForStream(shardDetector.streamIdentifier())
+ : leaseRefresher.listLeases();
+ final MultiStreamArgs multiStreamArgs =
+ new MultiStreamArgs(isMultiStreamMode, shardDetector.streamIdentifier());
+ final LeaseSynchronizer leaseSynchronizer = isLeaseTableEmpty
+ ? new EmptyLeaseTableSynchronizer()
+ : new NonEmptyLeaseTableSynchronizer(shardDetector, shardIdToShardMap, shardIdToChildShardIdsMap);
+ final List newLeasesToCreate = determineNewLeasesToCreate(
+ leaseSynchronizer, latestShards, currentLeases, initialPosition, inconsistentShardIds, multiStreamArgs);
log.info("{} - Number of new leases to create: {}", streamIdentifier, newLeasesToCreate.size());
final Set createdLeases = new HashSet<>();
@@ -172,7 +193,9 @@ public class HierarchicalShardSyncer {
} finally {
MetricsUtil.addSuccessAndLatency(scope, "CreateLease", success, startTime, MetricsLevel.DETAILED);
if (lease.checkpoint() != null) {
- final String metricName = lease.checkpoint().isSentinelCheckpoint() ? lease.checkpoint().sequenceNumber() : "SEQUENCE_NUMBER";
+ final String metricName = lease.checkpoint().isSentinelCheckpoint()
+ ? lease.checkpoint().sequenceNumber()
+ : "SEQUENCE_NUMBER";
MetricsUtil.addSuccess(scope, "CreateLease_" + metricName, true, MetricsLevel.DETAILED);
}
}
@@ -187,7 +210,7 @@ public class HierarchicalShardSyncer {
* @throws KinesisClientLibIOException
*/
private static void assertAllParentShardsAreClosed(final Set inconsistentShardIds)
- throws KinesisClientLibIOException {
+ throws KinesisClientLibIOException {
if (!CollectionUtils.isNullOrEmpty(inconsistentShardIds)) {
final String ids = StringUtils.join(inconsistentShardIds, ' ');
throw new KinesisClientLibIOException(String.format(
@@ -205,12 +228,17 @@ public class HierarchicalShardSyncer {
* @param shardIdToShardMap
* @return Set of inconsistent open shard ids for shards having open parents.
*/
- private static Set findInconsistentShardIds(final Map> shardIdToChildShardIdsMap,
- final Map shardIdToShardMap) {
+ private static Set findInconsistentShardIds(
+ final Map> shardIdToChildShardIdsMap, final Map shardIdToShardMap) {
return shardIdToChildShardIdsMap.entrySet().stream()
.filter(entry -> entry.getKey() == null
- || shardIdToShardMap.get(entry.getKey()).sequenceNumberRange().endingSequenceNumber() == null)
- .flatMap(entry -> shardIdToChildShardIdsMap.get(entry.getKey()).stream()).collect(Collectors.toSet());
+ || shardIdToShardMap
+ .get(entry.getKey())
+ .sequenceNumberRange()
+ .endingSequenceNumber()
+ == null)
+ .flatMap(entry -> shardIdToChildShardIdsMap.get(entry.getKey()).stream())
+ .collect(Collectors.toSet());
}
/**
@@ -227,15 +255,15 @@ public class HierarchicalShardSyncer {
final Shard shard = entry.getValue();
final String parentShardId = shard.parentShardId();
if (parentShardId != null && shardIdToShardMap.containsKey(parentShardId)) {
- final Set childShardIds = shardIdToChildShardIdsMap.computeIfAbsent(parentShardId,
- key -> new HashSet<>());
+ final Set childShardIds =
+ shardIdToChildShardIdsMap.computeIfAbsent(parentShardId, key -> new HashSet<>());
childShardIds.add(shardId);
}
final String adjacentParentShardId = shard.adjacentParentShardId();
if (adjacentParentShardId != null && shardIdToShardMap.containsKey(adjacentParentShardId)) {
- final Set childShardIds = shardIdToChildShardIdsMap.computeIfAbsent(adjacentParentShardId,
- key -> new HashSet<>());
+ final Set childShardIds =
+ shardIdToChildShardIdsMap.computeIfAbsent(adjacentParentShardId, key -> new HashSet<>());
childShardIds.add(shardId);
}
}
@@ -247,7 +275,8 @@ public class HierarchicalShardSyncer {
* @param initialPositionInStreamExtended
* @return ShardFilter shard filter for the corresponding position in the stream.
*/
- private static ShardFilter getShardFilterFromInitialPosition(InitialPositionInStreamExtended initialPositionInStreamExtended) {
+ private static ShardFilter getShardFilterFromInitialPosition(
+ InitialPositionInStreamExtended initialPositionInStreamExtended) {
ShardFilter.Builder builder = ShardFilter.builder();
switch (initialPositionInStreamExtended.getInitialPositionInStream()) {
@@ -258,14 +287,17 @@ public class HierarchicalShardSyncer {
builder = builder.type(ShardFilterType.AT_TRIM_HORIZON);
break;
case AT_TIMESTAMP:
- builder = builder.type(ShardFilterType.AT_TIMESTAMP).timestamp(initialPositionInStreamExtended.getTimestamp().toInstant());
+ builder = builder.type(ShardFilterType.AT_TIMESTAMP)
+ .timestamp(
+ initialPositionInStreamExtended.getTimestamp().toInstant());
break;
}
return builder.build();
}
- private static List getShardListAtInitialPosition(@NonNull final ShardDetector shardDetector,
- InitialPositionInStreamExtended initialPositionInStreamExtended) throws KinesisClientLibIOException, InterruptedException {
+ private static List getShardListAtInitialPosition(
+ @NonNull final ShardDetector shardDetector, InitialPositionInStreamExtended initialPositionInStreamExtended)
+ throws KinesisClientLibIOException, InterruptedException {
final ShardFilter shardFilter = getShardFilterFromInitialPosition(initialPositionInStreamExtended);
final String streamName = shardDetector.streamIdentifier().streamName();
@@ -276,8 +308,8 @@ public class HierarchicalShardSyncer {
shards = shardDetector.listShardsWithFilter(shardFilter);
if (shards == null) {
- throw new KinesisClientLibIOException(
- "Stream " + streamName + " is not in ACTIVE OR UPDATING state - will retry getting the shard list.");
+ throw new KinesisClientLibIOException("Stream " + streamName
+ + " is not in ACTIVE OR UPDATING state - will retry getting the shard list.");
}
if (isHashRangeOfShardsComplete(shards)) {
@@ -287,13 +319,13 @@ public class HierarchicalShardSyncer {
Thread.sleep(DELAY_BETWEEN_LIST_SHARDS_MILLIS);
}
- throw new KinesisClientLibIOException("Hash range of shards returned for " + streamName + " was incomplete after "
- + RETRIES_FOR_COMPLETE_HASH_RANGE + " retries.");
+ throw new KinesisClientLibIOException("Hash range of shards returned for " + streamName
+ + " was incomplete after " + RETRIES_FOR_COMPLETE_HASH_RANGE + " retries.");
}
private List getShardList(@NonNull final ShardDetector shardDetector) throws KinesisClientLibIOException {
// Fallback to existing behavior for backward compatibility
- List shardList = Collections.emptyList();
+ List shardList = Collections.emptyList();
try {
shardList = shardDetector.listShardsWithoutConsumingResourceNotFoundException();
} catch (ResourceNotFoundException e) {
@@ -303,8 +335,9 @@ public class HierarchicalShardSyncer {
}
final Optional> shards = Optional.of(shardList);
- return shards.orElseThrow(() -> new KinesisClientLibIOException("Stream " + shardDetector.streamIdentifier().streamName() +
- " is not in ACTIVE OR UPDATING state - will retry getting the shard list."));
+ return shards.orElseThrow(() -> new KinesisClientLibIOException(
+ "Stream " + shardDetector.streamIdentifier().streamName()
+ + " is not in ACTIVE OR UPDATING state - will retry getting the shard list."));
}
private static boolean isHashRangeOfShardsComplete(@NonNull List shards) {
@@ -315,8 +348,8 @@ public class HierarchicalShardSyncer {
final Comparator shardStartingHashKeyBasedComparator = new ShardStartingHashKeyBasedComparator();
shards.sort(shardStartingHashKeyBasedComparator);
- if (!shards.get(0).hashKeyRange().startingHashKey().equals(MIN_HASH_KEY) ||
- !shards.get(shards.size() - 1).hashKeyRange().endingHashKey().equals(MAX_HASH_KEY)) {
+ if (!shards.get(0).hashKeyRange().startingHashKey().equals(MIN_HASH_KEY)
+ || !shards.get(shards.size() - 1).hashKeyRange().endingHashKey().equals(MAX_HASH_KEY)) {
return false;
}
@@ -324,11 +357,16 @@ public class HierarchicalShardSyncer {
for (int i = 1; i < shards.size(); i++) {
final Shard shardAtStartOfPossibleHole = shards.get(i - 1);
final Shard shardAtEndOfPossibleHole = shards.get(i);
- final BigInteger startOfPossibleHole = new BigInteger(shardAtStartOfPossibleHole.hashKeyRange().endingHashKey());
- final BigInteger endOfPossibleHole = new BigInteger(shardAtEndOfPossibleHole.hashKeyRange().startingHashKey());
+ final BigInteger startOfPossibleHole =
+ new BigInteger(shardAtStartOfPossibleHole.hashKeyRange().endingHashKey());
+ final BigInteger endOfPossibleHole =
+ new BigInteger(shardAtEndOfPossibleHole.hashKeyRange().startingHashKey());
if (!endOfPossibleHole.subtract(startOfPossibleHole).equals(BigInteger.ONE)) {
- log.error("Incomplete hash range found between {} and {}.", shardAtStartOfPossibleHole, shardAtEndOfPossibleHole);
+ log.error(
+ "Incomplete hash range found between {} and {}.",
+ shardAtStartOfPossibleHole,
+ shardAtEndOfPossibleHole);
return false;
}
}
@@ -350,10 +388,15 @@ public class HierarchicalShardSyncer {
* @param multiStreamArgs determines if we are using multistream mode.
* @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 MultiStreamArgs multiStreamArgs) {
- return leaseSynchronizer.determineNewLeasesToCreate(shards, currentLeases, initialPosition, inconsistentShardIds, multiStreamArgs);
+ static List determineNewLeasesToCreate(
+ final LeaseSynchronizer leaseSynchronizer,
+ final List shards,
+ final List currentLeases,
+ final InitialPositionInStreamExtended initialPosition,
+ final Set inconsistentShardIds,
+ final MultiStreamArgs multiStreamArgs) {
+ return leaseSynchronizer.determineNewLeasesToCreate(
+ shards, currentLeases, initialPosition, inconsistentShardIds, multiStreamArgs);
}
/**
@@ -368,10 +411,18 @@ public class HierarchicalShardSyncer {
* @param inconsistentShardIds Set of child shard ids having open parents.
* @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,
+ static List determineNewLeasesToCreate(
+ final LeaseSynchronizer leaseSynchronizer,
+ final List shards,
+ final List currentLeases,
+ final InitialPositionInStreamExtended initialPosition,
final Set inconsistentShardIds) {
- return determineNewLeasesToCreate(leaseSynchronizer, shards, currentLeases, initialPosition, inconsistentShardIds,
+ return determineNewLeasesToCreate(
+ leaseSynchronizer,
+ shards,
+ currentLeases,
+ initialPosition,
+ inconsistentShardIds,
new MultiStreamArgs(false, null));
}
@@ -386,10 +437,14 @@ public class HierarchicalShardSyncer {
* location in the shard (when an application starts up for the first time - and there are no checkpoints).
* @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) {
+ static List determineNewLeasesToCreate(
+ final LeaseSynchronizer leaseSynchronizer,
+ final List shards,
+ final List currentLeases,
+ final InitialPositionInStreamExtended initialPosition) {
final Set inconsistentShardIds = new HashSet<>();
- return determineNewLeasesToCreate(leaseSynchronizer, shards, currentLeases, initialPosition, inconsistentShardIds);
+ return determineNewLeasesToCreate(
+ leaseSynchronizer, shards, currentLeases, initialPosition, inconsistentShardIds);
}
/**
@@ -407,10 +462,13 @@ public class HierarchicalShardSyncer {
* @param memoizationContext Memoization of shards that have been evaluated as part of the evaluation
* @return true if the shard is a descendant of any current shard (lease already exists)
*/
- static boolean checkIfDescendantAndAddNewLeasesForAncestors(final String shardId,
- final InitialPositionInStreamExtended initialPosition, final Set shardIdsOfCurrentLeases,
+ static boolean checkIfDescendantAndAddNewLeasesForAncestors(
+ final String shardId,
+ final InitialPositionInStreamExtended initialPosition,
+ final Set shardIdsOfCurrentLeases,
final Map shardIdToShardMapOfAllKinesisShards,
- final Map shardIdToLeaseMapOfNewShards, final MemoizationContext memoizationContext,
+ final Map shardIdToLeaseMapOfNewShards,
+ final MemoizationContext memoizationContext,
final MultiStreamArgs multiStreamArgs) {
final String streamIdentifier = getStreamIdentifier(multiStreamArgs);
final Boolean previousValue = memoizationContext.isDescendant(shardId);
@@ -427,7 +485,10 @@ public class HierarchicalShardSyncer {
isDescendant = true;
// We don't need to add leases of its ancestors,
// because we'd have done it when creating a lease for this shard.
- log.debug("{} - Shard {} is a descendant shard of an existing shard. Skipping lease creation", streamIdentifier, shardId);
+ log.debug(
+ "{} - Shard {} is a descendant shard of an existing shard. Skipping lease creation",
+ streamIdentifier,
+ shardId);
} else {
final Shard shard = shardIdToShardMapOfAllKinesisShards.get(shardId);
@@ -436,9 +497,14 @@ public class HierarchicalShardSyncer {
// Check if the parent is a descendant, and include its ancestors. Or, if the parent is NOT a
// descendant but we should create a lease for it anyway (e.g. to include in processing from
// TRIM_HORIZON or AT_TIMESTAMP). If either is true, then we mark the current shard as a descendant.
- final boolean isParentDescendant = checkIfDescendantAndAddNewLeasesForAncestors(parentShardId,
- initialPosition, shardIdsOfCurrentLeases, shardIdToShardMapOfAllKinesisShards,
- shardIdToLeaseMapOfNewShards, memoizationContext, multiStreamArgs);
+ final boolean isParentDescendant = checkIfDescendantAndAddNewLeasesForAncestors(
+ parentShardId,
+ initialPosition,
+ shardIdsOfCurrentLeases,
+ shardIdToShardMapOfAllKinesisShards,
+ shardIdToLeaseMapOfNewShards,
+ memoizationContext,
+ multiStreamArgs);
if (isParentDescendant || memoizationContext.shouldCreateLease(parentShardId)) {
isDescendant = true;
descendantParentShardIds.add(parentShardId);
@@ -465,13 +531,17 @@ public class HierarchicalShardSyncer {
* therefore covered in the lease table). So we should create a lease for the parent.
*/
if (lease == null) {
- if (memoizationContext.shouldCreateLease(parentShardId) ||
- !descendantParentShardIds.contains(parentShardId)) {
- log.debug("{} : Need to create a lease for shardId {}", streamIdentifier, parentShardId);
- lease = multiStreamArgs.isMultiStreamMode() ?
- newKCLMultiStreamLease(shardIdToShardMapOfAllKinesisShards.get(parentShardId),
- multiStreamArgs.streamIdentifier()) :
- newKCLLease(shardIdToShardMapOfAllKinesisShards.get(parentShardId));
+ if (memoizationContext.shouldCreateLease(parentShardId)
+ || !descendantParentShardIds.contains(parentShardId)) {
+ log.debug(
+ "{} : Need to create a lease for shardId {}",
+ streamIdentifier,
+ parentShardId);
+ lease = multiStreamArgs.isMultiStreamMode()
+ ? newKCLMultiStreamLease(
+ shardIdToShardMapOfAllKinesisShards.get(parentShardId),
+ multiStreamArgs.streamIdentifier())
+ : newKCLLease(shardIdToShardMapOfAllKinesisShards.get(parentShardId));
shardIdToLeaseMapOfNewShards.put(parentShardId, lease);
}
}
@@ -502,15 +572,21 @@ public class HierarchicalShardSyncer {
*/
if (lease != null) {
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());
+ && !initialPosition
+ .getInitialPositionInStream()
+ .equals(InitialPositionInStream.AT_TIMESTAMP)) {
+ 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);
}
}
@@ -522,8 +598,9 @@ public class HierarchicalShardSyncer {
// lease just like we do for TRIM_HORIZON. However we will only return back records with server-side
// timestamp at or after the specified initial position timestamp.
if (initialPosition.getInitialPositionInStream().equals(InitialPositionInStream.TRIM_HORIZON)
- || initialPosition.getInitialPositionInStream()
- .equals(InitialPositionInStream.AT_TIMESTAMP)) {
+ || initialPosition
+ .getInitialPositionInStream()
+ .equals(InitialPositionInStream.AT_TIMESTAMP)) {
memoizationContext.setShouldCreateLease(shardId, true);
}
}
@@ -534,12 +611,20 @@ public class HierarchicalShardSyncer {
return isDescendant;
}
- static boolean checkIfDescendantAndAddNewLeasesForAncestors(final String shardId,
- final InitialPositionInStreamExtended initialPosition, final Set shardIdsOfCurrentLeases,
+ static boolean checkIfDescendantAndAddNewLeasesForAncestors(
+ final String shardId,
+ final InitialPositionInStreamExtended initialPosition,
+ final Set shardIdsOfCurrentLeases,
final Map shardIdToShardMapOfAllKinesisShards,
- final Map shardIdToLeaseMapOfNewShards, MemoizationContext memoizationContext) {
- return checkIfDescendantAndAddNewLeasesForAncestors(shardId, initialPosition, shardIdsOfCurrentLeases,
- shardIdToShardMapOfAllKinesisShards, shardIdToLeaseMapOfNewShards, memoizationContext,
+ final Map shardIdToLeaseMapOfNewShards,
+ MemoizationContext memoizationContext) {
+ return checkIfDescendantAndAddNewLeasesForAncestors(
+ shardId,
+ initialPosition,
+ shardIdsOfCurrentLeases,
+ shardIdToShardMapOfAllKinesisShards,
+ shardIdToLeaseMapOfNewShards,
+ memoizationContext,
new MultiStreamArgs(false, null));
}
@@ -552,8 +637,8 @@ public class HierarchicalShardSyncer {
* @param shardIdToShardMapOfAllKinesisShards ShardId->Shard map containing all shards obtained via DescribeStream.
* @return Set of parentShardIds
*/
- static Set getParentShardIds(final Shard shard,
- final Map shardIdToShardMapOfAllKinesisShards) {
+ static Set getParentShardIds(
+ final Shard shard, final Map shardIdToShardMapOfAllKinesisShards) {
final Set parentShardIds = new HashSet<>(2);
final String parentShardId = shard.parentShardId();
if (parentShardId != null && shardIdToShardMapOfAllKinesisShards.containsKey(parentShardId)) {
@@ -566,12 +651,13 @@ public class HierarchicalShardSyncer {
return parentShardIds;
}
- public synchronized Lease createLeaseForChildShard(final ChildShard childShard,
- final StreamIdentifier streamIdentifier) throws InvalidStateException {
+ public synchronized Lease createLeaseForChildShard(
+ final ChildShard childShard, final StreamIdentifier streamIdentifier) throws InvalidStateException {
final MultiStreamArgs multiStreamArgs = new MultiStreamArgs(isMultiStreamMode, streamIdentifier);
- return multiStreamArgs.isMultiStreamMode() ? newKCLMultiStreamLeaseForChildShard(childShard, streamIdentifier)
- : newKCLLeaseForChildShard(childShard);
+ return multiStreamArgs.isMultiStreamMode()
+ ? newKCLMultiStreamLeaseForChildShard(childShard, streamIdentifier)
+ : newKCLLeaseForChildShard(childShard);
}
/**
@@ -595,8 +681,8 @@ public class HierarchicalShardSyncer {
return newLease;
}
- private static Lease newKCLMultiStreamLeaseForChildShard(final ChildShard childShard,
- final StreamIdentifier streamIdentifier) throws InvalidStateException {
+ private static Lease newKCLMultiStreamLeaseForChildShard(
+ final ChildShard childShard, final StreamIdentifier streamIdentifier) throws InvalidStateException {
MultiStreamLease newLease = new MultiStreamLease();
newLease.leaseKey(MultiStreamLease.getLeaseKey(streamIdentifier.serialize(), childShard.shardId()));
if (!CollectionUtils.isNullOrEmpty(childShard.parentShards())) {
@@ -671,8 +757,10 @@ public class HierarchicalShardSyncer {
* @return List of open shards (shards at the tip of the stream) - may include shards that are not yet active.
*/
static List getOpenShards(final List allShards, final String streamIdentifier) {
- return allShards.stream().filter(shard -> shard.sequenceNumberRange().endingSequenceNumber() == null)
- .peek(shard -> log.debug("{} : Found open shard: {}", streamIdentifier, shard.shardId())).collect(Collectors.toList());
+ return allShards.stream()
+ .filter(shard -> shard.sequenceNumberRange().endingSequenceNumber() == null)
+ .peek(shard -> log.debug("{} : Found open shard: {}", streamIdentifier, shard.shardId()))
+ .collect(Collectors.toList());
}
private static ExtendedSequenceNumber convertToCheckpoint(final InitialPositionInStreamExtended position) {
@@ -691,7 +779,8 @@ public class HierarchicalShardSyncer {
private static String getStreamIdentifier(MultiStreamArgs multiStreamArgs) {
return Optional.ofNullable(multiStreamArgs.streamIdentifier())
- .map(streamId -> streamId.serialize()).orElse("single_stream_mode");
+ .map(streamId -> streamId.serialize())
+ .orElse("single_stream_mode");
}
/**
@@ -745,8 +834,10 @@ public class HierarchicalShardSyncer {
// If we found shards for the two leases, use comparison of the starting sequence numbers
if (shard1 != null && shard2 != null) {
- BigInteger sequenceNumber1 = new BigInteger(shard1.sequenceNumberRange().startingSequenceNumber());
- BigInteger sequenceNumber2 = new BigInteger(shard2.sequenceNumberRange().startingSequenceNumber());
+ BigInteger sequenceNumber1 =
+ new BigInteger(shard1.sequenceNumberRange().startingSequenceNumber());
+ BigInteger sequenceNumber2 =
+ new BigInteger(shard2.sequenceNumberRange().startingSequenceNumber());
result = sequenceNumber1.compareTo(sequenceNumber2);
}
@@ -780,9 +871,12 @@ public class HierarchicalShardSyncer {
* @param multiStreamArgs
* @return
*/
- List determineNewLeasesToCreate(List shards, List currentLeases,
- InitialPositionInStreamExtended initialPosition, Set inconsistentShardIds,
- MultiStreamArgs multiStreamArgs);
+ List determineNewLeasesToCreate(
+ List shards,
+ List currentLeases,
+ InitialPositionInStreamExtended initialPosition,
+ Set inconsistentShardIds,
+ MultiStreamArgs multiStreamArgs);
}
/**
@@ -805,21 +899,29 @@ public class HierarchicalShardSyncer {
* @return
*/
@Override
- public List determineNewLeasesToCreate(List shards, List currentLeases,
- InitialPositionInStreamExtended initialPosition, Set inconsistentShardIds, MultiStreamArgs multiStreamArgs) {
+ public List determineNewLeasesToCreate(
+ List shards,
+ List currentLeases,
+ InitialPositionInStreamExtended initialPosition,
+ Set inconsistentShardIds,
+ MultiStreamArgs multiStreamArgs) {
final String streamIdentifier = Optional.ofNullable(multiStreamArgs.streamIdentifier())
- .map(streamId -> streamId.serialize()).orElse("");
+ .map(streamId -> streamId.serialize())
+ .orElse("");
final Map shardIdToShardMapOfAllKinesisShards = constructShardIdToShardMap(shards);
- currentLeases.stream().peek(lease -> log.debug("{} : Existing lease: {}", streamIdentifier, lease))
+ currentLeases.stream()
+ .peek(lease -> log.debug("{} : Existing lease: {}", streamIdentifier, lease))
.map(lease -> getShardIdFromLease(lease, multiStreamArgs))
.collect(Collectors.toSet());
- final List newLeasesToCreate = getLeasesToCreateForOpenAndClosedShards(initialPosition, shards, multiStreamArgs, streamIdentifier);
+ final List newLeasesToCreate =
+ getLeasesToCreateForOpenAndClosedShards(initialPosition, shards, multiStreamArgs, streamIdentifier);
- //TODO: Verify before LTR launch that ending sequence number is still returned from the service.
+ // TODO: Verify before LTR launch that ending sequence number is still returned from the service.
final Comparator startingSequenceNumberComparator =
- new StartingSequenceNumberAndShardIdBasedComparator(shardIdToShardMapOfAllKinesisShards, multiStreamArgs);
+ new StartingSequenceNumberAndShardIdBasedComparator(
+ shardIdToShardMapOfAllKinesisShards, multiStreamArgs);
newLeasesToCreate.sort(startingSequenceNumberComparator);
return newLeasesToCreate;
}
@@ -829,14 +931,18 @@ public class HierarchicalShardSyncer {
* regardless of if they are open or closed. Closed shards will be unblocked via child shard information upon
* reaching SHARD_END.
*/
- private List getLeasesToCreateForOpenAndClosedShards(InitialPositionInStreamExtended initialPosition,
- List shards, MultiStreamArgs multiStreamArgs, String streamId) {
+ private List getLeasesToCreateForOpenAndClosedShards(
+ InitialPositionInStreamExtended initialPosition,
+ List shards,
+ MultiStreamArgs multiStreamArgs,
+ String streamId) {
final Map shardIdToNewLeaseMap = new HashMap<>();
for (Shard shard : shards) {
final String shardId = shard.shardId();
- final Lease lease = multiStreamArgs.isMultiStreamMode() ?
- newKCLMultiStreamLease(shard, multiStreamArgs.streamIdentifier) : newKCLLease(shard);
+ final Lease lease = multiStreamArgs.isMultiStreamMode()
+ ? newKCLMultiStreamLease(shard, multiStreamArgs.streamIdentifier)
+ : newKCLLease(shard);
lease.checkpoint(convertToCheckpoint(initialPosition));
log.debug("{} : Need to create a lease for shard with shardId {}", streamId, shardId);
@@ -909,13 +1015,17 @@ public class HierarchicalShardSyncer {
* @return List of new leases to create sorted by starting sequenceNumber of the corresponding shard
*/
@Override
- public synchronized List determineNewLeasesToCreate(final List shards, final List currentLeases,
- final InitialPositionInStreamExtended initialPosition, final Set inconsistentShardIds,
+ public synchronized List determineNewLeasesToCreate(
+ final List shards,
+ final List currentLeases,
+ final InitialPositionInStreamExtended initialPosition,
+ final Set inconsistentShardIds,
final MultiStreamArgs multiStreamArgs) {
final Map shardIdToNewLeaseMap = new HashMap<>();
final Map shardIdToShardMapOfAllKinesisShards = constructShardIdToShardMap(shards);
final String streamIdentifier = Optional.ofNullable(multiStreamArgs.streamIdentifier())
- .map(streamId -> streamId.serialize()).orElse("");
+ .map(streamId -> streamId.serialize())
+ .orElse("");
final Set shardIdsOfCurrentLeases = currentLeases.stream()
.peek(lease -> log.debug("{} : Existing lease: {}", streamIdentifier, lease))
.map(lease -> getShardIdFromLease(lease, multiStreamArgs))
@@ -929,9 +1039,15 @@ public class HierarchicalShardSyncer {
final String shardId = shard.shardId();
log.debug("{} : Evaluating leases for open shard {} and its ancestors.", streamIdentifier, shardId);
if (shardIdsOfCurrentLeases.contains(shardId)) {
- log.debug("{} : Lease for shardId {} already exists. Not creating a lease", streamIdentifier, shardId);
+ log.debug(
+ "{} : Lease for shardId {} already exists. Not creating a lease",
+ streamIdentifier,
+ shardId);
} else if (inconsistentShardIds.contains(shardId)) {
- log.info("{} : shardId {} is an inconsistent child. Not creating a lease", streamIdentifier, shardId);
+ log.info(
+ "{} : shardId {} is an inconsistent child. Not creating a lease",
+ streamIdentifier,
+ shardId);
} else {
log.debug("{} : Beginning traversal of ancestry tree for shardId {}", streamIdentifier, shardId);
@@ -939,9 +1055,14 @@ public class HierarchicalShardSyncer {
// We will create leases for only one level in the ancestry tree. Once we find the first ancestor
// that needs to be processed in order to complete the hash range, we will not create leases for
// further descendants of that ancestor.
- final boolean isDescendant = checkIfDescendantAndAddNewLeasesForAncestors(shardId, initialPosition,
- shardIdsOfCurrentLeases, shardIdToShardMapOfAllKinesisShards, shardIdToNewLeaseMap,
- memoizationContext, multiStreamArgs);
+ final boolean isDescendant = checkIfDescendantAndAddNewLeasesForAncestors(
+ shardId,
+ initialPosition,
+ shardIdsOfCurrentLeases,
+ shardIdToShardMapOfAllKinesisShards,
+ shardIdToNewLeaseMap,
+ memoizationContext,
+ multiStreamArgs);
// If shard is a descendant, the leases for its ancestors were already created above. Open shards
// that are NOT descendants will not have leases yet, so we create them here. We will not create
@@ -949,22 +1070,30 @@ public class HierarchicalShardSyncer {
// SHARD_END of their parents.
if (!isDescendant) {
log.debug("{} : shardId {} has no ancestors. Creating a lease.", streamIdentifier, shardId);
- final Lease newLease = multiStreamArgs.isMultiStreamMode() ?
- newKCLMultiStreamLease(shard, multiStreamArgs.streamIdentifier()) :
- newKCLLease(shard);
+ final Lease newLease = multiStreamArgs.isMultiStreamMode()
+ ? newKCLMultiStreamLease(shard, multiStreamArgs.streamIdentifier())
+ : newKCLLease(shard);
newLease.checkpoint(convertToCheckpoint(initialPosition));
- log.debug("{} : Set checkpoint of {} to {}", streamIdentifier, newLease.leaseKey(), newLease.checkpoint());
+ log.debug(
+ "{} : Set checkpoint of {} to {}",
+ streamIdentifier,
+ newLease.leaseKey(),
+ newLease.checkpoint());
shardIdToNewLeaseMap.put(shardId, newLease);
} else {
- log.debug("{} : shardId {} is a descendant whose ancestors should already have leases. " +
- "Not creating a lease.", streamIdentifier, shardId);
+ log.debug(
+ "{} : shardId {} is a descendant whose ancestors should already have leases. "
+ + "Not creating a lease.",
+ streamIdentifier,
+ shardId);
}
}
}
final List newLeasesToCreate = new ArrayList<>(shardIdToNewLeaseMap.values());
- final Comparator startingSequenceNumberComparator = new StartingSequenceNumberAndShardIdBasedComparator(
- shardIdToShardMapOfAllKinesisShards, multiStreamArgs);
+ final Comparator startingSequenceNumberComparator =
+ new StartingSequenceNumberAndShardIdBasedComparator(
+ shardIdToShardMapOfAllKinesisShards, multiStreamArgs);
newLeasesToCreate.sort(startingSequenceNumberComparator);
return newLeasesToCreate;
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/KinesisShardDetector.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/KinesisShardDetector.java
index e2336562..d128fc95 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/KinesisShardDetector.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/KinesisShardDetector.java
@@ -27,6 +27,7 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
+
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
@@ -82,8 +83,11 @@ public class KinesisShardDetector implements ShardDetector {
@NonNull
private final KinesisAsyncClient kinesisClient;
- @NonNull @Getter
+
+ @NonNull
+ @Getter
private final StreamIdentifier streamIdentifier;
+
private final long listShardsBackoffTimeInMillis;
private final int maxListShardsRetryAttempts;
private final long listShardsCacheAllowedAgeInSeconds;
@@ -93,23 +97,41 @@ public class KinesisShardDetector implements ShardDetector {
private volatile Map cachedShardMap = null;
private volatile Instant lastCacheUpdateTime;
+
@Getter(AccessLevel.PACKAGE)
private final AtomicInteger cacheMisses = new AtomicInteger(0);
private static final Boolean THROW_RESOURCE_NOT_FOUND_EXCEPTION = true;
@Deprecated
- public KinesisShardDetector(KinesisAsyncClient kinesisClient, String streamName, long listShardsBackoffTimeInMillis,
- int maxListShardsRetryAttempts, long listShardsCacheAllowedAgeInSeconds, int maxCacheMissesBeforeReload,
+ public KinesisShardDetector(
+ KinesisAsyncClient kinesisClient,
+ String streamName,
+ long listShardsBackoffTimeInMillis,
+ int maxListShardsRetryAttempts,
+ long listShardsCacheAllowedAgeInSeconds,
+ int maxCacheMissesBeforeReload,
int cacheMissWarningModulus) {
- this(kinesisClient, StreamIdentifier.singleStreamInstance(streamName), listShardsBackoffTimeInMillis, maxListShardsRetryAttempts,
- listShardsCacheAllowedAgeInSeconds, maxCacheMissesBeforeReload, cacheMissWarningModulus,
+ this(
+ kinesisClient,
+ StreamIdentifier.singleStreamInstance(streamName),
+ listShardsBackoffTimeInMillis,
+ maxListShardsRetryAttempts,
+ listShardsCacheAllowedAgeInSeconds,
+ maxCacheMissesBeforeReload,
+ cacheMissWarningModulus,
LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT);
}
- public KinesisShardDetector(KinesisAsyncClient kinesisClient, StreamIdentifier streamIdentifier, long listShardsBackoffTimeInMillis,
- int maxListShardsRetryAttempts, long listShardsCacheAllowedAgeInSeconds, int maxCacheMissesBeforeReload,
- int cacheMissWarningModulus, Duration kinesisRequestTimeout) {
+ public KinesisShardDetector(
+ KinesisAsyncClient kinesisClient,
+ StreamIdentifier streamIdentifier,
+ long listShardsBackoffTimeInMillis,
+ int maxListShardsRetryAttempts,
+ long listShardsCacheAllowedAgeInSeconds,
+ int maxCacheMissesBeforeReload,
+ int cacheMissWarningModulus,
+ Duration kinesisRequestTimeout) {
this.kinesisClient = kinesisClient;
this.streamIdentifier = streamIdentifier;
this.listShardsBackoffTimeInMillis = listShardsBackoffTimeInMillis;
@@ -143,8 +165,10 @@ public class KinesisShardDetector implements ShardDetector {
shard = cachedShardMap.get(shardId);
if (shard == null) {
- log.warn("Even after cache refresh shard '{}' wasn't found. This could indicate a bigger"
- + " problem.", shardId);
+ log.warn(
+ "Even after cache refresh shard '{}' wasn't found. This could indicate a bigger"
+ + " problem.",
+ shardId);
}
cacheMisses.set(0);
@@ -159,8 +183,8 @@ public class KinesisShardDetector implements ShardDetector {
}
if (shard == null) {
- final String message = String.format("Cannot find the shard given the shardId %s. Cache misses: %s",
- shardId, cacheMisses);
+ final String message =
+ String.format("Cannot find the shard given the shardId %s. Cache misses: %s", shardId, cacheMisses);
if (cacheMisses.get() % cacheMissWarningModulus == 0) {
log.warn(message);
} else {
@@ -189,8 +213,8 @@ public class KinesisShardDetector implements ShardDetector {
return listShardsWithFilterInternal(shardFilter, !THROW_RESOURCE_NOT_FOUND_EXCEPTION);
}
- private List listShardsWithFilterInternal(ShardFilter shardFilter,
- boolean shouldPropagateResourceNotFoundException) {
+ private List listShardsWithFilterInternal(
+ ShardFilter shardFilter, boolean shouldPropagateResourceNotFoundException) {
final List shards = new ArrayList<>();
ListShardsResponse result;
String nextToken = null;
@@ -218,8 +242,8 @@ public class KinesisShardDetector implements ShardDetector {
* @param shouldPropagateResourceNotFoundException : used to determine if ResourceNotFoundException should be
* handled by method and return Empty list or propagate the exception.
*/
- private ListShardsResponse listShards(ShardFilter shardFilter, final String nextToken,
- final boolean shouldPropagateResourceNotFoundException) {
+ private ListShardsResponse listShards(
+ ShardFilter shardFilter, final String nextToken, final boolean shouldPropagateResourceNotFoundException) {
ListShardsRequest.Builder builder = KinesisRequestsBuilder.listShardsRequestBuilder();
if (StringUtils.isEmpty(nextToken)) {
builder.streamName(streamIdentifier.streamName()).shardFilter(shardFilter);
@@ -250,7 +274,9 @@ public class KinesisShardDetector implements ShardDetector {
+ " Active or Updating)");
return null;
} catch (LimitExceededException e) {
- log.info("Got LimitExceededException when listing shards {}. Backing off for {} millis.", streamIdentifier,
+ log.info(
+ "Got LimitExceededException when listing shards {}. Backing off for {} millis.",
+ streamIdentifier,
listShardsBackoffTimeInMillis);
try {
Thread.sleep(listShardsBackoffTimeInMillis);
@@ -259,15 +285,16 @@ public class KinesisShardDetector implements ShardDetector {
}
lastException = e;
} catch (ResourceNotFoundException e) {
- log.warn("Got ResourceNotFoundException when fetching shard list for {}. Stream no longer exists.",
+ log.warn(
+ "Got ResourceNotFoundException when fetching shard list for {}. Stream no longer exists.",
streamIdentifier.streamName());
if (shouldPropagateResourceNotFoundException) {
throw e;
}
return ListShardsResponse.builder()
- .shards(Collections.emptyList())
- .nextToken(null)
- .build();
+ .shards(Collections.emptyList())
+ .nextToken(null)
+ .build();
} catch (TimeoutException te) {
throw new RuntimeException(te);
@@ -301,8 +328,8 @@ public class KinesisShardDetector implements ShardDetector {
}
@Override
- public ListShardsResponse getListShardsResponse(ListShardsRequest request) throws
- ExecutionException, TimeoutException, InterruptedException {
+ public ListShardsResponse getListShardsResponse(ListShardsRequest request)
+ throws ExecutionException, TimeoutException, InterruptedException {
return FutureUtils.resolveOrCancelFuture(kinesisClient.listShards(request), kinesisRequestTimeout);
}
@@ -317,16 +344,14 @@ public class KinesisShardDetector implements ShardDetector {
streamIdentifier.streamArnOptional().ifPresent(arn -> getShardIteratorRequestBuilder.streamARN(arn.toString()));
final GetShardIteratorResponse getShardIteratorResponse = FutureUtils.resolveOrCancelFuture(
- kinesisClient.getShardIterator(getShardIteratorRequestBuilder.build()),
- kinesisRequestTimeout);
+ kinesisClient.getShardIterator(getShardIteratorRequestBuilder.build()), kinesisRequestTimeout);
final GetRecordsRequest.Builder getRecordsRequestBuilder = KinesisRequestsBuilder.getRecordsRequestBuilder()
.shardIterator(getShardIteratorResponse.shardIterator());
streamIdentifier.streamArnOptional().ifPresent(arn -> getRecordsRequestBuilder.streamARN(arn.toString()));
final GetRecordsResponse getRecordsResponse = FutureUtils.resolveOrCancelFuture(
- kinesisClient.getRecords(getRecordsRequestBuilder.build()),
- kinesisRequestTimeout);
+ kinesisClient.getRecords(getRecordsRequestBuilder.build()), kinesisRequestTimeout);
return getRecordsResponse.childShards();
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/Lease.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/Lease.java
index b1602eb8..01735f9c 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/Lease.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/Lease.java
@@ -19,6 +19,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
+
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -39,12 +40,19 @@ import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
@NoArgsConstructor
@Getter
@Accessors(fluent = true)
-@EqualsAndHashCode(exclude = {"concurrencyToken", "lastCounterIncrementNanos", "childShardIds", "pendingCheckpointState", "isMarkedForLeaseSteal"})
+@EqualsAndHashCode(
+ exclude = {
+ "concurrencyToken",
+ "lastCounterIncrementNanos",
+ "childShardIds",
+ "pendingCheckpointState",
+ "isMarkedForLeaseSteal"
+ })
@ToString
public class Lease {
/**
* See javadoc for System.nanoTime - summary:
- *
+ *
* Sometimes System.nanoTime's return values will wrap due to overflow. When they do, the difference between two
* values will be very large. We will consider leases to be expired if they are more than a year old.
*/
@@ -100,36 +108,71 @@ public class Lease {
* Count of distinct lease holders between checkpoints.
*/
private Long ownerSwitchesSinceCheckpoint = 0L;
+
private final Set parentShardIds = new HashSet<>();
private final Set childShardIds = new HashSet<>();
private HashKeyRangeForLease hashKeyRangeForLease;
/**
* Copy constructor, used by clone().
- *
+ *
* @param lease lease to copy
*/
protected Lease(Lease lease) {
- this(lease.leaseKey(), lease.leaseOwner(), lease.leaseCounter(), lease.concurrencyToken(),
- lease.lastCounterIncrementNanos(), lease.checkpoint(), lease.pendingCheckpoint(),
- lease.ownerSwitchesSinceCheckpoint(), lease.parentShardIds(), lease.childShardIds(),
- lease.pendingCheckpointState(), lease.hashKeyRangeForLease());
+ this(
+ lease.leaseKey(),
+ lease.leaseOwner(),
+ lease.leaseCounter(),
+ lease.concurrencyToken(),
+ lease.lastCounterIncrementNanos(),
+ lease.checkpoint(),
+ lease.pendingCheckpoint(),
+ lease.ownerSwitchesSinceCheckpoint(),
+ lease.parentShardIds(),
+ lease.childShardIds(),
+ lease.pendingCheckpointState(),
+ lease.hashKeyRangeForLease());
}
@Deprecated
- public Lease(final String leaseKey, final String leaseOwner, final Long leaseCounter,
- final UUID concurrencyToken, final Long lastCounterIncrementNanos,
- final ExtendedSequenceNumber checkpoint, final ExtendedSequenceNumber pendingCheckpoint,
- final Long ownerSwitchesSinceCheckpoint, final Set parentShardIds) {
- this(leaseKey, leaseOwner, leaseCounter, concurrencyToken, lastCounterIncrementNanos, checkpoint, pendingCheckpoint,
- ownerSwitchesSinceCheckpoint, parentShardIds, new HashSet<>(), null, null);
+ public Lease(
+ final String leaseKey,
+ final String leaseOwner,
+ final Long leaseCounter,
+ final UUID concurrencyToken,
+ final Long lastCounterIncrementNanos,
+ final ExtendedSequenceNumber checkpoint,
+ final ExtendedSequenceNumber pendingCheckpoint,
+ final Long ownerSwitchesSinceCheckpoint,
+ final Set parentShardIds) {
+ this(
+ leaseKey,
+ leaseOwner,
+ leaseCounter,
+ concurrencyToken,
+ lastCounterIncrementNanos,
+ checkpoint,
+ pendingCheckpoint,
+ ownerSwitchesSinceCheckpoint,
+ parentShardIds,
+ new HashSet<>(),
+ null,
+ null);
}
- public Lease(final String leaseKey, final String leaseOwner, final Long leaseCounter,
- final UUID concurrencyToken, final Long lastCounterIncrementNanos,
- final ExtendedSequenceNumber checkpoint, final ExtendedSequenceNumber pendingCheckpoint,
- final Long ownerSwitchesSinceCheckpoint, final Set parentShardIds, final Set childShardIds,
- final byte[] pendingCheckpointState, final HashKeyRangeForLease hashKeyRangeForLease) {
+ public Lease(
+ final String leaseKey,
+ final String leaseOwner,
+ final Long leaseCounter,
+ final UUID concurrencyToken,
+ final Long lastCounterIncrementNanos,
+ final ExtendedSequenceNumber checkpoint,
+ final ExtendedSequenceNumber pendingCheckpoint,
+ final Long ownerSwitchesSinceCheckpoint,
+ final Set parentShardIds,
+ final Set childShardIds,
+ final byte[] pendingCheckpointState,
+ final HashKeyRangeForLease hashKeyRangeForLease) {
this.leaseKey = leaseKey;
this.leaseOwner = leaseOwner;
this.leaseCounter = leaseCounter;
@@ -159,7 +202,7 @@ public class Lease {
/**
* Updates this Lease's mutable, application-specific fields based on the passed-in lease object. Does not update
* fields that are internal to the leasing library (leaseKey, leaseOwner, leaseCounter).
- *
+ *
* @param lease
*/
public void update(final Lease lease) {
@@ -208,7 +251,7 @@ public class Lease {
/**
* Sets lastCounterIncrementNanos
- *
+ *
* @param lastCounterIncrementNanos last renewal in nanoseconds since the epoch
*/
public void lastCounterIncrementNanos(Long lastCounterIncrementNanos) {
@@ -217,7 +260,7 @@ public class Lease {
/**
* Sets concurrencyToken.
- *
+ *
* @param concurrencyToken may not be null
*/
public void concurrencyToken(@NonNull final UUID concurrencyToken) {
@@ -226,7 +269,7 @@ public class Lease {
/**
* Sets leaseKey. LeaseKey is immutable once set.
- *
+ *
* @param leaseKey may not be null.
*/
public void leaseKey(@NonNull final String leaseKey) {
@@ -238,7 +281,7 @@ public class Lease {
/**
* Sets leaseCounter.
- *
+ *
* @param leaseCounter may not be null
*/
public void leaseCounter(@NonNull final Long leaseCounter) {
@@ -314,7 +357,7 @@ public class Lease {
/**
* Sets leaseOwner.
- *
+ *
* @param leaseOwner may be null.
*/
public void leaseOwner(String leaseOwner) {
@@ -323,11 +366,10 @@ public class Lease {
/**
* Returns a deep copy of this object. Type-unsafe - there aren't good mechanisms for copy-constructing generics.
- *
+ *
* @return A deep copy of this object.
*/
public Lease copy() {
return new Lease(this);
}
-
}
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 861626b6..739732d2 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
@@ -15,6 +15,18 @@
package software.amazon.kinesis.leases;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Queue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
import lombok.EqualsAndHashCode;
@@ -28,40 +40,31 @@ import software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException;
import software.amazon.awssdk.utils.CollectionUtils;
import software.amazon.kinesis.common.StreamIdentifier;
import software.amazon.kinesis.leases.exceptions.DependencyException;
-import software.amazon.kinesis.leases.exceptions.LeasePendingDeletion;
import software.amazon.kinesis.leases.exceptions.InvalidStateException;
+import software.amazon.kinesis.leases.exceptions.LeasePendingDeletion;
import software.amazon.kinesis.leases.exceptions.ProvisionedThroughputException;
import software.amazon.kinesis.metrics.MetricsFactory;
import software.amazon.kinesis.retrieval.AWSExceptionManager;
import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Queue;
-import java.util.Set;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.stream.Collectors;
-
/**
* Helper class to cleanup of any expired/closed shard leases. It will cleanup leases periodically as defined by
* {@link LeaseManagementConfig#leaseCleanupConfig()} asynchronously.
*/
-@Accessors(fluent=true)
+@Accessors(fluent = true)
@Slf4j
@RequiredArgsConstructor
@EqualsAndHashCode
public class LeaseCleanupManager {
@NonNull
private final LeaseCoordinator leaseCoordinator;
+
@NonNull
private final MetricsFactory metricsFactory;
+
@NonNull
private final ScheduledExecutorService deletionThreadPool;
+
private final boolean cleanupLeasesUponShardCompletion;
private final long leaseCleanupIntervalMillis;
private final long completedLeaseCleanupIntervalMillis;
@@ -85,8 +88,8 @@ public class LeaseCleanupManager {
log.info("Starting lease cleanup thread.");
completedLeaseStopwatch.reset().start();
garbageLeaseStopwatch.reset().start();
- deletionThreadPool.scheduleAtFixedRate(new LeaseCleanupThread(), INITIAL_DELAY, leaseCleanupIntervalMillis,
- TimeUnit.MILLISECONDS);
+ deletionThreadPool.scheduleAtFixedRate(
+ new LeaseCleanupThread(), INITIAL_DELAY, leaseCleanupIntervalMillis, TimeUnit.MILLISECONDS);
isRunning = true;
} else {
log.info("Lease cleanup thread already running, no need to start.");
@@ -117,8 +120,10 @@ public class LeaseCleanupManager {
public void enqueueForDeletion(LeasePendingDeletion leasePendingDeletion) {
final Lease lease = leasePendingDeletion.lease();
if (lease == null) {
- log.warn("Cannot enqueue {} for {} as instance doesn't hold the lease for that shard.",
- leasePendingDeletion.shardInfo(), leasePendingDeletion.streamIdentifier());
+ log.warn(
+ "Cannot enqueue {} for {} as instance doesn't hold the lease for that shard.",
+ leasePendingDeletion.shardInfo(),
+ leasePendingDeletion.streamIdentifier());
} else {
log.debug("Enqueuing lease {} for deferred deletion.", lease.leaseKey());
if (!deletionQueue.add(leasePendingDeletion)) {
@@ -161,9 +166,12 @@ public class LeaseCleanupManager {
return garbageLeaseStopwatch.elapsed(TimeUnit.MILLISECONDS) >= garbageLeaseCleanupIntervalMillis;
}
- public LeaseCleanupResult cleanupLease(LeasePendingDeletion leasePendingDeletion,
- boolean timeToCheckForCompletedShard, boolean timeToCheckForGarbageShard) throws TimeoutException,
- InterruptedException, DependencyException, ProvisionedThroughputException, InvalidStateException {
+ public LeaseCleanupResult cleanupLease(
+ LeasePendingDeletion leasePendingDeletion,
+ boolean timeToCheckForCompletedShard,
+ boolean timeToCheckForGarbageShard)
+ throws TimeoutException, InterruptedException, DependencyException, ProvisionedThroughputException,
+ InvalidStateException {
final Lease lease = leasePendingDeletion.lease();
final ShardInfo shardInfo = leasePendingDeletion.shardInfo();
final StreamIdentifier streamIdentifier = leasePendingDeletion.streamIdentifier();
@@ -188,7 +196,8 @@ public class LeaseCleanupManager {
if (CollectionUtils.isNullOrEmpty(childShardKeys)) {
log.error(
"No child shards returned from service for shard {} for {} while cleaning up lease.",
- shardInfo.shardId(), streamIdentifier.streamName());
+ shardInfo.shardId(),
+ streamIdentifier.streamName());
} else {
wereChildShardsPresent = true;
updateLeaseWithChildShards(leasePendingDeletion, childShardKeys);
@@ -205,19 +214,25 @@ public class LeaseCleanupManager {
cleanedUpCompletedLease = cleanupLeaseForCompletedShard(lease, shardInfo, childShardKeys);
} catch (Exception e) {
// Suppressing the exception here, so that we can attempt for garbage cleanup.
- log.warn("Unable to cleanup lease for shard {} in {}", shardInfo.shardId(), streamIdentifier.streamName(), e);
+ log.warn(
+ "Unable to cleanup lease for shard {} in {}",
+ shardInfo.shardId(),
+ streamIdentifier.streamName(),
+ e);
}
} else {
- log.info("Lease not present in lease table while cleaning the shard {} of {}",
- shardInfo.shardId(), streamIdentifier.streamName());
+ log.info(
+ "Lease not present in lease table while cleaning the shard {} of {}",
+ shardInfo.shardId(),
+ streamIdentifier.streamName());
cleanedUpCompletedLease = true;
}
}
if (!alreadyCheckedForGarbageCollection && timeToCheckForGarbageShard) {
try {
- wereChildShardsPresent = !CollectionUtils
- .isNullOrEmpty(leasePendingDeletion.getChildShardsFromService());
+ wereChildShardsPresent =
+ !CollectionUtils.isNullOrEmpty(leasePendingDeletion.getChildShardsFromService());
} catch (ExecutionException e) {
throw exceptionManager.apply(e.getCause());
}
@@ -227,8 +242,8 @@ public class LeaseCleanupManager {
cleanedUpGarbageLease = cleanupLeaseForGarbageShard(lease, e);
}
- return new LeaseCleanupResult(cleanedUpCompletedLease, cleanedUpGarbageLease, wereChildShardsPresent,
- wasResourceNotFound);
+ return new LeaseCleanupResult(
+ cleanedUpCompletedLease, cleanedUpGarbageLease, wereChildShardsPresent, wasResourceNotFound);
}
// A lease that ended with SHARD_END from ResourceNotFoundException is safe to delete if it no longer exists in the
@@ -254,11 +269,15 @@ public class LeaseCleanupManager {
private boolean allParentShardLeasesDeleted(Lease lease, ShardInfo shardInfo)
throws DependencyException, ProvisionedThroughputException, InvalidStateException {
for (String parentShard : lease.parentShardIds()) {
- final Lease parentLease = leaseCoordinator.leaseRefresher().getLease(ShardInfo.getLeaseKey(shardInfo, parentShard));
+ final Lease parentLease =
+ leaseCoordinator.leaseRefresher().getLease(ShardInfo.getLeaseKey(shardInfo, parentShard));
if (parentLease != null) {
- log.warn("Lease {} has a parent lease {} which is still present in the lease table, skipping deletion " +
- "for this lease.", lease, parentLease);
+ log.warn(
+ "Lease {} has a parent lease {} which is still present in the lease table, skipping deletion "
+ + "for this lease.",
+ lease,
+ parentLease);
return false;
}
}
@@ -271,27 +290,29 @@ public class LeaseCleanupManager {
private boolean cleanupLeaseForCompletedShard(Lease lease, ShardInfo shardInfo, Set childShardKeys)
throws DependencyException, ProvisionedThroughputException, InvalidStateException, IllegalStateException {
final Set processedChildShardLeaseKeys = new HashSet<>();
- final Set childShardLeaseKeys = childShardKeys.stream().map(ck -> ShardInfo.getLeaseKey(shardInfo, ck))
+ final Set childShardLeaseKeys = childShardKeys.stream()
+ .map(ck -> ShardInfo.getLeaseKey(shardInfo, ck))
.collect(Collectors.toSet());
for (String childShardLeaseKey : childShardLeaseKeys) {
final Lease childShardLease = Optional.ofNullable(
- leaseCoordinator.leaseRefresher().getLease(childShardLeaseKey))
- .orElseThrow(() -> new IllegalStateException(
- "Child lease " + childShardLeaseKey + " for completed shard not found in "
- + "lease table - not cleaning up lease " + lease));
+ leaseCoordinator.leaseRefresher().getLease(childShardLeaseKey))
+ .orElseThrow(() -> new IllegalStateException("Child lease " + childShardLeaseKey
+ + " for completed shard not found in " + "lease table - not cleaning up lease " + lease));
- if (!childShardLease.checkpoint().equals(ExtendedSequenceNumber.TRIM_HORIZON) && !childShardLease
- .checkpoint().equals(ExtendedSequenceNumber.AT_TIMESTAMP)) {
+ if (!childShardLease.checkpoint().equals(ExtendedSequenceNumber.TRIM_HORIZON)
+ && !childShardLease.checkpoint().equals(ExtendedSequenceNumber.AT_TIMESTAMP)) {
processedChildShardLeaseKeys.add(childShardLease.leaseKey());
}
}
- if (!allParentShardLeasesDeleted(lease, shardInfo) || !Objects.equals(childShardLeaseKeys, processedChildShardLeaseKeys)) {
+ if (!allParentShardLeasesDeleted(lease, shardInfo)
+ || !Objects.equals(childShardLeaseKeys, processedChildShardLeaseKeys)) {
return false;
}
- log.info("Deleting lease {} as it has been completely processed and processing of child shard(s) has begun.",
+ log.info(
+ "Deleting lease {} as it has been completely processed and processing of child shard(s) has begun.",
lease);
leaseCoordinator.leaseRefresher().deleteLease(lease);
@@ -331,23 +352,36 @@ public class LeaseCleanupManager {
final StreamIdentifier streamIdentifier = leasePendingDeletion.streamIdentifier();
boolean deletionSucceeded = false;
try {
- final LeaseCleanupResult leaseCleanupResult = cleanupLease(leasePendingDeletion,
- timeToCheckForCompletedShard(), timeToCheckForGarbageShard());
+ final LeaseCleanupResult leaseCleanupResult = cleanupLease(
+ leasePendingDeletion, timeToCheckForCompletedShard(), timeToCheckForGarbageShard());
completedLeaseCleanedUp |= leaseCleanupResult.cleanedUpCompletedLease();
garbageLeaseCleanedUp |= leaseCleanupResult.cleanedUpGarbageLease();
if (leaseCleanupResult.leaseCleanedUp()) {
- log.info("Successfully cleaned up lease {} for {} due to {}", leaseKey, streamIdentifier, leaseCleanupResult);
+ log.info(
+ "Successfully cleaned up lease {} for {} due to {}",
+ leaseKey,
+ streamIdentifier,
+ leaseCleanupResult);
deletionSucceeded = true;
} else {
- log.warn("Unable to clean up lease {} for {} due to {}", leaseKey, streamIdentifier, leaseCleanupResult);
+ log.warn(
+ "Unable to clean up lease {} for {} due to {}",
+ leaseKey,
+ streamIdentifier,
+ leaseCleanupResult);
}
} catch (Exception e) {
- log.error("Failed to cleanup lease {} for {}. Will re-enqueue for deletion and retry on next " +
- "scheduled execution.", leaseKey, streamIdentifier, e);
+ log.error(
+ "Failed to cleanup lease {} for {}. Will re-enqueue for deletion and retry on next "
+ + "scheduled execution.",
+ leaseKey,
+ streamIdentifier,
+ e);
}
if (!deletionSucceeded) {
- log.debug("Did not cleanup lease {} for {}. Re-enqueueing for deletion.", leaseKey, streamIdentifier);
+ log.debug(
+ "Did not cleanup lease {} for {}. Re-enqueueing for deletion.", leaseKey, streamIdentifier);
failedDeletions.add(leasePendingDeletion);
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCoordinator.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCoordinator.java
index 6437f339..acc08dab 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCoordinator.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseCoordinator.java
@@ -136,7 +136,7 @@ public interface LeaseCoordinator {
* @return all leases for the application that are in the lease table
*/
default List allLeases() {
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
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 aef4d87e..c8c49a19 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
@@ -15,8 +15,6 @@
package software.amazon.kinesis.leases;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
import java.time.Duration;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
@@ -25,11 +23,12 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.Data;
import lombok.NonNull;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.Validate;
-
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import software.amazon.awssdk.services.dynamodb.model.BillingMode;
@@ -53,14 +52,16 @@ public class LeaseManagementConfig {
public static final Duration DEFAULT_REQUEST_TIMEOUT = Duration.ofMinutes(1);
- public static final long DEFAULT_LEASE_CLEANUP_INTERVAL_MILLIS = Duration.ofMinutes(1).toMillis();
- public static final long DEFAULT_COMPLETED_LEASE_CLEANUP_INTERVAL_MILLIS = Duration.ofMinutes(5).toMillis();
- public static final long DEFAULT_GARBAGE_LEASE_CLEANUP_INTERVAL_MILLIS = Duration.ofMinutes(30).toMillis();
+ public static final long DEFAULT_LEASE_CLEANUP_INTERVAL_MILLIS =
+ Duration.ofMinutes(1).toMillis();
+ public static final long DEFAULT_COMPLETED_LEASE_CLEANUP_INTERVAL_MILLIS =
+ Duration.ofMinutes(5).toMillis();
+ public static final long DEFAULT_GARBAGE_LEASE_CLEANUP_INTERVAL_MILLIS =
+ Duration.ofMinutes(30).toMillis();
public static final long DEFAULT_PERIODIC_SHARD_SYNC_INTERVAL_MILLIS = 2 * 60 * 1000L;
public static final boolean DEFAULT_ENABLE_PRIORITY_LEASE_ASSIGNMENT = true;
public static final int DEFAULT_CONSECUTIVE_HOLES_FOR_TRIGGERING_LEASE_RECOVERY = 3;
-
public static final LeaseCleanupConfig DEFAULT_LEASE_CLEANUP_CONFIG = LeaseCleanupConfig.builder()
.leaseCleanupIntervalMillis(DEFAULT_LEASE_CLEANUP_INTERVAL_MILLIS)
.completedLeaseCleanupIntervalMillis(DEFAULT_COMPLETED_LEASE_CLEANUP_INTERVAL_MILLIS)
@@ -232,7 +233,8 @@ public class LeaseManagementConfig {
* is inconsistent. If the auditor finds same set of inconsistencies consecutively for a stream for this many times,
* then it would trigger a shard sync.
*/
- private int leasesRecoveryAuditorInconsistencyConfidenceThreshold = DEFAULT_CONSECUTIVE_HOLES_FOR_TRIGGERING_LEASE_RECOVERY;
+ private int leasesRecoveryAuditorInconsistencyConfidenceThreshold =
+ DEFAULT_CONSECUTIVE_HOLES_FOR_TRIGGERING_LEASE_RECOVERY;
/**
* The initial position for getting records from Kinesis streams.
@@ -249,8 +251,12 @@ public class LeaseManagementConfig {
private MetricsFactory metricsFactory = new NullMetricsFactory();
@Deprecated
- public LeaseManagementConfig(String tableName, DynamoDbAsyncClient dynamoDBClient, KinesisAsyncClient kinesisClient,
- String streamName, String workerIdentifier) {
+ public LeaseManagementConfig(
+ String tableName,
+ DynamoDbAsyncClient dynamoDBClient,
+ KinesisAsyncClient kinesisClient,
+ String streamName,
+ String workerIdentifier) {
this.tableName = tableName;
this.dynamoDBClient = dynamoDBClient;
this.kinesisClient = kinesisClient;
@@ -258,7 +264,10 @@ public class LeaseManagementConfig {
this.workerIdentifier = workerIdentifier;
}
- public LeaseManagementConfig(String tableName, DynamoDbAsyncClient dynamoDBClient, KinesisAsyncClient kinesisClient,
+ public LeaseManagementConfig(
+ String tableName,
+ DynamoDbAsyncClient dynamoDBClient,
+ KinesisAsyncClient kinesisClient,
String workerIdentifier) {
this.tableName = tableName;
this.dynamoDBClient = dynamoDBClient;
@@ -302,14 +311,20 @@ public class LeaseManagementConfig {
*
* Default value: {@link LeaseManagementThreadPool}
*/
- private ExecutorService executorService = new LeaseManagementThreadPool(
- new ThreadFactoryBuilder().setNameFormat("ShardSyncTaskManager-%04d").build());
+ private ExecutorService executorService = new LeaseManagementThreadPool(new ThreadFactoryBuilder()
+ .setNameFormat("ShardSyncTaskManager-%04d")
+ .build());
static class LeaseManagementThreadPool extends ThreadPoolExecutor {
private static final long DEFAULT_KEEP_ALIVE_TIME = 60L;
LeaseManagementThreadPool(ThreadFactory threadFactory) {
- super(0, Integer.MAX_VALUE, DEFAULT_KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<>(),
+ super(
+ 0,
+ Integer.MAX_VALUE,
+ DEFAULT_KEEP_ALIVE_TIME,
+ TimeUnit.SECONDS,
+ new SynchronousQueue<>(),
threadFactory);
}
}
@@ -339,7 +354,8 @@ public class LeaseManagementConfig {
public LeaseManagementFactory leaseManagementFactory() {
if (leaseManagementFactory == null) {
Validate.notEmpty(streamName(), "Stream name is empty");
- leaseManagementFactory = new DynamoDBLeaseManagementFactory(kinesisClient(),
+ leaseManagementFactory = new DynamoDBLeaseManagementFactory(
+ kinesisClient(),
streamName(),
dynamoDBClient(),
tableName(),
@@ -363,7 +379,10 @@ public class LeaseManagementConfig {
initialLeaseTableReadCapacity(),
initialLeaseTableWriteCapacity(),
hierarchicalShardSyncer(),
- tableCreatorCallback(), dynamoDbRequestTimeout(), billingMode(), tags());
+ tableCreatorCallback(),
+ dynamoDbRequestTimeout(),
+ billingMode(),
+ tags());
}
return leaseManagementFactory;
}
@@ -374,9 +393,11 @@ public class LeaseManagementConfig {
* @param isMultiStreamingMode
* @return LeaseManagementFactory
*/
- public LeaseManagementFactory leaseManagementFactory(final LeaseSerializer leaseSerializer, boolean isMultiStreamingMode) {
+ public LeaseManagementFactory leaseManagementFactory(
+ final LeaseSerializer leaseSerializer, boolean isMultiStreamingMode) {
if (leaseManagementFactory == null) {
- leaseManagementFactory = new DynamoDBLeaseManagementFactory(kinesisClient(),
+ leaseManagementFactory = new DynamoDBLeaseManagementFactory(
+ kinesisClient(),
dynamoDBClient(),
tableName(),
workerIdentifier(),
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementFactory.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementFactory.java
index 9f2e5f94..9ed77a53 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementFactory.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseManagementFactory.java
@@ -32,7 +32,9 @@ public interface LeaseManagementFactory {
throw new UnsupportedOperationException();
}
- default ShardSyncTaskManager createShardSyncTaskManager(MetricsFactory metricsFactory, StreamConfig streamConfig,
+ default ShardSyncTaskManager createShardSyncTaskManager(
+ MetricsFactory metricsFactory,
+ StreamConfig streamConfig,
DeletedStreamListProvider deletedStreamListProvider) {
throw new UnsupportedOperationException("createShardSyncTaskManager method not implemented");
}
@@ -46,5 +48,4 @@ public interface LeaseManagementFactory {
}
LeaseCleanupManager createLeaseCleanupManager(MetricsFactory metricsFactory);
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRefresher.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRefresher.java
index 7ec5b5ec..c38d442a 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRefresher.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRefresher.java
@@ -47,31 +47,30 @@ public interface LeaseRefresher {
/**
* Creates the table that will store leases. Table is now created in PayPerRequest billing mode by default.
* Succeeds if table already exists.
- *
+ *
* @return true if we created a new table (table didn't exist before)
- *
+ *
* @throws ProvisionedThroughputException if we cannot create the lease table due to per-AWS-account capacity
* restrictions.
* @throws DependencyException if DynamoDB createTable fails in an unexpected way
*/
- boolean createLeaseTableIfNotExists()
- throws ProvisionedThroughputException, DependencyException;
+ boolean createLeaseTableIfNotExists() throws ProvisionedThroughputException, DependencyException;
/**
* @return true if the lease table already exists.
- *
+ *
* @throws DependencyException if DynamoDB describeTable fails in an unexpected way
*/
boolean leaseTableExists() throws DependencyException;
/**
* Blocks until the lease table exists by polling leaseTableExists.
- *
+ *
* @param secondsBetweenPolls time to wait between polls in seconds
* @param timeoutSeconds total time to wait in seconds
- *
+ *
* @return true if table exists, false if timeout was reached
- *
+ *
* @throws DependencyException if DynamoDB describeTable fails in an unexpected way
*/
boolean waitUntilLeaseTableExists(long secondsBetweenPolls, long timeoutSeconds) throws DependencyException;
@@ -85,41 +84,41 @@ public interface LeaseRefresher {
*
* @return list of leases
*/
- List listLeasesForStream(StreamIdentifier streamIdentifier) throws DependencyException, InvalidStateException,
- ProvisionedThroughputException;
+ List listLeasesForStream(StreamIdentifier streamIdentifier)
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* List all objects in table synchronously.
- *
+ *
* @throws DependencyException if DynamoDB scan fails in an unexpected way
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB scan fails due to lack of capacity
- *
+ *
* @return list of leases
*/
List listLeases() throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* Create a new lease. Conditional on a lease not already existing with this shardId.
- *
+ *
* @param lease the lease to create
- *
+ *
* @return true if lease was created, false if lease already exists
- *
+ *
* @throws DependencyException if DynamoDB put fails in an unexpected way
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB put fails due to lack of capacity
*/
boolean createLeaseIfNotExists(Lease lease)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException;
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* @param leaseKey Get the lease for this leasekey
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB get fails due to lack of capacity
* @throws DependencyException if DynamoDB get fails in an unexpected way
- *
+ *
* @return lease for the specified leaseKey, or null if one doesn't exist
*/
Lease getLease(String leaseKey) throws DependencyException, InvalidStateException, ProvisionedThroughputException;
@@ -127,55 +126,53 @@ public interface LeaseRefresher {
/**
* Renew a lease by incrementing the lease counter. Conditional on the leaseCounter in DynamoDB matching the leaseCounter
* of the input. Mutates the leaseCounter of the passed-in lease object after updating the record in DynamoDB.
- *
+ *
* @param lease the lease to renew
- *
+ *
* @return true if renewal succeeded, false otherwise
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB update fails due to lack of capacity
* @throws DependencyException if DynamoDB update fails in an unexpected way
*/
- boolean renewLease(Lease lease)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException;
+ boolean renewLease(Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* Take a lease for the given owner by incrementing its leaseCounter and setting its owner field. Conditional on
* the leaseCounter in DynamoDB matching the leaseCounter of the input. Mutates the leaseCounter and owner of the
* passed-in lease object after updating DynamoDB.
- *
+ *
* @param lease the lease to take
* @param owner the new owner
- *
+ *
* @return true if lease was successfully taken, false otherwise
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB update fails due to lack of capacity
* @throws DependencyException if DynamoDB update fails in an unexpected way
*/
boolean takeLease(Lease lease, String owner)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException;
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* Evict the current owner of lease by setting owner to null. Conditional on the owner in DynamoDB matching the owner of
* the input. Mutates the lease counter and owner of the passed-in lease object after updating the record in DynamoDB.
- *
+ *
* @param lease the lease to void
- *
+ *
* @return true if eviction succeeded, false otherwise
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB update fails due to lack of capacity
* @throws DependencyException if DynamoDB update fails in an unexpected way
*/
- boolean evictLease(Lease lease)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException;
+ boolean evictLease(Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* Delete the given lease from DynamoDB. Does nothing when passed a lease that does not exist in DynamoDB.
- *
+ *
* @param lease the lease to delete
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB delete fails due to lack of capacity
* @throws DependencyException if DynamoDB delete fails in an unexpected way
@@ -184,7 +181,7 @@ public interface LeaseRefresher {
/**
* Delete all leases from DynamoDB. Useful for tools/utils and testing.
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB scan or delete fail due to lack of capacity
* @throws DependencyException if DynamoDB scan or delete fail in an unexpected way
@@ -196,15 +193,14 @@ public interface LeaseRefresher {
* library such as leaseCounter, leaseOwner, or leaseKey. Conditional on the leaseCounter in DynamoDB matching the
* leaseCounter of the input. Increments the lease counter in DynamoDB so that updates can be contingent on other
* updates. Mutates the lease counter of the passed-in lease object.
- *
+ *
* @return true if update succeeded, false otherwise
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB update fails due to lack of capacity
* @throws DependencyException if DynamoDB update fails in an unexpected way
*/
- boolean updateLease(Lease lease)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException;
+ boolean updateLease(Lease lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* Update application-specific fields of the given lease in DynamoDB. Does not update fields managed by the leasing
@@ -221,9 +217,9 @@ public interface LeaseRefresher {
/**
* Check (synchronously) if there are any leases in the lease table.
- *
+ *
* @return true if there are no leases in the lease table
- *
+ *
* @throws DependencyException if DynamoDB scan fails in an unexpected way
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB scan fails due to lack of capacity
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRenewer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRenewer.java
index 25ec5b45..61d9643c 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRenewer.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseRenewer.java
@@ -28,18 +28,18 @@ import software.amazon.kinesis.leases.exceptions.ProvisionedThroughputException;
* that worker.
*/
public interface LeaseRenewer {
-
+
/**
* Bootstrap initial set of leases from the {@link LeaseRefresher} (e.g. upon process restart, pick up leases we own)
* @throws DependencyException on unexpected DynamoDB failures
* @throws InvalidStateException if lease table doesn't exist
* @throws ProvisionedThroughputException if DynamoDB reads fail due to insufficient capacity
*/
- void initialize() throws DependencyException, InvalidStateException, ProvisionedThroughputException;
+ void initialize() throws DependencyException, InvalidStateException, ProvisionedThroughputException;
/**
* Attempt to renew all currently held leases.
- *
+ *
* @throws DependencyException on unexpected DynamoDB failures
* @throws InvalidStateException if lease table does not exist
*/
@@ -54,7 +54,7 @@ public interface LeaseRenewer {
/**
* @param leaseKey key of the lease to retrieve
- *
+ *
* @return a deep copy of a currently held lease, or null if we don't hold the lease
*/
Lease getCurrentlyHeldLease(String leaseKey);
@@ -62,7 +62,7 @@ public interface LeaseRenewer {
/**
* Adds leases to this LeaseRenewer's set of currently held leases. Leases must have lastRenewalNanos set to the
* last time the lease counter was incremented before being passed to this method.
- *
+ *
* @param newLeases new leases.
*/
void addLeasesToRenew(Collection newLeases);
@@ -74,7 +74,7 @@ public interface LeaseRenewer {
/**
* Stops the lease renewer from continunig to maintain the given lease.
- *
+ *
* @param lease the lease to drop.
*/
void dropLease(Lease lease);
@@ -83,20 +83,19 @@ public interface LeaseRenewer {
* Update application-specific fields in a currently held lease. Cannot be used to update internal fields such as
* leaseCounter, leaseOwner, etc. Fails if we do not hold the lease, or if the concurrency token does not match
* the concurrency token on the internal authoritative copy of the lease (ie, if we lost and re-acquired the lease).
- *
+ *
* @param lease lease object containing updated data
* @param concurrencyToken obtained by calling Lease.concurrencyToken for a currently held lease
* @param operation that performs updateLease
* @param singleStreamShardId shardId for metrics emission in single stream mode. MultiStream mode will get the
* shardId from the lease object
- *
+ *
* @return true if update succeeds, false otherwise
- *
+ *
* @throws InvalidStateException if lease table does not exist
* @throws ProvisionedThroughputException if DynamoDB update fails due to lack of capacity
* @throws DependencyException if DynamoDB update fails in an unexpected way
*/
boolean updateLease(Lease lease, UUID concurrencyToken, String operation, String singleStreamShardId)
throws DependencyException, InvalidStateException, ProvisionedThroughputException;
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseSerializer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseSerializer.java
index f36f5a66..5d7bea63 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseSerializer.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseSerializer.java
@@ -16,6 +16,7 @@ package software.amazon.kinesis.leases;
import java.util.Collection;
import java.util.Map;
+
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate;
@@ -29,7 +30,7 @@ public interface LeaseSerializer {
/**
* Construct a DynamoDB record out of a Lease object
- *
+ *
* @param lease lease object to serialize
* @return an attribute value map representing the lease object
*/
@@ -37,13 +38,12 @@ public interface LeaseSerializer {
/**
* Construct a Lease object out of a DynamoDB record.
- *
+ *
* @param dynamoRecord attribute value map from DynamoDB
* @return a deserialized lease object representing the attribute value map
*/
Lease fromDynamoRecord(Map dynamoRecord);
-
default Lease fromDynamoRecord(Map dynamoRecord, Lease leaseToUpdate) {
throw new UnsupportedOperationException();
}
@@ -56,7 +56,7 @@ public interface LeaseSerializer {
/**
* Special getDynamoHashKey implementation used by {@link LeaseRefresher#getLease(String)}.
- *
+ *
* @param leaseKey
* @return the attribute value map representing a Lease's hash key given a string.
*/
@@ -131,5 +131,4 @@ public interface LeaseSerializer {
* @return attribute definitions for creating a DynamoDB table to store leases
*/
Collection getAttributeDefinitions();
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseTaker.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseTaker.java
index ead8c195..2d082edb 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseTaker.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/LeaseTaker.java
@@ -29,14 +29,14 @@ public interface LeaseTaker {
/**
* Compute the set of leases available to be taken and attempt to take them. Lease taking rules are:
- *
+ *
* 1) If a lease's counter hasn't changed in long enough, try to take it.
* 2) If we see a lease we've never seen before, take it only if owner == null. If it's owned, odds are the owner is
* holding it. We can't tell until we see it more than once.
* 3) For load balancing purposes, you may violate rules 1 and 2 for EXACTLY ONE lease per call of takeLeases().
- *
+ *
* @return map of shardId to Lease object for leases we just successfully took.
- *
+ *
* @throws DependencyException on unexpected DynamoDB failures
* @throws InvalidStateException if lease table does not exist
*/
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 c79cc458..36e108c5 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
@@ -32,8 +32,11 @@ import static com.google.common.base.Verify.verifyNotNull;
@EqualsAndHashCode(callSuper = true)
public class MultiStreamLease extends Lease {
- @NonNull private String streamIdentifier;
- @NonNull private String shardId;
+ @NonNull
+ private String streamIdentifier;
+
+ @NonNull
+ private String shardId;
public MultiStreamLease(MultiStreamLease other) {
super(other);
@@ -74,5 +77,4 @@ public class MultiStreamLease extends Lease {
Validate.isInstanceOf(MultiStreamLease.class, lease);
return (MultiStreamLease) lease;
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/NoOpShardPrioritization.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/NoOpShardPrioritization.java
index 9b97086d..2944e2d1 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/NoOpShardPrioritization.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/NoOpShardPrioritization.java
@@ -19,14 +19,12 @@ import java.util.List;
/**
* Shard Prioritization that returns the same original list of shards without any modifications.
*/
-public class NoOpShardPrioritization implements
- ShardPrioritization {
+public class NoOpShardPrioritization implements ShardPrioritization {
/**
* Empty constructor for NoOp Shard Prioritization.
*/
- public NoOpShardPrioritization() {
- }
+ public NoOpShardPrioritization() {}
@Override
public List prioritize(List original) {
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ParentsFirstShardPrioritization.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ParentsFirstShardPrioritization.java
index b5796d96..02232ab2 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ParentsFirstShardPrioritization.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ParentsFirstShardPrioritization.java
@@ -25,8 +25,7 @@ import java.util.Map;
* It also limits number of shards that will be available for initialization based on their depth.
* It doesn't make a lot of sense to work on a shard that has too many unfinished parents.
*/
-public class ParentsFirstShardPrioritization implements
- ShardPrioritization {
+public class ParentsFirstShardPrioritization implements ShardPrioritization {
private static final SortingNode PROCESSING_NODE = new SortingNode(null, Integer.MIN_VALUE);
private final int maxDepth;
@@ -34,13 +33,13 @@ public class ParentsFirstShardPrioritization implements
/**
* Creates ParentFirst prioritization with filtering based on depth of the shard.
* Shards that have depth > maxDepth will be ignored and will not be returned by this prioritization.
- *
+ *
* @param maxDepth any shard that is deeper than max depth, will be excluded from processing
*/
public ParentsFirstShardPrioritization(int maxDepth) {
/* Depth 0 means that shard is completed or cannot be found,
- * it is impossible to process such shards.
- */
+ * it is impossible to process such shards.
+ */
if (maxDepth <= 0) {
throw new IllegalArgumentException("Max depth cannot be negative or zero. Provided value: " + maxDepth);
}
@@ -51,16 +50,13 @@ public class ParentsFirstShardPrioritization implements
public List prioritize(List original) {
Map shards = new HashMap<>();
for (ShardInfo shardInfo : original) {
- shards.put(shardInfo.shardId(),
- shardInfo);
+ shards.put(shardInfo.shardId(), shardInfo);
}
Map processedNodes = new HashMap<>();
for (ShardInfo shardInfo : original) {
- populateDepth(shardInfo.shardId(),
- shards,
- processedNodes);
+ populateDepth(shardInfo.shardId(), shards, processedNodes);
}
List orderedInfos = new ArrayList<>(original.size());
@@ -77,14 +73,12 @@ public class ParentsFirstShardPrioritization implements
return orderedInfos;
}
- private int populateDepth(String shardId,
- Map shards,
- Map processedNodes) {
+ private int populateDepth(String shardId, Map shards, Map processedNodes) {
SortingNode processed = processedNodes.get(shardId);
if (processed != null) {
if (processed == PROCESSING_NODE) {
- throw new IllegalArgumentException("Circular dependency detected. Shard Id "
- + shardId + " is processed twice");
+ throw new IllegalArgumentException(
+ "Circular dependency detected. Shard Id " + shardId + " is processed twice");
}
return processed.getDepth();
}
@@ -105,16 +99,11 @@ public class ParentsFirstShardPrioritization implements
int maxParentDepth = 0;
for (String parentId : shardInfo.parentShardIds()) {
- maxParentDepth = Math.max(maxParentDepth,
- populateDepth(parentId,
- shards,
- processedNodes));
+ maxParentDepth = Math.max(maxParentDepth, populateDepth(parentId, shards, processedNodes));
}
int currentNodeLevel = maxParentDepth + 1;
- SortingNode previousValue = processedNodes.put(shardId,
- new SortingNode(shardInfo,
- currentNodeLevel));
+ SortingNode previousValue = processedNodes.put(shardId, new SortingNode(shardInfo, currentNodeLevel));
if (previousValue != PROCESSING_NODE) {
throw new IllegalStateException("Validation failed. Depth for shardId " + shardId + " was populated twice");
}
@@ -125,13 +114,11 @@ public class ParentsFirstShardPrioritization implements
/**
* Class to store depth of shards during prioritization.
*/
- private static class SortingNode implements
- Comparable {
+ private static class SortingNode implements Comparable {
private final ShardInfo shardInfo;
private final int depth;
- public SortingNode(ShardInfo shardInfo,
- int depth) {
+ public SortingNode(ShardInfo shardInfo, int depth) {
this.shardInfo = shardInfo;
this.depth = depth;
}
@@ -142,8 +129,7 @@ public class ParentsFirstShardPrioritization implements
@Override
public int compareTo(SortingNode o) {
- return Integer.compare(depth,
- o.depth);
+ return Integer.compare(depth, o.depth);
}
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardDetector.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardDetector.java
index 81154c03..7eb065eb 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardDetector.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardDetector.java
@@ -93,7 +93,8 @@ public interface ShardDetector {
* @throws ExecutionException
* @throws TimeoutException
*/
- default List getChildShards(String shardId) throws InterruptedException, ExecutionException, TimeoutException {
+ default List getChildShards(String shardId)
+ throws InterruptedException, ExecutionException, TimeoutException {
throw new UnsupportedOperationException("getChildShards not available.");
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardInfo.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardInfo.java
index aff3f6f0..bb59cbb1 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardInfo.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardInfo.java
@@ -20,13 +20,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;
import lombok.experimental.Accessors;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
/**
@@ -46,7 +45,7 @@ public class ShardInfo {
/**
* Creates a new ShardInfo object. The checkpoint is not part of the equality, but is used for debugging output.
- *
+ *
* @param shardId
* Kinesis shardId that this will be about
* @param concurrencyToken
@@ -56,7 +55,8 @@ public class ShardInfo {
* @param checkpoint
* the latest checkpoint from lease
*/
- public ShardInfo(@NonNull final String shardId,
+ public ShardInfo(
+ @NonNull final String shardId,
final String concurrencyToken,
final Collection parentShardIds,
final ExtendedSequenceNumber checkpoint) {
@@ -72,7 +72,8 @@ public class ShardInfo {
* @param checkpoint
* @param streamIdentifierSer
*/
- public ShardInfo(@NonNull final String shardId,
+ public ShardInfo(
+ @NonNull final String shardId,
final String concurrencyToken,
final Collection parentShardIds,
final ExtendedSequenceNumber checkpoint,
@@ -92,7 +93,7 @@ public class ShardInfo {
/**
* A list of shards that are parents of this shard. This may be empty if the shard has no parents.
- *
+ *
* @return a list of shardId's that are parents of this shard, or empty if the shard has no parents.
*/
public List parentShardIds() {
@@ -114,7 +115,11 @@ public class ShardInfo {
@Override
public int hashCode() {
return new HashCodeBuilder()
- .append(concurrencyToken).append(parentShardIds).append(shardId).append(streamIdentifierSerOpt.orElse("")).toHashCode();
+ .append(concurrencyToken)
+ .append(parentShardIds)
+ .append(shardId)
+ .append(streamIdentifierSerOpt.orElse(""))
+ .toHashCode();
}
/**
@@ -137,10 +142,12 @@ public class ShardInfo {
return false;
}
ShardInfo other = (ShardInfo) obj;
- return new EqualsBuilder().append(concurrencyToken, other.concurrencyToken)
- .append(parentShardIds, other.parentShardIds).append(shardId, other.shardId)
- .append(streamIdentifierSerOpt.orElse(""), other.streamIdentifierSerOpt.orElse("")).isEquals();
-
+ return new EqualsBuilder()
+ .append(concurrencyToken, other.concurrencyToken)
+ .append(parentShardIds, other.parentShardIds)
+ .append(shardId, other.shardId)
+ .append(streamIdentifierSerOpt.orElse(""), other.streamIdentifierSerOpt.orElse(""))
+ .isEquals();
}
/**
@@ -159,9 +166,9 @@ public class ShardInfo {
* @return lease key
*/
public static String getLeaseKey(ShardInfo shardInfo, String shardIdOverride) {
- return shardInfo.streamIdentifierSerOpt().isPresent() ?
- MultiStreamLease.getLeaseKey(shardInfo.streamIdentifierSerOpt().get(), shardIdOverride) :
- shardIdOverride;
+ return shardInfo.streamIdentifierSerOpt().isPresent()
+ ? MultiStreamLease.getLeaseKey(
+ shardInfo.streamIdentifierSerOpt().get(), shardIdOverride)
+ : shardIdOverride;
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardPrioritization.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardPrioritization.java
index dc99d413..934b454a 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardPrioritization.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardPrioritization.java
@@ -24,7 +24,7 @@ public interface ShardPrioritization {
/**
* Returns new list of shards ordered based on their priority.
* Resulted list may have fewer shards compared to original list
- *
+ *
* @param original
* list of shards needed to be prioritized
* @return new list that contains only shards that should be processed
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 1986fa49..be4fbf51 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
@@ -41,16 +41,21 @@ public class ShardSyncTask implements ConsumerTask {
@NonNull
private final ShardDetector shardDetector;
+
@NonNull
private final LeaseRefresher leaseRefresher;
+
@NonNull
private final InitialPositionInStreamExtended initialPosition;
+
private final boolean cleanupLeasesUponShardCompletion;
private final boolean garbageCollectLeases;
private final boolean ignoreUnexpectedChildShards;
private final long shardSyncTaskIdleTimeMillis;
+
@NonNull
private final HierarchicalShardSyncer hierarchicalShardSyncer;
+
@NonNull
private final MetricsFactory metricsFactory;
@@ -67,8 +72,12 @@ public class ShardSyncTask implements ConsumerTask {
boolean shardSyncSuccess = true;
try {
- boolean didPerformShardSync = hierarchicalShardSyncer.checkAndCreateLeaseForNewShards(shardDetector, leaseRefresher,
- initialPosition, scope, ignoreUnexpectedChildShards,
+ boolean didPerformShardSync = hierarchicalShardSyncer.checkAndCreateLeaseForNewShards(
+ shardDetector,
+ leaseRefresher,
+ initialPosition,
+ scope,
+ ignoreUnexpectedChildShards,
leaseRefresher.isLeaseTableEmpty());
if (didPerformShardSync && shardSyncTaskIdleTimeMillis > 0) {
@@ -80,7 +89,8 @@ public class ShardSyncTask implements ConsumerTask {
shardSyncSuccess = false;
} finally {
// NOTE: This metric is reflecting if a shard sync task succeeds. Customer can use this metric to monitor if
- // their application encounter any shard sync failures. This metric can help to detect potential shard stuck issues
+ // their application encounter any shard sync failures. This metric can help to detect potential shard stuck
+ // issues
// that are due to shard sync failures.
MetricsUtil.addSuccess(scope, "SyncShards", shardSyncSuccess, MetricsLevel.DETAILED);
MetricsUtil.endScope(scope);
@@ -97,5 +107,4 @@ public class ShardSyncTask implements ConsumerTask {
public TaskType taskType() {
return taskType;
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTaskManager.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTaskManager.java
index 9a015c28..add8cf4f 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTaskManager.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/ShardSyncTaskManager.java
@@ -20,17 +20,16 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
-import software.amazon.kinesis.common.InitialPositionInStreamExtended;
-
import lombok.Data;
import lombok.NonNull;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
+import software.amazon.kinesis.common.InitialPositionInStreamExtended;
import software.amazon.kinesis.coordinator.ExecutorStateEvent;
import software.amazon.kinesis.lifecycle.ConsumerTask;
import software.amazon.kinesis.lifecycle.TaskResult;
-import software.amazon.kinesis.metrics.MetricsFactory;
import software.amazon.kinesis.metrics.MetricsCollectingTaskDecorator;
+import software.amazon.kinesis.metrics.MetricsFactory;
/**
* The ShardSyncTaskManager is used to track the task to sync shards with leases (create leases for new
@@ -43,20 +42,27 @@ import software.amazon.kinesis.metrics.MetricsCollectingTaskDecorator;
public class ShardSyncTaskManager {
@NonNull
private final ShardDetector shardDetector;
+
@NonNull
private final LeaseRefresher leaseRefresher;
+
@NonNull
private final InitialPositionInStreamExtended initialPositionInStream;
+
private final boolean cleanupLeasesUponShardCompletion;
private final boolean garbageCollectLeases;
private final boolean ignoreUnexpectedChildShards;
private final long shardSyncIdleTimeMillis;
+
@NonNull
private final ExecutorService executorService;
+
@NonNull
private final HierarchicalShardSyncer hierarchicalShardSyncer;
+
@NonNull
private final MetricsFactory metricsFactory;
+
private ConsumerTask currentTask;
private CompletableFuture future;
private AtomicBoolean shardSyncRequestPending;
@@ -77,9 +83,14 @@ public class ShardSyncTaskManager {
* @param metricsFactory
*/
@Deprecated
- public ShardSyncTaskManager(ShardDetector shardDetector, LeaseRefresher leaseRefresher,
- InitialPositionInStreamExtended initialPositionInStream, boolean cleanupLeasesUponShardCompletion,
- boolean ignoreUnexpectedChildShards, long shardSyncIdleTimeMillis, ExecutorService executorService,
+ public ShardSyncTaskManager(
+ ShardDetector shardDetector,
+ LeaseRefresher leaseRefresher,
+ InitialPositionInStreamExtended initialPositionInStream,
+ boolean cleanupLeasesUponShardCompletion,
+ boolean ignoreUnexpectedChildShards,
+ long shardSyncIdleTimeMillis,
+ ExecutorService executorService,
MetricsFactory metricsFactory) {
this.shardDetector = shardDetector;
this.leaseRefresher = leaseRefresher;
@@ -108,10 +119,16 @@ public class ShardSyncTaskManager {
* @param hierarchicalShardSyncer
* @param metricsFactory
*/
- public ShardSyncTaskManager(ShardDetector shardDetector, LeaseRefresher leaseRefresher,
- InitialPositionInStreamExtended initialPositionInStream, boolean cleanupLeasesUponShardCompletion,
- boolean ignoreUnexpectedChildShards, long shardSyncIdleTimeMillis, ExecutorService executorService,
- HierarchicalShardSyncer hierarchicalShardSyncer, MetricsFactory metricsFactory) {
+ public ShardSyncTaskManager(
+ ShardDetector shardDetector,
+ LeaseRefresher leaseRefresher,
+ InitialPositionInStreamExtended initialPositionInStream,
+ boolean cleanupLeasesUponShardCompletion,
+ boolean ignoreUnexpectedChildShards,
+ long shardSyncIdleTimeMillis,
+ ExecutorService executorService,
+ HierarchicalShardSyncer hierarchicalShardSyncer,
+ MetricsFactory metricsFactory) {
this.shardDetector = shardDetector;
this.leaseRefresher = leaseRefresher;
this.initialPositionInStream = initialPositionInStream;
@@ -131,15 +148,16 @@ public class ShardSyncTaskManager {
* @return the Task Result.
*/
public TaskResult callShardSyncTask() {
- final ShardSyncTask shardSyncTask = new ShardSyncTask(shardDetector,
- leaseRefresher,
- initialPositionInStream,
- cleanupLeasesUponShardCompletion,
- garbageCollectLeases,
- ignoreUnexpectedChildShards,
- shardSyncIdleTimeMillis,
- hierarchicalShardSyncer,
- metricsFactory);
+ final ShardSyncTask shardSyncTask = new ShardSyncTask(
+ shardDetector,
+ leaseRefresher,
+ initialPositionInStream,
+ cleanupLeasesUponShardCompletion,
+ garbageCollectLeases,
+ ignoreUnexpectedChildShards,
+ shardSyncIdleTimeMillis,
+ hierarchicalShardSyncer,
+ metricsFactory);
final ConsumerTask metricCollectingTask = new MetricsCollectingTaskDecorator(shardSyncTask, metricsFactory);
return metricCollectingTask.call();
}
@@ -164,28 +182,27 @@ public class ShardSyncTaskManager {
try {
TaskResult result = future.get();
if (result.getException() != null) {
- log.error("Caught exception running {} task: ", currentTask.taskType(),
- result.getException());
+ log.error("Caught exception running {} task: ", currentTask.taskType(), result.getException());
}
} catch (InterruptedException | ExecutionException e) {
log.warn("{} task encountered exception.", currentTask.taskType(), e);
}
}
- currentTask =
- new MetricsCollectingTaskDecorator(
- new ShardSyncTask(shardDetector,
- leaseRefresher,
- initialPositionInStream,
- cleanupLeasesUponShardCompletion,
- garbageCollectLeases,
- ignoreUnexpectedChildShards,
- shardSyncIdleTimeMillis,
- hierarchicalShardSyncer,
- metricsFactory),
- metricsFactory);
+ currentTask = new MetricsCollectingTaskDecorator(
+ new ShardSyncTask(
+ shardDetector,
+ leaseRefresher,
+ initialPositionInStream,
+ cleanupLeasesUponShardCompletion,
+ garbageCollectLeases,
+ ignoreUnexpectedChildShards,
+ shardSyncIdleTimeMillis,
+ hierarchicalShardSyncer,
+ metricsFactory),
+ metricsFactory);
future = CompletableFuture.supplyAsync(() -> currentTask.call(), executorService)
- .whenComplete((taskResult, exception) -> handlePendingShardSyncs(exception, taskResult));
+ .whenComplete((taskResult, exception) -> handlePendingShardSyncs(exception, taskResult));
log.info(new ExecutorStateEvent(executorService).message());
@@ -195,8 +212,10 @@ public class ShardSyncTaskManager {
}
} else {
if (log.isDebugEnabled()) {
- log.debug("Previous {} task still pending. Not submitting new task. "
- + "Triggered a pending request but will not be executed until the current request completes.", currentTask.taskType());
+ log.debug(
+ "Previous {} task still pending. Not submitting new task. "
+ + "Triggered a pending request but will not be executed until the current request completes.",
+ currentTask.taskType());
}
shardSyncRequestPending.compareAndSet(false /*expected*/, true /*update*/);
}
@@ -205,9 +224,10 @@ public class ShardSyncTaskManager {
private void handlePendingShardSyncs(Throwable exception, TaskResult taskResult) {
if (exception != null || taskResult.getException() != null) {
- log.error("Caught exception running {} task: {}", currentTask.taskType(),
+ log.error(
+ "Caught exception running {} task: {}",
+ currentTask.taskType(),
exception != null ? exception : taskResult.getException());
}
}
-
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/UpdateField.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/UpdateField.java
index 9461a18e..4ce3f1a9 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/UpdateField.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/UpdateField.java
@@ -22,5 +22,6 @@ package software.amazon.kinesis.leases;
* for backfilling while rolling forward to newer versions.
*/
public enum UpdateField {
- CHILD_SHARDS, HASH_KEY_RANGE
+ CHILD_SHARDS,
+ HASH_KEY_RANGE
}
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 6c0803f2..bef76ef0 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
@@ -14,8 +14,6 @@
*/
package software.amazon.kinesis.leases.dynamodb;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -30,6 +28,8 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import software.amazon.kinesis.annotations.KinesisClientInternalApi;
import software.amazon.kinesis.leases.Lease;
@@ -63,9 +63,13 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
// Time to wait for in-flight Runnables to finish when calling .stop();
private static final long STOP_WAIT_TIME_MILLIS = 2000L;
private static final ThreadFactory LEASE_COORDINATOR_THREAD_FACTORY = new ThreadFactoryBuilder()
- .setNameFormat("LeaseCoordinator-%04d").setDaemon(true).build();
+ .setNameFormat("LeaseCoordinator-%04d")
+ .setDaemon(true)
+ .build();
private static final ThreadFactory LEASE_RENEWAL_THREAD_FACTORY = new ThreadFactoryBuilder()
- .setNameFormat("LeaseRenewer-%04d").setDaemon(true).build();
+ .setNameFormat("LeaseRenewer-%04d")
+ .setDaemon(true)
+ .build();
private final LeaseRenewer leaseRenewer;
private final LeaseTaker leaseTaker;
@@ -105,18 +109,26 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
* Used to publish metrics about lease operations
*/
@Deprecated
- public DynamoDBLeaseCoordinator(final LeaseRefresher leaseRefresher,
- final String workerIdentifier,
- final long leaseDurationMillis,
- final long epsilonMillis,
- final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime,
- final int maxLeaseRenewerThreadCount,
- final MetricsFactory metricsFactory) {
- this(leaseRefresher, workerIdentifier, leaseDurationMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewerThreadCount,
+ public DynamoDBLeaseCoordinator(
+ final LeaseRefresher leaseRefresher,
+ final String workerIdentifier,
+ final long leaseDurationMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewerThreadCount,
+ final MetricsFactory metricsFactory) {
+ this(
+ leaseRefresher,
+ workerIdentifier,
+ leaseDurationMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewerThreadCount,
TableConstants.DEFAULT_INITIAL_LEASE_TABLE_READ_CAPACITY,
- TableConstants.DEFAULT_INITIAL_LEASE_TABLE_WRITE_CAPACITY, metricsFactory);
+ TableConstants.DEFAULT_INITIAL_LEASE_TABLE_WRITE_CAPACITY,
+ metricsFactory);
}
/**
@@ -142,21 +154,29 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
* Used to publish metrics about lease operations
*/
@Deprecated
- public DynamoDBLeaseCoordinator(final LeaseRefresher leaseRefresher,
- final String workerIdentifier,
- final long leaseDurationMillis,
- final long epsilonMillis,
- final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime,
- final int maxLeaseRenewerThreadCount,
- final long initialLeaseTableReadCapacity,
- final long initialLeaseTableWriteCapacity,
- final MetricsFactory metricsFactory) {
- this(leaseRefresher, workerIdentifier, leaseDurationMillis,
- LeaseManagementConfig.DEFAULT_ENABLE_PRIORITY_LEASE_ASSIGNMENT, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewerThreadCount,
+ public DynamoDBLeaseCoordinator(
+ final LeaseRefresher leaseRefresher,
+ final String workerIdentifier,
+ final long leaseDurationMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewerThreadCount,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final MetricsFactory metricsFactory) {
+ this(
+ leaseRefresher,
+ workerIdentifier,
+ leaseDurationMillis,
+ LeaseManagementConfig.DEFAULT_ENABLE_PRIORITY_LEASE_ASSIGNMENT,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewerThreadCount,
TableConstants.DEFAULT_INITIAL_LEASE_TABLE_READ_CAPACITY,
- TableConstants.DEFAULT_INITIAL_LEASE_TABLE_WRITE_CAPACITY, metricsFactory);
+ TableConstants.DEFAULT_INITIAL_LEASE_TABLE_WRITE_CAPACITY,
+ metricsFactory);
}
/**
@@ -183,7 +203,8 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
* @param metricsFactory
* Used to publish metrics about lease operations
*/
- public DynamoDBLeaseCoordinator(final LeaseRefresher leaseRefresher,
+ public DynamoDBLeaseCoordinator(
+ final LeaseRefresher leaseRefresher,
final String workerIdentifier,
final long leaseDurationMillis,
final boolean enablePriorityLeaseAssignment,
@@ -214,7 +235,8 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
this.initialLeaseTableWriteCapacity = initialLeaseTableWriteCapacity;
this.metricsFactory = metricsFactory;
- log.info("With failover time {} ms and epsilon {} ms, LeaseCoordinator will renew leases every {} ms, take"
+ log.info(
+ "With failover time {} ms and epsilon {} ms, LeaseCoordinator will renew leases every {} ms, take"
+ "leases every {} ms, process maximum of {} leases and steal {} lease(s) at a time.",
leaseDurationMillis,
epsilonMillis,
@@ -236,7 +258,6 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
log.error("Throwable encountered in lease taking thread", t);
}
}
-
}
private class RenewerRunnable implements Runnable {
@@ -251,13 +272,11 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
log.error("Throwable encountered in lease renewing thread", t);
}
}
-
}
@Override
public void initialize() throws ProvisionedThroughputException, DependencyException, IllegalStateException {
- final boolean newTableCreated =
- leaseRefresher.createLeaseTableIfNotExists();
+ final boolean newTableCreated = leaseRefresher.createLeaseTableIfNotExists();
if (newTableCreated) {
log.info("Created new lease table for coordinator with pay per request billing mode.");
}
@@ -278,15 +297,11 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
leaseCoordinatorThreadPool = Executors.newScheduledThreadPool(2, LEASE_COORDINATOR_THREAD_FACTORY);
// Taker runs with fixed DELAY because we want it to run slower in the event of performance degredation.
- takerFuture = leaseCoordinatorThreadPool.scheduleWithFixedDelay(new TakerRunnable(),
- 0L,
- takerIntervalMillis,
- TimeUnit.MILLISECONDS);
+ takerFuture = leaseCoordinatorThreadPool.scheduleWithFixedDelay(
+ new TakerRunnable(), 0L, takerIntervalMillis, TimeUnit.MILLISECONDS);
// Renewer runs at fixed INTERVAL because we want it to run at the same rate in the event of degredation.
- leaseCoordinatorThreadPool.scheduleAtFixedRate(new RenewerRunnable(),
- 0L,
- renewerIntervalMillis,
- TimeUnit.MILLISECONDS);
+ leaseCoordinatorThreadPool.scheduleAtFixedRate(
+ new RenewerRunnable(), 0L, renewerIntervalMillis, TimeUnit.MILLISECONDS);
running = true;
}
@@ -350,11 +365,13 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
leaseCoordinatorThreadPool.shutdown();
try {
if (leaseCoordinatorThreadPool.awaitTermination(STOP_WAIT_TIME_MILLIS, TimeUnit.MILLISECONDS)) {
- log.info("Worker {} has successfully stopped lease-tracking threads",
+ log.info(
+ "Worker {} has successfully stopped lease-tracking threads",
leaseTaker.getWorkerIdentifier());
} else {
leaseCoordinatorThreadPool.shutdownNow();
- log.info("Worker {} stopped lease-tracking threads {} ms after stop",
+ log.info(
+ "Worker {} stopped lease-tracking threads {} ms after stop",
leaseTaker.getWorkerIdentifier(),
STOP_WAIT_TIME_MILLIS);
}
@@ -394,8 +411,9 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
}
@Override
- public boolean updateLease(final Lease lease, final UUID concurrencyToken, final String operation,
- final String singleStreamShardId) throws DependencyException, InvalidStateException, ProvisionedThroughputException {
+ public boolean updateLease(
+ final Lease lease, final UUID concurrencyToken, final String operation, final String singleStreamShardId)
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException {
return leaseRenewer.updateLease(lease, concurrencyToken, operation, singleStreamShardId);
}
@@ -407,8 +425,13 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
private static ExecutorService getLeaseRenewalExecutorService(int maximumPoolSize) {
int coreLeaseCount = Math.max(maximumPoolSize / 4, 2);
- return new ThreadPoolExecutor(coreLeaseCount, maximumPoolSize, 60, TimeUnit.SECONDS,
- new LinkedTransferQueue<>(), LEASE_RENEWAL_THREAD_FACTORY);
+ return new ThreadPoolExecutor(
+ coreLeaseCount,
+ maximumPoolSize,
+ 60,
+ TimeUnit.SECONDS,
+ new LinkedTransferQueue<>(),
+ LEASE_RENEWAL_THREAD_FACTORY);
}
@Override
@@ -421,7 +444,9 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
if (leases == null) {
return Collections.emptyList();
}
- return leases.stream().map(DynamoDBLeaseCoordinator::convertLeaseToAssignment).collect(Collectors.toList());
+ return leases.stream()
+ .map(DynamoDBLeaseCoordinator::convertLeaseToAssignment)
+ .collect(Collectors.toList());
}
/**
@@ -431,11 +456,15 @@ public class DynamoDBLeaseCoordinator implements LeaseCoordinator {
*/
public static ShardInfo convertLeaseToAssignment(final Lease lease) {
if (lease instanceof MultiStreamLease) {
- return new ShardInfo(((MultiStreamLease) lease).shardId(), lease.concurrencyToken().toString(), lease.parentShardIds(),
- lease.checkpoint(), ((MultiStreamLease) lease).streamIdentifier());
+ return new ShardInfo(
+ ((MultiStreamLease) lease).shardId(),
+ lease.concurrencyToken().toString(),
+ lease.parentShardIds(),
+ lease.checkpoint(),
+ ((MultiStreamLease) lease).streamIdentifier());
} else {
- return new ShardInfo(lease.leaseKey(), lease.concurrencyToken().toString(), lease.parentShardIds(),
- lease.checkpoint());
+ return new ShardInfo(
+ lease.leaseKey(), lease.concurrencyToken().toString(), lease.parentShardIds(), lease.checkpoint());
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseManagementFactory.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseManagementFactory.java
index 7d9ebeef..2eb3e707 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseManagementFactory.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseManagementFactory.java
@@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;
+
import lombok.Data;
import lombok.NonNull;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
@@ -53,18 +54,25 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
@NonNull
private final KinesisAsyncClient kinesisClient;
+
@NonNull
private final DynamoDbAsyncClient dynamoDBClient;
+
@NonNull
private final String tableName;
+
@NonNull
private final String workerIdentifier;
+
@NonNull
private final ExecutorService executorService;
+
@NonNull
private final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer;
+
@NonNull
private final LeaseSerializer leaseSerializer;
+
@NonNull
private StreamConfig streamConfig;
@@ -123,21 +131,51 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param cacheMissWarningModulus
*/
@Deprecated
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final String streamName,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final InitialPositionInStreamExtended initialPositionInStream,
- final long failoverTimeMillis, final long epsilonMillis, final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus) {
- this(kinesisClient, streamName, dynamoDBClient, tableName, workerIdentifier, executorService,
- initialPositionInStream, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, TableConstants.DEFAULT_INITIAL_LEASE_TABLE_READ_CAPACITY,
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final String streamName,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final InitialPositionInStreamExtended initialPositionInStream,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus) {
+ this(
+ kinesisClient,
+ streamName,
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ initialPositionInStream,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ TableConstants.DEFAULT_INITIAL_LEASE_TABLE_READ_CAPACITY,
TableConstants.DEFAULT_INITIAL_LEASE_TABLE_WRITE_CAPACITY);
}
@@ -173,23 +211,56 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param initialLeaseTableWriteCapacity
*/
@Deprecated
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final String streamName,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final InitialPositionInStreamExtended initialPositionInStream,
- final long failoverTimeMillis, final long epsilonMillis, final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity) {
- this(kinesisClient, streamName, dynamoDBClient, tableName, workerIdentifier, executorService,
- initialPositionInStream, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- new HierarchicalShardSyncer(), TableCreatorCallback.NOOP_TABLE_CREATOR_CALLBACK,
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final String streamName,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final InitialPositionInStreamExtended initialPositionInStream,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity) {
+ this(
+ kinesisClient,
+ streamName,
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ initialPositionInStream,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ new HierarchicalShardSyncer(),
+ TableCreatorCallback.NOOP_TABLE_CREATOR_CALLBACK,
LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT);
}
@@ -223,24 +294,59 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param tableCreatorCallback
*/
@Deprecated
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final String streamName,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final InitialPositionInStreamExtended initialPositionInStream,
- final long failoverTimeMillis, final long epsilonMillis, final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer hierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback) {
- this(kinesisClient, streamName, dynamoDBClient, tableName, workerIdentifier, executorService,
- initialPositionInStream, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- hierarchicalShardSyncer, tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT);
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final String streamName,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final InitialPositionInStreamExtended initialPositionInStream,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer hierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback) {
+ this(
+ kinesisClient,
+ streamName,
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ initialPositionInStream,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ hierarchicalShardSyncer,
+ tableCreatorCallback,
+ LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT);
}
/**
@@ -274,25 +380,61 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param dynamoDbRequestTimeout
*/
@Deprecated
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final String streamName,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final InitialPositionInStreamExtended initialPositionInStream,
- final long failoverTimeMillis, final long epsilonMillis, final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer hierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final String streamName,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final InitialPositionInStreamExtended initialPositionInStream,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer hierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback,
Duration dynamoDbRequestTimeout) {
- this(kinesisClient, streamName, dynamoDBClient, tableName, workerIdentifier, executorService,
- initialPositionInStream, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- hierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, BillingMode.PAY_PER_REQUEST);
+ this(
+ kinesisClient,
+ streamName,
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ initialPositionInStream,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ hierarchicalShardSyncer,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ BillingMode.PAY_PER_REQUEST);
}
/**
@@ -327,26 +469,63 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param billingMode
*/
@Deprecated
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final String streamName,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final InitialPositionInStreamExtended initialPositionInStream,
- final long failoverTimeMillis, final long epsilonMillis, final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer hierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
- Duration dynamoDbRequestTimeout, BillingMode billingMode) {
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final String streamName,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final InitialPositionInStreamExtended initialPositionInStream,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer hierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ BillingMode billingMode) {
- this(kinesisClient, new StreamConfig(StreamIdentifier.singleStreamInstance(streamName), initialPositionInStream), dynamoDBClient, tableName,
- workerIdentifier, executorService, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- hierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode, new DynamoDBLeaseSerializer());
+ this(
+ kinesisClient,
+ new StreamConfig(StreamIdentifier.singleStreamInstance(streamName), initialPositionInStream),
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ hierarchicalShardSyncer,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ billingMode,
+ new DynamoDBLeaseSerializer());
}
/**
@@ -382,26 +561,64 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param tags
*/
@Deprecated
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final String streamName,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final InitialPositionInStreamExtended initialPositionInStream,
- final long failoverTimeMillis, final long epsilonMillis, final int maxLeasesForWorker,
- final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer hierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
- Duration dynamoDbRequestTimeout, BillingMode billingMode, Collection tags) {
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final String streamName,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final InitialPositionInStreamExtended initialPositionInStream,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer hierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ BillingMode billingMode,
+ Collection tags) {
- this(kinesisClient, new StreamConfig(StreamIdentifier.singleStreamInstance(streamName), initialPositionInStream), dynamoDBClient, tableName,
- workerIdentifier, executorService, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- hierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode, new DynamoDBLeaseSerializer());
+ this(
+ kinesisClient,
+ new StreamConfig(StreamIdentifier.singleStreamInstance(streamName), initialPositionInStream),
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ hierarchicalShardSyncer,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ billingMode,
+ new DynamoDBLeaseSerializer());
}
/**
@@ -435,25 +652,64 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param billingMode
*/
@Deprecated
- private DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final StreamConfig streamConfig,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final long failoverTimeMillis, final long epsilonMillis,
- final int maxLeasesForWorker, final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
- Duration dynamoDbRequestTimeout, BillingMode billingMode, LeaseSerializer leaseSerializer) {
- this(kinesisClient, streamConfig, dynamoDBClient, tableName,
- workerIdentifier, executorService, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- deprecatedHierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode, false,
- DefaultSdkAutoConstructList.getInstance(), leaseSerializer);
+ private DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final StreamConfig streamConfig,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ BillingMode billingMode,
+ LeaseSerializer leaseSerializer) {
+ this(
+ kinesisClient,
+ streamConfig,
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ deprecatedHierarchicalShardSyncer,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ billingMode,
+ false,
+ DefaultSdkAutoConstructList.getInstance(),
+ leaseSerializer);
}
/**
@@ -489,26 +745,67 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param tags
*/
@Deprecated
- private DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final StreamConfig streamConfig,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final long failoverTimeMillis, final long epsilonMillis,
- final int maxLeasesForWorker, final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
- Duration dynamoDbRequestTimeout, BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled,
- Collection tags, LeaseSerializer leaseSerializer) {
- this(kinesisClient, dynamoDBClient, tableName,
- workerIdentifier, executorService, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- deprecatedHierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode,
- leaseTableDeletionProtectionEnabled, tags, leaseSerializer, null, false,
+ private DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final StreamConfig streamConfig,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ BillingMode billingMode,
+ final boolean leaseTableDeletionProtectionEnabled,
+ Collection tags,
+ LeaseSerializer leaseSerializer) {
+ this(
+ kinesisClient,
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ failoverTimeMillis,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ deprecatedHierarchicalShardSyncer,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ billingMode,
+ leaseTableDeletionProtectionEnabled,
+ tags,
+ leaseSerializer,
+ null,
+ false,
LeaseManagementConfig.DEFAULT_LEASE_CLEANUP_CONFIG);
this.streamConfig = streamConfig;
}
@@ -547,29 +844,70 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param leaseCleanupConfig
*/
@Deprecated
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final long failoverTimeMillis, final long epsilonMillis,
- final int maxLeasesForWorker, final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
- Duration dynamoDbRequestTimeout, BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled,
- Collection tags, LeaseSerializer leaseSerializer,
- Function customShardDetectorProvider, boolean isMultiStreamMode,
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final long failoverTimeMillis,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ BillingMode billingMode,
+ final boolean leaseTableDeletionProtectionEnabled,
+ Collection tags,
+ LeaseSerializer leaseSerializer,
+ Function customShardDetectorProvider,
+ boolean isMultiStreamMode,
LeaseCleanupConfig leaseCleanupConfig) {
- this(kinesisClient, dynamoDBClient, tableName,
- workerIdentifier, executorService, failoverTimeMillis,
- LeaseManagementConfig.DEFAULT_ENABLE_PRIORITY_LEASE_ASSIGNMENT, epsilonMillis, maxLeasesForWorker,
- maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
- ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
- cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
- deprecatedHierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode,
- leaseTableDeletionProtectionEnabled, tags, leaseSerializer, customShardDetectorProvider, isMultiStreamMode,
+ this(
+ kinesisClient,
+ dynamoDBClient,
+ tableName,
+ workerIdentifier,
+ executorService,
+ failoverTimeMillis,
+ LeaseManagementConfig.DEFAULT_ENABLE_PRIORITY_LEASE_ASSIGNMENT,
+ epsilonMillis,
+ maxLeasesForWorker,
+ maxLeasesToStealAtOneTime,
+ maxLeaseRenewalThreads,
+ cleanupLeasesUponShardCompletion,
+ ignoreUnexpectedChildShards,
+ shardSyncIntervalMillis,
+ consistentReads,
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ maxCacheMissesBeforeReload,
+ listShardsCacheAllowedAgeInSeconds,
+ cacheMissWarningModulus,
+ initialLeaseTableReadCapacity,
+ initialLeaseTableWriteCapacity,
+ deprecatedHierarchicalShardSyncer,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ billingMode,
+ leaseTableDeletionProtectionEnabled,
+ tags,
+ leaseSerializer,
+ customShardDetectorProvider,
+ isMultiStreamMode,
leaseCleanupConfig);
}
@@ -607,20 +945,38 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @param isMultiStreamMode
* @param leaseCleanupConfig
*/
- public DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient,
- final DynamoDbAsyncClient dynamoDBClient, final String tableName, final String workerIdentifier,
- final ExecutorService executorService, final long failoverTimeMillis,
- final boolean enablePriorityLeaseAssignment, final long epsilonMillis,
- final int maxLeasesForWorker, final int maxLeasesToStealAtOneTime, final int maxLeaseRenewalThreads,
- final boolean cleanupLeasesUponShardCompletion, final boolean ignoreUnexpectedChildShards,
- final long shardSyncIntervalMillis, final boolean consistentReads, final long listShardsBackoffTimeMillis,
- final int maxListShardsRetryAttempts, final int maxCacheMissesBeforeReload,
- final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
- final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
- final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
- Duration dynamoDbRequestTimeout, BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled,
- Collection tags, LeaseSerializer leaseSerializer,
- Function customShardDetectorProvider, boolean isMultiStreamMode,
+ public DynamoDBLeaseManagementFactory(
+ final KinesisAsyncClient kinesisClient,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final String tableName,
+ final String workerIdentifier,
+ final ExecutorService executorService,
+ final long failoverTimeMillis,
+ final boolean enablePriorityLeaseAssignment,
+ final long epsilonMillis,
+ final int maxLeasesForWorker,
+ final int maxLeasesToStealAtOneTime,
+ final int maxLeaseRenewalThreads,
+ final boolean cleanupLeasesUponShardCompletion,
+ final boolean ignoreUnexpectedChildShards,
+ final long shardSyncIntervalMillis,
+ final boolean consistentReads,
+ final long listShardsBackoffTimeMillis,
+ final int maxListShardsRetryAttempts,
+ final int maxCacheMissesBeforeReload,
+ final long listShardsCacheAllowedAgeInSeconds,
+ final int cacheMissWarningModulus,
+ final long initialLeaseTableReadCapacity,
+ final long initialLeaseTableWriteCapacity,
+ final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer,
+ final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ BillingMode billingMode,
+ final boolean leaseTableDeletionProtectionEnabled,
+ Collection tags,
+ LeaseSerializer leaseSerializer,
+ Function customShardDetectorProvider,
+ boolean isMultiStreamMode,
LeaseCleanupConfig leaseCleanupConfig) {
this.kinesisClient = kinesisClient;
this.dynamoDBClient = dynamoDBClient;
@@ -658,9 +1014,11 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
@Override
public LeaseCoordinator createLeaseCoordinator(@NonNull final MetricsFactory metricsFactory) {
- return new DynamoDBLeaseCoordinator(this.createLeaseRefresher(),
+ return new DynamoDBLeaseCoordinator(
+ this.createLeaseRefresher(),
workerIdentifier,
- failoverTimeMillis, enablePriorityLeaseAssignment,
+ failoverTimeMillis,
+ enablePriorityLeaseAssignment,
epsilonMillis,
maxLeasesForWorker,
maxLeasesToStealAtOneTime,
@@ -670,15 +1028,18 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
metricsFactory);
}
- @Override @Deprecated
+ @Override
+ @Deprecated
public ShardSyncTaskManager createShardSyncTaskManager(@NonNull final MetricsFactory metricsFactory) {
- return new ShardSyncTaskManager(this.createShardDetector(),
+ return new ShardSyncTaskManager(
+ this.createShardDetector(),
this.createLeaseRefresher(),
streamConfig.initialPositionInStreamExtended(),
cleanupLeasesUponShardCompletion,
ignoreUnexpectedChildShards,
shardSyncIntervalMillis,
- executorService, deprecatedHierarchicalShardSyncer,
+ executorService,
+ deprecatedHierarchicalShardSyncer,
metricsFactory);
}
@@ -702,33 +1063,49 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
* @return ShardSyncTaskManager
*/
@Override
- public ShardSyncTaskManager createShardSyncTaskManager(MetricsFactory metricsFactory, StreamConfig streamConfig,
+ public ShardSyncTaskManager createShardSyncTaskManager(
+ MetricsFactory metricsFactory,
+ StreamConfig streamConfig,
DeletedStreamListProvider deletedStreamListProvider) {
- return new ShardSyncTaskManager(this.createShardDetector(streamConfig),
+ return new ShardSyncTaskManager(
+ this.createShardDetector(streamConfig),
this.createLeaseRefresher(),
streamConfig.initialPositionInStreamExtended(),
cleanupLeasesUponShardCompletion,
ignoreUnexpectedChildShards,
shardSyncIntervalMillis,
executorService,
- new HierarchicalShardSyncer(isMultiStreamMode, streamConfig.streamIdentifier().toString(),
- deletedStreamListProvider),
+ new HierarchicalShardSyncer(
+ isMultiStreamMode, streamConfig.streamIdentifier().toString(), deletedStreamListProvider),
metricsFactory);
}
-
@Override
public DynamoDBLeaseRefresher createLeaseRefresher() {
- return new DynamoDBLeaseRefresher(tableName, dynamoDBClient, leaseSerializer, consistentReads,
- tableCreatorCallback, dynamoDbRequestTimeout, billingMode, leaseTableDeletionProtectionEnabled, tags);
+ return new DynamoDBLeaseRefresher(
+ tableName,
+ dynamoDBClient,
+ leaseSerializer,
+ consistentReads,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ billingMode,
+ leaseTableDeletionProtectionEnabled,
+ tags);
}
@Override
@Deprecated
public ShardDetector createShardDetector() {
- return new KinesisShardDetector(kinesisClient, streamConfig.streamIdentifier(),
- listShardsBackoffTimeMillis, maxListShardsRetryAttempts, listShardsCacheAllowedAgeInSeconds,
- maxCacheMissesBeforeReload, cacheMissWarningModulus, dynamoDbRequestTimeout);
+ return new KinesisShardDetector(
+ kinesisClient,
+ streamConfig.streamIdentifier(),
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ listShardsCacheAllowedAgeInSeconds,
+ maxCacheMissesBeforeReload,
+ cacheMissWarningModulus,
+ dynamoDbRequestTimeout);
}
/**
@@ -739,10 +1116,17 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
*/
@Override
public ShardDetector createShardDetector(StreamConfig streamConfig) {
- return customShardDetectorProvider != null ? customShardDetectorProvider.apply(streamConfig) :
- new KinesisShardDetector(kinesisClient, streamConfig.streamIdentifier(), listShardsBackoffTimeMillis,
- maxListShardsRetryAttempts, listShardsCacheAllowedAgeInSeconds, maxCacheMissesBeforeReload,
- cacheMissWarningModulus, dynamoDbRequestTimeout);
+ return customShardDetectorProvider != null
+ ? customShardDetectorProvider.apply(streamConfig)
+ : new KinesisShardDetector(
+ kinesisClient,
+ streamConfig.streamIdentifier(),
+ listShardsBackoffTimeMillis,
+ maxListShardsRetryAttempts,
+ listShardsCacheAllowedAgeInSeconds,
+ maxCacheMissesBeforeReload,
+ cacheMissWarningModulus,
+ dynamoDbRequestTimeout);
}
/**
@@ -753,9 +1137,12 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
*/
@Override
public LeaseCleanupManager createLeaseCleanupManager(MetricsFactory metricsFactory) {
- return new LeaseCleanupManager(createLeaseCoordinator(metricsFactory),
- metricsFactory, Executors.newSingleThreadScheduledExecutor(),
- cleanupLeasesUponShardCompletion, leaseCleanupConfig.leaseCleanupIntervalMillis(),
+ return new LeaseCleanupManager(
+ createLeaseCoordinator(metricsFactory),
+ metricsFactory,
+ Executors.newSingleThreadScheduledExecutor(),
+ cleanupLeasesUponShardCompletion,
+ leaseCleanupConfig.leaseCleanupIntervalMillis(),
leaseCleanupConfig.completedLeaseCleanupIntervalMillis(),
leaseCleanupConfig.garbageLeaseCleanupIntervalMillis());
}
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 11807b9c..838d2d15 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
@@ -14,8 +14,6 @@
*/
package software.amazon.kinesis.leases.dynamodb;
-import com.google.common.collect.ImmutableMap;
-
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
@@ -24,6 +22,8 @@ import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+
+import com.google.common.collect.ImmutableMap;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
@@ -101,8 +101,11 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* @param consistentReads
*/
@Deprecated
- public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
- final LeaseSerializer serializer, final boolean consistentReads) {
+ public DynamoDBLeaseRefresher(
+ final String table,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final LeaseSerializer serializer,
+ final boolean consistentReads) {
this(table, dynamoDBClient, serializer, consistentReads, TableCreatorCallback.NOOP_TABLE_CREATOR_CALLBACK);
}
@@ -116,10 +119,19 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* @param tableCreatorCallback
*/
@Deprecated
- public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
- final LeaseSerializer serializer, final boolean consistentReads,
- @NonNull final TableCreatorCallback tableCreatorCallback) {
- this(table, dynamoDBClient, serializer, consistentReads, tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT);
+ public DynamoDBLeaseRefresher(
+ final String table,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final LeaseSerializer serializer,
+ final boolean consistentReads,
+ @NonNull final TableCreatorCallback tableCreatorCallback) {
+ this(
+ table,
+ dynamoDBClient,
+ serializer,
+ consistentReads,
+ tableCreatorCallback,
+ LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT);
}
/**
@@ -132,10 +144,22 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* @param dynamoDbRequestTimeout
*/
@Deprecated
- public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
- final LeaseSerializer serializer, final boolean consistentReads,
- @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout) {
- this(table, dynamoDBClient, serializer, consistentReads, tableCreatorCallback, dynamoDbRequestTimeout, BillingMode.PAY_PER_REQUEST, false);
+ public DynamoDBLeaseRefresher(
+ final String table,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final LeaseSerializer serializer,
+ final boolean consistentReads,
+ @NonNull final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout) {
+ this(
+ table,
+ dynamoDBClient,
+ serializer,
+ consistentReads,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ BillingMode.PAY_PER_REQUEST,
+ false);
}
/**
@@ -150,12 +174,25 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* @param leaseTableDeletionProtectionEnabled
*/
@Deprecated
- public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
- final LeaseSerializer serializer, final boolean consistentReads,
- @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
- final BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled) {
- this(table, dynamoDBClient, serializer, consistentReads, tableCreatorCallback, dynamoDbRequestTimeout,
- billingMode, leaseTableDeletionProtectionEnabled, DefaultSdkAutoConstructList.getInstance());
+ public DynamoDBLeaseRefresher(
+ final String table,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final LeaseSerializer serializer,
+ final boolean consistentReads,
+ @NonNull final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ final BillingMode billingMode,
+ final boolean leaseTableDeletionProtectionEnabled) {
+ this(
+ table,
+ dynamoDBClient,
+ serializer,
+ consistentReads,
+ tableCreatorCallback,
+ dynamoDbRequestTimeout,
+ billingMode,
+ leaseTableDeletionProtectionEnabled,
+ DefaultSdkAutoConstructList.getInstance());
}
/**
@@ -170,11 +207,16 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* @param leaseTableDeletionProtectionEnabled
* @param tags
*/
- public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
- final LeaseSerializer serializer, final boolean consistentReads,
- @NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
- final BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled,
- final Collection tags) {
+ public DynamoDBLeaseRefresher(
+ final String table,
+ final DynamoDbAsyncClient dynamoDBClient,
+ final LeaseSerializer serializer,
+ final boolean consistentReads,
+ @NonNull final TableCreatorCallback tableCreatorCallback,
+ Duration dynamoDbRequestTimeout,
+ final BillingMode billingMode,
+ final boolean leaseTableDeletionProtectionEnabled,
+ final Collection tags) {
this.table = table;
this.dynamoDBClient = dynamoDBClient;
this.serializer = serializer;
@@ -194,8 +236,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throws ProvisionedThroughputException, DependencyException {
final CreateTableRequest.Builder builder = createTableRequestBuilder();
if (BillingMode.PROVISIONED.equals(billingMode)) {
- ProvisionedThroughput throughput = ProvisionedThroughput.builder().readCapacityUnits(readCapacity)
- .writeCapacityUnits(writeCapacity).build();
+ ProvisionedThroughput throughput = ProvisionedThroughput.builder()
+ .readCapacityUnits(readCapacity)
+ .writeCapacityUnits(writeCapacity)
+ .build();
builder.provisionedThroughput(throughput);
}
return createTableIfNotExists(builder.build());
@@ -205,8 +249,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* {@inheritDoc}
*/
@Override
- public boolean createLeaseTableIfNotExists()
- throws ProvisionedThroughputException, DependencyException {
+ public boolean createLeaseTableIfNotExists() throws ProvisionedThroughputException, DependencyException {
final CreateTableRequest request = createTableRequestBuilder().build();
return createTableIfNotExists(request);
@@ -259,7 +302,8 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
}
private TableStatus tableStatus() throws DependencyException {
- DescribeTableRequest request = DescribeTableRequest.builder().tableName(table).build();
+ DescribeTableRequest request =
+ DescribeTableRequest.builder().tableName(table).build();
final AWSExceptionManager exceptionManager = createExceptionManager();
exceptionManager.add(ResourceNotFoundException.class, t -> t);
@@ -267,7 +311,8 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
DescribeTableResponse result;
try {
try {
- result = FutureUtils.resolveOrCancelFuture(dynamoDBClient.describeTable(request), dynamoDbRequestTimeout);
+ result = FutureUtils.resolveOrCancelFuture(
+ dynamoDBClient.describeTable(request), dynamoDbRequestTimeout);
} catch (ExecutionException e) {
throw exceptionManager.apply(e.getCause());
} catch (InterruptedException e) {
@@ -332,9 +377,9 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* {@inheritDoc}
*/
@Override
- public List listLeasesForStream(StreamIdentifier streamIdentifier) throws DependencyException,
- InvalidStateException, ProvisionedThroughputException {
- return list( null, streamIdentifier);
+ public List listLeasesForStream(StreamIdentifier streamIdentifier)
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException {
+ return list(null, streamIdentifier);
}
/**
@@ -380,8 +425,8 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
* @throws DependencyException if DynamoDB scan fail in an unexpected way
* @throws ProvisionedThroughputException if DynamoDB scan fail due to exceeded capacity
*/
- private List list(Integer limit, Integer maxPages, StreamIdentifier streamIdentifier) throws DependencyException, InvalidStateException,
- ProvisionedThroughputException {
+ private List list(Integer limit, Integer maxPages, StreamIdentifier streamIdentifier)
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException {
log.debug("Listing leases from table {}", table);
@@ -389,9 +434,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
if (streamIdentifier != null) {
final Map expressionAttributeValues = ImmutableMap.of(
- DDB_STREAM_NAME, AttributeValue.builder().s(streamIdentifier.serialize()).build()
- );
- scanRequestBuilder = scanRequestBuilder.filterExpression(STREAM_NAME + " = " + DDB_STREAM_NAME)
+ DDB_STREAM_NAME,
+ AttributeValue.builder().s(streamIdentifier.serialize()).build());
+ scanRequestBuilder = scanRequestBuilder
+ .filterExpression(STREAM_NAME + " = " + DDB_STREAM_NAME)
.expressionAttributeValues(expressionAttributeValues);
}
@@ -401,12 +447,13 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
ScanRequest scanRequest = scanRequestBuilder.build();
final AWSExceptionManager exceptionManager = createExceptionManager();
- exceptionManager.add(ResourceNotFoundException.class, t -> t);
+ exceptionManager.add(ResourceNotFoundException.class, t -> t);
exceptionManager.add(ProvisionedThroughputExceededException.class, t -> t);
try {
try {
- ScanResponse scanResult = FutureUtils.resolveOrCancelFuture(dynamoDBClient.scan(scanRequest), dynamoDbRequestTimeout);
+ ScanResponse scanResult =
+ FutureUtils.resolveOrCancelFuture(dynamoDBClient.scan(scanRequest), dynamoDbRequestTimeout);
List result = new ArrayList<>();
while (scanResult != null) {
@@ -422,9 +469,12 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
log.debug("lastEvaluatedKey was null - scan finished.");
} else {
// Make another request, picking up where we left off.
- scanRequest = scanRequest.toBuilder().exclusiveStartKey(lastEvaluatedKey).build();
+ scanRequest = scanRequest.toBuilder()
+ .exclusiveStartKey(lastEvaluatedKey)
+ .build();
log.debug("lastEvaluatedKey was {}, continuing scan.", lastEvaluatedKey);
- scanResult = FutureUtils.resolveOrCancelFuture(dynamoDBClient.scan(scanRequest), dynamoDbRequestTimeout);
+ scanResult = FutureUtils.resolveOrCancelFuture(
+ dynamoDBClient.scan(scanRequest), dynamoDbRequestTimeout);
}
}
log.debug("Listed {} leases from table {}", result.size(), table);
@@ -452,8 +502,11 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throws DependencyException, InvalidStateException, ProvisionedThroughputException {
log.debug("Creating lease: {}", lease);
- PutItemRequest request = PutItemRequest.builder().tableName(table).item(serializer.toDynamoRecord(lease))
- .expected(serializer.getDynamoNonexistantExpectation()).build();
+ PutItemRequest request = PutItemRequest.builder()
+ .tableName(table)
+ .item(serializer.toDynamoRecord(lease))
+ .expected(serializer.getDynamoNonexistantExpectation())
+ .build();
final AWSExceptionManager exceptionManager = createExceptionManager();
exceptionManager.add(ConditionalCheckFailedException.class, t -> t);
@@ -485,12 +538,16 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throws DependencyException, InvalidStateException, ProvisionedThroughputException {
log.debug("Getting lease with key {}", leaseKey);
- GetItemRequest request = GetItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(leaseKey))
- .consistentRead(consistentReads).build();
+ GetItemRequest request = GetItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(leaseKey))
+ .consistentRead(consistentReads)
+ .build();
final AWSExceptionManager exceptionManager = createExceptionManager();
try {
try {
- GetItemResponse result = FutureUtils.resolveOrCancelFuture(dynamoDBClient.getItem(request), dynamoDbRequestTimeout);
+ GetItemResponse result =
+ FutureUtils.resolveOrCancelFuture(dynamoDBClient.getItem(request), dynamoDbRequestTimeout);
Map dynamoRecord = result.item();
if (CollectionUtils.isNullOrEmpty(dynamoRecord)) {
@@ -520,12 +577,15 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throws DependencyException, InvalidStateException, ProvisionedThroughputException {
log.debug("Renewing lease with key {}", lease.leaseKey());
- UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease))
+ UpdateItemRequest request = UpdateItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(lease))
.expected(serializer.getDynamoLeaseCounterExpectation(lease))
- .attributeUpdates(serializer.getDynamoLeaseCounterUpdate(lease)).build();
+ .attributeUpdates(serializer.getDynamoLeaseCounterUpdate(lease))
+ .build();
final AWSExceptionManager exceptionManager = createExceptionManager();
- exceptionManager.add(ConditionalCheckFailedException.class, t -> t);
+ exceptionManager.add(ConditionalCheckFailedException.class, t -> t);
try {
try {
@@ -537,8 +597,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throw new DependencyException(e);
}
} catch (ConditionalCheckFailedException e) {
- log.debug("Lease renewal failed for lease with key {} because the lease counter was not {}",
- lease.leaseKey(), lease.leaseCounter());
+ log.debug(
+ "Lease renewal failed for lease with key {} because the lease counter was not {}",
+ lease.leaseKey(),
+ lease.leaseCounter());
// If we had a spurious retry during the Dynamo update, then this conditional PUT failure
// might be incorrect. So, we get the item straight away and check if the lease owner + lease
@@ -546,7 +608,8 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
String expectedOwner = lease.leaseOwner();
Long expectedCounter = lease.leaseCounter() + 1;
final Lease updatedLease = getLease(lease.leaseKey());
- if (updatedLease == null || !expectedOwner.equals(updatedLease.leaseOwner())
+ if (updatedLease == null
+ || !expectedOwner.equals(updatedLease.leaseOwner())
|| !expectedCounter.equals(updatedLease.leaseCounter())) {
return false;
}
@@ -569,8 +632,11 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throws DependencyException, InvalidStateException, ProvisionedThroughputException {
final String oldOwner = lease.leaseOwner();
- log.debug("Taking lease with leaseKey {} from {} to {}", lease.leaseKey(),
- lease.leaseOwner() == null ? "nobody" : lease.leaseOwner(), owner);
+ log.debug(
+ "Taking lease with leaseKey {} from {} to {}",
+ lease.leaseKey(),
+ lease.leaseOwner() == null ? "nobody" : lease.leaseOwner(),
+ owner);
final AWSExceptionManager exceptionManager = createExceptionManager();
exceptionManager.add(ConditionalCheckFailedException.class, t -> t);
@@ -578,8 +644,12 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
Map updates = serializer.getDynamoLeaseCounterUpdate(lease);
updates.putAll(serializer.getDynamoTakeLeaseUpdate(lease, owner));
- UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease))
- .expected(serializer.getDynamoLeaseCounterExpectation(lease)).attributeUpdates(updates).build();
+ UpdateItemRequest request = UpdateItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(lease))
+ .expected(serializer.getDynamoLeaseCounterExpectation(lease))
+ .attributeUpdates(updates)
+ .build();
try {
try {
@@ -591,8 +661,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throw new DependencyException(e);
}
} catch (ConditionalCheckFailedException e) {
- log.debug("Lease renewal failed for lease with key {} because the lease counter was not {}",
- lease.leaseKey(), lease.leaseCounter());
+ log.debug(
+ "Lease renewal failed for lease with key {} because the lease counter was not {}",
+ lease.leaseKey(),
+ lease.leaseCounter());
return false;
} catch (DynamoDbException | TimeoutException e) {
throw convertAndRethrowExceptions("take", lease.leaseKey(), e);
@@ -623,8 +695,12 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
Map updates = serializer.getDynamoLeaseCounterUpdate(lease);
updates.putAll(serializer.getDynamoEvictLeaseUpdate(lease));
- UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease))
- .expected(serializer.getDynamoLeaseOwnerExpectation(lease)).attributeUpdates(updates).build();
+ UpdateItemRequest request = UpdateItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(lease))
+ .expected(serializer.getDynamoLeaseOwnerExpectation(lease))
+ .attributeUpdates(updates)
+ .build();
try {
try {
@@ -636,8 +712,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throw new DependencyException(e);
}
} catch (ConditionalCheckFailedException e) {
- log.debug("Lease eviction failed for lease with key {} because the lease owner was not {}",
- lease.leaseKey(), lease.leaseOwner());
+ log.debug(
+ "Lease eviction failed for lease with key {} because the lease owner was not {}",
+ lease.leaseKey(),
+ lease.leaseOwner());
return false;
} catch (DynamoDbException | TimeoutException e) {
throw convertAndRethrowExceptions("evict", lease.leaseKey(), e);
@@ -660,8 +738,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
final AWSExceptionManager exceptionManager = createExceptionManager();
for (final Lease lease : allLeases) {
- DeleteItemRequest deleteRequest = DeleteItemRequest.builder().tableName(table)
- .key(serializer.getDynamoHashKey(lease)).build();
+ DeleteItemRequest deleteRequest = DeleteItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(lease))
+ .build();
try {
try {
@@ -687,8 +767,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throws DependencyException, InvalidStateException, ProvisionedThroughputException {
log.debug("Deleting lease with leaseKey {}", lease.leaseKey());
- DeleteItemRequest deleteRequest = DeleteItemRequest.builder().tableName(table)
- .key(serializer.getDynamoHashKey(lease)).build();
+ DeleteItemRequest deleteRequest = DeleteItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(lease))
+ .build();
final AWSExceptionManager exceptionManager = createExceptionManager();
try {
@@ -721,8 +803,12 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
Map updates = serializer.getDynamoLeaseCounterUpdate(lease);
updates.putAll(serializer.getDynamoUpdateLeaseUpdate(lease));
- UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease))
- .expected(serializer.getDynamoLeaseCounterExpectation(lease)).attributeUpdates(updates).build();
+ UpdateItemRequest request = UpdateItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(lease))
+ .expected(serializer.getDynamoLeaseCounterExpectation(lease))
+ .attributeUpdates(updates)
+ .build();
try {
try {
@@ -733,8 +819,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throw new DependencyException(e);
}
} catch (ConditionalCheckFailedException e) {
- log.debug("Lease update failed for lease with key {} because the lease counter was not {}",
- lease.leaseKey(), lease.leaseCounter());
+ log.debug(
+ "Lease update failed for lease with key {} because the lease counter was not {}",
+ lease.leaseKey(),
+ lease.leaseCounter());
return false;
} catch (DynamoDbException | TimeoutException e) {
throw convertAndRethrowExceptions("update", lease.leaseKey(), e);
@@ -752,9 +840,12 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
final AWSExceptionManager exceptionManager = createExceptionManager();
exceptionManager.add(ConditionalCheckFailedException.class, t -> t);
Map updates = serializer.getDynamoUpdateLeaseUpdate(lease, updateField);
- UpdateItemRequest request = UpdateItemRequest.builder().tableName(table).key(serializer.getDynamoHashKey(lease))
+ UpdateItemRequest request = UpdateItemRequest.builder()
+ .tableName(table)
+ .key(serializer.getDynamoHashKey(lease))
.expected(serializer.getDynamoExistentExpectation(lease.leaseKey()))
- .attributeUpdates(updates).build();
+ .attributeUpdates(updates)
+ .build();
try {
try {
FutureUtils.resolveOrCancelFuture(dynamoDBClient.updateItem(request), dynamoDbRequestTimeout);
@@ -764,8 +855,10 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throw new DependencyException(e);
}
} catch (ConditionalCheckFailedException e) {
- log.warn("Lease update failed for lease with key {} because the lease did not exist at the time of the update",
- lease.leaseKey(), e);
+ log.warn(
+ "Lease update failed for lease with key {} because the lease did not exist at the time of the update",
+ lease.leaseKey(),
+ e);
} catch (DynamoDbException | TimeoutException e) {
throw convertAndRethrowExceptions("update", lease.leaseKey(), e);
}
@@ -800,8 +893,8 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
throw new ProvisionedThroughputException(e);
} else if (e instanceof ResourceNotFoundException) {
throw new InvalidStateException(
- String.format("Cannot %s lease with key %s because table %s does not exist.",
- operation, leaseKey, table),
+ String.format(
+ "Cannot %s lease with key %s because table %s does not exist.", operation, leaseKey, table),
e);
} else {
return new DependencyException(e);
@@ -809,10 +902,12 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
}
private CreateTableRequest.Builder createTableRequestBuilder() {
- final CreateTableRequest.Builder builder = CreateTableRequest.builder().tableName(table).keySchema(serializer.getKeySchema())
- .attributeDefinitions(serializer.getAttributeDefinitions())
- .deletionProtectionEnabled(leaseTableDeletionProtectionEnabled)
- .tags(tags);
+ final CreateTableRequest.Builder builder = CreateTableRequest.builder()
+ .tableName(table)
+ .keySchema(serializer.getKeySchema())
+ .attributeDefinitions(serializer.getAttributeDefinitions())
+ .deletionProtectionEnabled(leaseTableDeletionProtectionEnabled)
+ .tags(tags);
if (BillingMode.PAY_PER_REQUEST.equals(billingMode)) {
builder.billingMode(billingMode);
}
@@ -826,7 +921,9 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
}
void performPostTableCreationAction() {
- tableCreatorCallback.performAction(
- TableCreatorCallbackInput.builder().dynamoDbClient(dynamoDBClient).tableName(table).build());
+ tableCreatorCallback.performAction(TableCreatorCallbackInput.builder()
+ .dynamoDbClient(dynamoDBClient)
+ .tableName(table)
+ .build());
}
}
diff --git a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewer.java b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewer.java
index ab2d38c5..88a6f9b2 100644
--- a/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewer.java
+++ b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseRenewer.java
@@ -29,11 +29,10 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.lang3.StringUtils;
-
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import software.amazon.awssdk.services.cloudwatch.model.StandardUnit;
import software.amazon.kinesis.annotations.KinesisClientInternalApi;
import software.amazon.kinesis.common.StreamIdentifier;
@@ -78,8 +77,11 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
* @param executorService
* ExecutorService to use for renewing leases in parallel
*/
- public DynamoDBLeaseRenewer(final LeaseRefresher leaseRefresher, final String workerIdentifier,
- final long leaseDurationMillis, final ExecutorService executorService,
+ public DynamoDBLeaseRenewer(
+ final LeaseRefresher leaseRefresher,
+ final String workerIdentifier,
+ final long leaseDurationMillis,
+ final ExecutorService executorService,
final MetricsFactory metricsFactory) {
this.leaseRefresher = leaseRefresher;
this.workerIdentifier = workerIdentifier;
@@ -108,10 +110,10 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
boolean success = false;
try {
- /*
- * We iterate in descending order here so that the synchronized(lease) inside renewLease doesn't "lead" calls
- * to getCurrentlyHeldLeases. They'll still cross paths, but they won't interleave their executions.
- */
+ /*
+ * We iterate in descending order here so that the synchronized(lease) inside renewLease doesn't "lead" calls
+ * to getCurrentlyHeldLeases. They'll still cross paths, but they won't interleave their executions.
+ */
int lostLeases = 0;
List> renewLeaseTasks = new ArrayList<>();
for (Lease lease : ownedLeases.descendingMap().values()) {
@@ -139,8 +141,10 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
scope.addData("CurrentLeases", ownedLeases.size(), StandardUnit.COUNT, MetricsLevel.SUMMARY);
if (leasesInUnknownState > 0) {
throw new DependencyException(
- String.format("Encountered an exception while renewing leases. The number"
- + " of leases which might not have been renewed is %d", leasesInUnknownState),
+ String.format(
+ "Encountered an exception while renewing leases. The number"
+ + " of leases which might not have been renewed is %d",
+ leasesInUnknownState),
lastException);
}
success = true;
@@ -165,7 +169,8 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
return renewLease(lease, false);
}
- private boolean renewLease(Lease lease, boolean renewEvenIfExpired) throws DependencyException, InvalidStateException {
+ private boolean renewLease(Lease lease, boolean renewEvenIfExpired)
+ throws DependencyException, InvalidStateException {
String leaseKey = lease.leaseKey();
final MetricsScope scope = MetricsUtil.createMetricsWithOperation(metricsFactory, RENEW_ALL_LEASES_DIMENSION);
@@ -201,8 +206,12 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
success = true;
break;
} catch (ProvisionedThroughputException e) {
- log.info("Worker {} could not renew lease with key {} on try {} out of {} due to capacity",
- workerIdentifier, leaseKey, i, RENEWAL_RETRIES);
+ log.info(
+ "Worker {} could not renew lease with key {} on try {} out of {} due to capacity",
+ workerIdentifier,
+ leaseKey,
+ i,
+ RENEWAL_RETRIES);
}
}
} finally {
@@ -258,8 +267,8 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
}
if (copy.isExpired(leaseDurationNanos, now)) {
- log.info("getCurrentlyHeldLease not returning lease with key {} because it is expired",
- copy.leaseKey());
+ log.info(
+ "getCurrentlyHeldLease not returning lease with key {} because it is expired", copy.leaseKey());
return null;
} else {
return copy;
@@ -271,8 +280,9 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
* {@inheritDoc}
*/
@Override
- public boolean updateLease(Lease lease, UUID concurrencyToken, @NonNull String operation, String singleStreamShardId)
- throws DependencyException, InvalidStateException, ProvisionedThroughputException {
+ public boolean updateLease(
+ Lease lease, UUID concurrencyToken, @NonNull String operation, String singleStreamShardId)
+ throws DependencyException, InvalidStateException, ProvisionedThroughputException {
verifyNotNull(lease, "lease cannot be null");
verifyNotNull(lease.leaseKey(), "leaseKey cannot be null");
verifyNotNull(concurrencyToken, "concurrencyToken cannot be null");
@@ -281,7 +291,9 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
Lease authoritativeLease = ownedLeases.get(leaseKey);
if (authoritativeLease == null) {
- log.info("Worker {} could not update lease with key {} because it does not hold it", workerIdentifier,
+ log.info(
+ "Worker {} could not update lease with key {} because it does not hold it",
+ workerIdentifier,
leaseKey);
return false;
}
@@ -292,15 +304,17 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
* called update.
*/
if (!authoritativeLease.concurrencyToken().equals(concurrencyToken)) {
- log.info("Worker {} refusing to update lease with key {} because concurrency tokens don't match",
- workerIdentifier, leaseKey);
+ log.info(
+ "Worker {} refusing to update lease with key {} because concurrency tokens don't match",
+ workerIdentifier,
+ leaseKey);
return false;
}
final MetricsScope scope = MetricsUtil.createMetricsWithOperation(metricsFactory, operation);
if (lease instanceof MultiStreamLease) {
- MetricsUtil.addStreamId(scope,
- StreamIdentifier.multiStreamInstance(((MultiStreamLease) lease).streamIdentifier()));
+ MetricsUtil.addStreamId(
+ scope, StreamIdentifier.multiStreamInstance(((MultiStreamLease) lease).streamIdentifier()));
MetricsUtil.addShardId(scope, ((MultiStreamLease) lease).shardId());
} else if (StringUtils.isNotEmpty(singleStreamShardId)) {
MetricsUtil.addShardId(scope, singleStreamShardId);
@@ -359,7 +373,8 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
for (Lease lease : newLeases) {
if (lease.lastCounterIncrementNanos() == null) {
- log.info("addLeasesToRenew ignoring lease with key {} because it does not have lastRenewalNanos set",
+ log.info(
+ "addLeasesToRenew ignoring lease with key {} because it does not have lastRenewalNanos set",
lease.leaseKey());
continue;
}
@@ -424,5 +439,4 @@ public class DynamoDBLeaseRenewer implements LeaseRenewer {
throw new IllegalArgumentException(message);
}
}
-
}
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 7e12b9a9..c10cf475 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
@@ -20,7 +20,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import com.google.common.base.Strings;
import software.amazon.awssdk.services.dynamodb.model.AttributeAction;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
@@ -71,8 +70,12 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer {
}
result.put(OWNER_SWITCHES_KEY, DynamoUtils.createAttributeValue(lease.ownerSwitchesSinceCheckpoint()));
- result.put(CHECKPOINT_SEQUENCE_NUMBER_KEY, DynamoUtils.createAttributeValue(lease.checkpoint().sequenceNumber()));
- result.put(CHECKPOINT_SUBSEQUENCE_NUMBER_KEY, DynamoUtils.createAttributeValue(lease.checkpoint().subSequenceNumber()));
+ result.put(
+ CHECKPOINT_SEQUENCE_NUMBER_KEY,
+ DynamoUtils.createAttributeValue(lease.checkpoint().sequenceNumber()));
+ result.put(
+ CHECKPOINT_SUBSEQUENCE_NUMBER_KEY,
+ DynamoUtils.createAttributeValue(lease.checkpoint().subSequenceNumber()));
if (lease.parentShardIds() != null && !lease.parentShardIds().isEmpty()) {
result.put(PARENT_SHARD_ID_KEY, DynamoUtils.createAttributeValue(lease.parentShardIds()));
}
@@ -80,18 +83,31 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer {
result.put(CHILD_SHARD_IDS_KEY, DynamoUtils.createAttributeValue(lease.childShardIds()));
}
- if (lease.pendingCheckpoint() != null && !lease.pendingCheckpoint().sequenceNumber().isEmpty()) {
- result.put(PENDING_CHECKPOINT_SEQUENCE_KEY, DynamoUtils.createAttributeValue(lease.pendingCheckpoint().sequenceNumber()));
- result.put(PENDING_CHECKPOINT_SUBSEQUENCE_KEY, DynamoUtils.createAttributeValue(lease.pendingCheckpoint().subSequenceNumber()));
+ if (lease.pendingCheckpoint() != null
+ && !lease.pendingCheckpoint().sequenceNumber().isEmpty()) {
+ result.put(
+ PENDING_CHECKPOINT_SEQUENCE_KEY,
+ DynamoUtils.createAttributeValue(lease.pendingCheckpoint().sequenceNumber()));
+ result.put(
+ PENDING_CHECKPOINT_SUBSEQUENCE_KEY,
+ DynamoUtils.createAttributeValue(lease.pendingCheckpoint().subSequenceNumber()));
}
if (lease.pendingCheckpointState() != null) {
- result.put(PENDING_CHECKPOINT_STATE_KEY, DynamoUtils.createAttributeValue(lease.checkpoint().subSequenceNumber()));
+ result.put(
+ PENDING_CHECKPOINT_STATE_KEY,
+ DynamoUtils.createAttributeValue(lease.checkpoint().subSequenceNumber()));
}
if (lease.hashKeyRangeForLease() != null) {
- result.put(STARTING_HASH_KEY, DynamoUtils.createAttributeValue(lease.hashKeyRangeForLease().serializedStartingHashKey()));
- result.put(ENDING_HASH_KEY, DynamoUtils.createAttributeValue(lease.hashKeyRangeForLease().serializedEndingHashKey()));
+ result.put(
+ STARTING_HASH_KEY,
+ DynamoUtils.createAttributeValue(
+ lease.hashKeyRangeForLease().serializedStartingHashKey()));
+ result.put(
+ ENDING_HASH_KEY,
+ DynamoUtils.createAttributeValue(
+ lease.hashKeyRangeForLease().serializedEndingHashKey()));
}
return result;
@@ -110,20 +126,16 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer {
leaseToUpdate.leaseCounter(DynamoUtils.safeGetLong(dynamoRecord, LEASE_COUNTER_KEY));
leaseToUpdate.ownerSwitchesSinceCheckpoint(DynamoUtils.safeGetLong(dynamoRecord, OWNER_SWITCHES_KEY));
- leaseToUpdate.checkpoint(
- new ExtendedSequenceNumber(
- DynamoUtils.safeGetString(dynamoRecord, CHECKPOINT_SEQUENCE_NUMBER_KEY),
- DynamoUtils.safeGetLong(dynamoRecord, CHECKPOINT_SUBSEQUENCE_NUMBER_KEY))
- );
+ leaseToUpdate.checkpoint(new ExtendedSequenceNumber(
+ DynamoUtils.safeGetString(dynamoRecord, CHECKPOINT_SEQUENCE_NUMBER_KEY),
+ DynamoUtils.safeGetLong(dynamoRecord, CHECKPOINT_SUBSEQUENCE_NUMBER_KEY)));
leaseToUpdate.parentShardIds(DynamoUtils.safeGetSS(dynamoRecord, PARENT_SHARD_ID_KEY));
leaseToUpdate.childShardIds(DynamoUtils.safeGetSS(dynamoRecord, CHILD_SHARD_IDS_KEY));
if (!Strings.isNullOrEmpty(DynamoUtils.safeGetString(dynamoRecord, PENDING_CHECKPOINT_SEQUENCE_KEY))) {
- leaseToUpdate.pendingCheckpoint(
- new ExtendedSequenceNumber(
- DynamoUtils.safeGetString(dynamoRecord, PENDING_CHECKPOINT_SEQUENCE_KEY),
- DynamoUtils.safeGetLong(dynamoRecord, PENDING_CHECKPOINT_SUBSEQUENCE_KEY))
- );
+ leaseToUpdate.pendingCheckpoint(new ExtendedSequenceNumber(
+ DynamoUtils.safeGetString(dynamoRecord, PENDING_CHECKPOINT_SEQUENCE_KEY),
+ DynamoUtils.safeGetLong(dynamoRecord, PENDING_CHECKPOINT_SUBSEQUENCE_KEY)));
}
leaseToUpdate.pendingCheckpointState(DynamoUtils.safeGetByteArray(dynamoRecord, PENDING_CHECKPOINT_STATE_KEY));
@@ -159,7 +171,9 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer {
public Map getDynamoLeaseCounterExpectation(final Long leaseCounter) {
Map result = new HashMap<>();
- ExpectedAttributeValue eav = ExpectedAttributeValue.builder().value(DynamoUtils.createAttributeValue(leaseCounter)).build();
+ ExpectedAttributeValue eav = ExpectedAttributeValue.builder()
+ .value(DynamoUtils.createAttributeValue(leaseCounter))
+ .build();
result.put(LEASE_COUNTER_KEY, eav);
return result;
@@ -170,13 +184,13 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer {
Map result = new HashMap<>();
ExpectedAttributeValue.Builder eavBuilder = ExpectedAttributeValue.builder();
-
+
if (lease.leaseOwner() == null) {
eavBuilder = eavBuilder.exists(false);
} else {
eavBuilder = eavBuilder.value(DynamoUtils.createAttributeValue(lease.leaseOwner()));
}
-
+
result.put(LEASE_OWNER_KEY, eavBuilder.build());
return result;
@@ -186,7 +200,8 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer {
public Map getDynamoNonexistantExpectation() {
Map result = new HashMap<>();
- ExpectedAttributeValue expectedAV = ExpectedAttributeValue.builder().exists(false).build();
+ ExpectedAttributeValue expectedAV =
+ ExpectedAttributeValue.builder().exists(false).build();
result.put(LEASE_KEY_KEY, expectedAV);
return result;
@@ -213,8 +228,10 @@ public class DynamoDBLeaseSerializer implements LeaseSerializer {
public Map getDynamoLeaseCounterUpdate(Long leaseCounter) {
Map