Add Deletion protection config (#1260)
* Add deletionProtectionEnabled config
This commit is contained in:
parent
2d769733fe
commit
b2eb38e510
6 changed files with 73 additions and 15 deletions
|
|
@ -194,6 +194,13 @@ public class LeaseManagementConfig {
|
||||||
|
|
||||||
private BillingMode billingMode = BillingMode.PAY_PER_REQUEST;
|
private BillingMode billingMode = BillingMode.PAY_PER_REQUEST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to enabled deletion protection on the DynamoDB lease table created by KCL.
|
||||||
|
*
|
||||||
|
* <p>Default value: false
|
||||||
|
*/
|
||||||
|
private boolean leaseTableDeletionProtectionEnabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of tags to be applied to the DynamoDB table created for lease management.
|
* The list of tags to be applied to the DynamoDB table created for lease management.
|
||||||
*
|
*
|
||||||
|
|
@ -382,6 +389,7 @@ public class LeaseManagementConfig {
|
||||||
tableCreatorCallback(),
|
tableCreatorCallback(),
|
||||||
dynamoDbRequestTimeout(),
|
dynamoDbRequestTimeout(),
|
||||||
billingMode(),
|
billingMode(),
|
||||||
|
leaseTableDeletionProtectionEnabled(),
|
||||||
tags(),
|
tags(),
|
||||||
leaseSerializer,
|
leaseSerializer,
|
||||||
customShardDetectorProvider(),
|
customShardDetectorProvider(),
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
private final TableCreatorCallback tableCreatorCallback;
|
private final TableCreatorCallback tableCreatorCallback;
|
||||||
private final Duration dynamoDbRequestTimeout;
|
private final Duration dynamoDbRequestTimeout;
|
||||||
private final BillingMode billingMode;
|
private final BillingMode billingMode;
|
||||||
|
private final boolean leaseTableDeletionProtectionEnabled;
|
||||||
private final Collection<Tag> tags;
|
private final Collection<Tag> tags;
|
||||||
private final boolean isMultiStreamMode;
|
private final boolean isMultiStreamMode;
|
||||||
private final LeaseCleanupConfig leaseCleanupConfig;
|
private final LeaseCleanupConfig leaseCleanupConfig;
|
||||||
|
|
@ -450,7 +451,7 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
|
ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
|
||||||
maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
|
maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
|
||||||
cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
|
cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
|
||||||
deprecatedHierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode,
|
deprecatedHierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode, false,
|
||||||
DefaultSdkAutoConstructList.getInstance(), leaseSerializer);
|
DefaultSdkAutoConstructList.getInstance(), leaseSerializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -483,6 +484,7 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
* @param tableCreatorCallback
|
* @param tableCreatorCallback
|
||||||
* @param dynamoDbRequestTimeout
|
* @param dynamoDbRequestTimeout
|
||||||
* @param billingMode
|
* @param billingMode
|
||||||
|
* @param leaseTableDeletionProtectionEnabled
|
||||||
* @param tags
|
* @param tags
|
||||||
*/
|
*/
|
||||||
private DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final StreamConfig streamConfig,
|
private DynamoDBLeaseManagementFactory(final KinesisAsyncClient kinesisClient, final StreamConfig streamConfig,
|
||||||
|
|
@ -495,15 +497,17 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
|
final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
|
||||||
final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
|
final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
|
||||||
final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
|
final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
|
||||||
Duration dynamoDbRequestTimeout, BillingMode billingMode, Collection<Tag> tags, LeaseSerializer leaseSerializer) {
|
Duration dynamoDbRequestTimeout, BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled,
|
||||||
|
Collection<Tag> tags, LeaseSerializer leaseSerializer) {
|
||||||
this(kinesisClient, dynamoDBClient, tableName,
|
this(kinesisClient, dynamoDBClient, tableName,
|
||||||
workerIdentifier, executorService, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
|
workerIdentifier, executorService, failoverTimeMillis, epsilonMillis, maxLeasesForWorker,
|
||||||
maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
|
maxLeasesToStealAtOneTime, maxLeaseRenewalThreads, cleanupLeasesUponShardCompletion,
|
||||||
ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
|
ignoreUnexpectedChildShards, shardSyncIntervalMillis, consistentReads, listShardsBackoffTimeMillis,
|
||||||
maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
|
maxListShardsRetryAttempts, maxCacheMissesBeforeReload, listShardsCacheAllowedAgeInSeconds,
|
||||||
cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
|
cacheMissWarningModulus, initialLeaseTableReadCapacity, initialLeaseTableWriteCapacity,
|
||||||
deprecatedHierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode, tags, leaseSerializer,
|
deprecatedHierarchicalShardSyncer, tableCreatorCallback, dynamoDbRequestTimeout, billingMode,
|
||||||
null, false, LeaseManagementConfig.DEFAULT_LEASE_CLEANUP_CONFIG);
|
leaseTableDeletionProtectionEnabled, tags, leaseSerializer, null, false,
|
||||||
|
LeaseManagementConfig.DEFAULT_LEASE_CLEANUP_CONFIG);
|
||||||
this.streamConfig = streamConfig;
|
this.streamConfig = streamConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -534,6 +538,7 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
* @param tableCreatorCallback
|
* @param tableCreatorCallback
|
||||||
* @param dynamoDbRequestTimeout
|
* @param dynamoDbRequestTimeout
|
||||||
* @param billingMode
|
* @param billingMode
|
||||||
|
* @param leaseTableDeletionProtectionEnabled
|
||||||
* @param leaseSerializer
|
* @param leaseSerializer
|
||||||
* @param customShardDetectorProvider
|
* @param customShardDetectorProvider
|
||||||
* @param isMultiStreamMode
|
* @param isMultiStreamMode
|
||||||
|
|
@ -549,7 +554,8 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
|
final long listShardsCacheAllowedAgeInSeconds, final int cacheMissWarningModulus,
|
||||||
final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
|
final long initialLeaseTableReadCapacity, final long initialLeaseTableWriteCapacity,
|
||||||
final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
|
final HierarchicalShardSyncer deprecatedHierarchicalShardSyncer, final TableCreatorCallback tableCreatorCallback,
|
||||||
Duration dynamoDbRequestTimeout, BillingMode billingMode, Collection<Tag> tags, LeaseSerializer leaseSerializer,
|
Duration dynamoDbRequestTimeout, BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled,
|
||||||
|
Collection<Tag> tags, LeaseSerializer leaseSerializer,
|
||||||
Function<StreamConfig, ShardDetector> customShardDetectorProvider, boolean isMultiStreamMode,
|
Function<StreamConfig, ShardDetector> customShardDetectorProvider, boolean isMultiStreamMode,
|
||||||
LeaseCleanupConfig leaseCleanupConfig) {
|
LeaseCleanupConfig leaseCleanupConfig) {
|
||||||
this.kinesisClient = kinesisClient;
|
this.kinesisClient = kinesisClient;
|
||||||
|
|
@ -577,6 +583,7 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
this.tableCreatorCallback = tableCreatorCallback;
|
this.tableCreatorCallback = tableCreatorCallback;
|
||||||
this.dynamoDbRequestTimeout = dynamoDbRequestTimeout;
|
this.dynamoDbRequestTimeout = dynamoDbRequestTimeout;
|
||||||
this.billingMode = billingMode;
|
this.billingMode = billingMode;
|
||||||
|
this.leaseTableDeletionProtectionEnabled = leaseTableDeletionProtectionEnabled;
|
||||||
this.leaseSerializer = leaseSerializer;
|
this.leaseSerializer = leaseSerializer;
|
||||||
this.customShardDetectorProvider = customShardDetectorProvider;
|
this.customShardDetectorProvider = customShardDetectorProvider;
|
||||||
this.isMultiStreamMode = isMultiStreamMode;
|
this.isMultiStreamMode = isMultiStreamMode;
|
||||||
|
|
@ -648,7 +655,7 @@ public class DynamoDBLeaseManagementFactory implements LeaseManagementFactory {
|
||||||
@Override
|
@Override
|
||||||
public DynamoDBLeaseRefresher createLeaseRefresher() {
|
public DynamoDBLeaseRefresher createLeaseRefresher() {
|
||||||
return new DynamoDBLeaseRefresher(tableName, dynamoDBClient, leaseSerializer, consistentReads,
|
return new DynamoDBLeaseRefresher(tableName, dynamoDBClient, leaseSerializer, consistentReads,
|
||||||
tableCreatorCallback, dynamoDbRequestTimeout, billingMode, tags);
|
tableCreatorCallback, dynamoDbRequestTimeout, billingMode, leaseTableDeletionProtectionEnabled, tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
|
|
||||||
private final Duration dynamoDbRequestTimeout;
|
private final Duration dynamoDbRequestTimeout;
|
||||||
private final BillingMode billingMode;
|
private final BillingMode billingMode;
|
||||||
|
private final boolean leaseTableDeletionProtectionEnabled;
|
||||||
private final Collection<Tag> tags;
|
private final Collection<Tag> tags;
|
||||||
|
|
||||||
private boolean newTableCreated = false;
|
private boolean newTableCreated = false;
|
||||||
|
|
@ -134,7 +135,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
|
public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
|
||||||
final LeaseSerializer serializer, final boolean consistentReads,
|
final LeaseSerializer serializer, final boolean consistentReads,
|
||||||
@NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout) {
|
@NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout) {
|
||||||
this(table, dynamoDBClient, serializer, consistentReads, tableCreatorCallback, dynamoDbRequestTimeout, BillingMode.PAY_PER_REQUEST);
|
this(table, dynamoDBClient, serializer, consistentReads, tableCreatorCallback, dynamoDbRequestTimeout, BillingMode.PAY_PER_REQUEST, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -146,14 +147,15 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
* @param tableCreatorCallback
|
* @param tableCreatorCallback
|
||||||
* @param dynamoDbRequestTimeout
|
* @param dynamoDbRequestTimeout
|
||||||
* @param billingMode
|
* @param billingMode
|
||||||
|
* @param leaseTableDeletionProtectionEnabled
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
|
public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
|
||||||
final LeaseSerializer serializer, final boolean consistentReads,
|
final LeaseSerializer serializer, final boolean consistentReads,
|
||||||
@NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
|
@NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
|
||||||
final BillingMode billingMode) {
|
final BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled) {
|
||||||
this(table, dynamoDBClient, serializer, consistentReads, tableCreatorCallback, dynamoDbRequestTimeout,
|
this(table, dynamoDBClient, serializer, consistentReads, tableCreatorCallback, dynamoDbRequestTimeout,
|
||||||
billingMode, DefaultSdkAutoConstructList.getInstance());
|
billingMode, leaseTableDeletionProtectionEnabled, DefaultSdkAutoConstructList.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -165,12 +167,14 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
* @param tableCreatorCallback
|
* @param tableCreatorCallback
|
||||||
* @param dynamoDbRequestTimeout
|
* @param dynamoDbRequestTimeout
|
||||||
* @param billingMode
|
* @param billingMode
|
||||||
|
* @param leaseTableDeletionProtectionEnabled
|
||||||
* @param tags
|
* @param tags
|
||||||
*/
|
*/
|
||||||
public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
|
public DynamoDBLeaseRefresher(final String table, final DynamoDbAsyncClient dynamoDBClient,
|
||||||
final LeaseSerializer serializer, final boolean consistentReads,
|
final LeaseSerializer serializer, final boolean consistentReads,
|
||||||
@NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
|
@NonNull final TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout,
|
||||||
final BillingMode billingMode, final Collection<Tag> tags) {
|
final BillingMode billingMode, final boolean leaseTableDeletionProtectionEnabled,
|
||||||
|
final Collection<Tag> tags) {
|
||||||
this.table = table;
|
this.table = table;
|
||||||
this.dynamoDBClient = dynamoDBClient;
|
this.dynamoDBClient = dynamoDBClient;
|
||||||
this.serializer = serializer;
|
this.serializer = serializer;
|
||||||
|
|
@ -178,6 +182,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
this.tableCreatorCallback = tableCreatorCallback;
|
this.tableCreatorCallback = tableCreatorCallback;
|
||||||
this.dynamoDbRequestTimeout = dynamoDbRequestTimeout;
|
this.dynamoDbRequestTimeout = dynamoDbRequestTimeout;
|
||||||
this.billingMode = billingMode;
|
this.billingMode = billingMode;
|
||||||
|
this.leaseTableDeletionProtectionEnabled = leaseTableDeletionProtectionEnabled;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -806,6 +811,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
private CreateTableRequest.Builder createTableRequestBuilder() {
|
private CreateTableRequest.Builder createTableRequestBuilder() {
|
||||||
final CreateTableRequest.Builder builder = CreateTableRequest.builder().tableName(table).keySchema(serializer.getKeySchema())
|
final CreateTableRequest.Builder builder = CreateTableRequest.builder().tableName(table).keySchema(serializer.getKeySchema())
|
||||||
.attributeDefinitions(serializer.getAttributeDefinitions())
|
.attributeDefinitions(serializer.getAttributeDefinitions())
|
||||||
|
.deletionProtectionEnabled(leaseTableDeletionProtectionEnabled)
|
||||||
.tags(tags);
|
.tags(tags);
|
||||||
if (BillingMode.PAY_PER_REQUEST.equals(billingMode)) {
|
if (BillingMode.PAY_PER_REQUEST.equals(billingMode)) {
|
||||||
builder.billingMode(billingMode);
|
builder.billingMode(billingMode);
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,6 @@ public class LeaseIntegrationBillingModePayPerRequestTest extends LeaseIntegrati
|
||||||
@Override
|
@Override
|
||||||
protected DynamoDBLeaseRefresher getLeaseRefresher() {
|
protected DynamoDBLeaseRefresher getLeaseRefresher() {
|
||||||
return new DynamoDBLeaseRefresher(tableName+"Per-Request", ddbClient, leaseSerializer, true,
|
return new DynamoDBLeaseRefresher(tableName+"Per-Request", ddbClient, leaseSerializer, true,
|
||||||
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PAY_PER_REQUEST);
|
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PAY_PER_REQUEST, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ public class LeaseIntegrationTest {
|
||||||
|
|
||||||
protected DynamoDBLeaseRefresher getLeaseRefresher() {
|
protected DynamoDBLeaseRefresher getLeaseRefresher() {
|
||||||
return new DynamoDBLeaseRefresher(tableName, ddbClient, leaseSerializer, true,
|
return new DynamoDBLeaseRefresher(tableName, ddbClient, leaseSerializer, true,
|
||||||
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PAY_PER_REQUEST);
|
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PAY_PER_REQUEST, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
|
|
||||||
private static final String TABLE_NAME = "test";
|
private static final String TABLE_NAME = "test";
|
||||||
private static final boolean CONSISTENT_READS = true;
|
private static final boolean CONSISTENT_READS = true;
|
||||||
|
private static final boolean DELETION_PROTECTION_ENABLED = false;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private DynamoDbAsyncClient dynamoDbClient;
|
private DynamoDbAsyncClient dynamoDbClient;
|
||||||
|
|
@ -127,6 +128,7 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
.keySchema(leaseSerializer.getKeySchema())
|
.keySchema(leaseSerializer.getKeySchema())
|
||||||
.attributeDefinitions(leaseSerializer.getAttributeDefinitions())
|
.attributeDefinitions(leaseSerializer.getAttributeDefinitions())
|
||||||
.billingMode(BillingMode.PAY_PER_REQUEST)
|
.billingMode(BillingMode.PAY_PER_REQUEST)
|
||||||
|
.deletionProtectionEnabled(DELETION_PROTECTION_ENABLED)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,7 +288,7 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCreateLeaseTableProvisionedBillingModeIfNotExists() throws Exception {
|
public void testCreateLeaseTableProvisionedBillingModeIfNotExists() throws Exception {
|
||||||
leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
|
leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
|
||||||
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PROVISIONED);
|
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PROVISIONED, DELETION_PROTECTION_ENABLED);
|
||||||
|
|
||||||
when(dynamoDbClient.describeTable(describeTableRequest)).thenReturn(mockDescribeTableFuture);
|
when(dynamoDbClient.describeTable(describeTableRequest)).thenReturn(mockDescribeTableFuture);
|
||||||
when(mockDescribeTableFuture.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS)))
|
when(mockDescribeTableFuture.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS)))
|
||||||
|
|
@ -299,6 +301,7 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
.keySchema(leaseSerializer.getKeySchema())
|
.keySchema(leaseSerializer.getKeySchema())
|
||||||
.attributeDefinitions(leaseSerializer.getAttributeDefinitions())
|
.attributeDefinitions(leaseSerializer.getAttributeDefinitions())
|
||||||
.provisionedThroughput(throughput)
|
.provisionedThroughput(throughput)
|
||||||
|
.deletionProtectionEnabled(DELETION_PROTECTION_ENABLED)
|
||||||
.build();
|
.build();
|
||||||
when(dynamoDbClient.createTable(createTableRequest)).thenReturn(mockCreateTableFuture);
|
when(dynamoDbClient.createTable(createTableRequest)).thenReturn(mockCreateTableFuture);
|
||||||
when(mockCreateTableFuture.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS)))
|
when(mockCreateTableFuture.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS)))
|
||||||
|
|
@ -319,7 +322,7 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
public void testCreateLeaseTableWithTagsIfNotExists() throws Exception {
|
public void testCreateLeaseTableWithTagsIfNotExists() throws Exception {
|
||||||
tags = Collections.singletonList(Tag.builder().key("foo").value("bar").build());
|
tags = Collections.singletonList(Tag.builder().key("foo").value("bar").build());
|
||||||
leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
|
leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
|
||||||
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PROVISIONED, tags);
|
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PROVISIONED, DELETION_PROTECTION_ENABLED, tags);
|
||||||
|
|
||||||
when(dynamoDbClient.describeTable(describeTableRequest)).thenReturn(mockDescribeTableFuture);
|
when(dynamoDbClient.describeTable(describeTableRequest)).thenReturn(mockDescribeTableFuture);
|
||||||
when(mockDescribeTableFuture.get(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS))
|
when(mockDescribeTableFuture.get(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS))
|
||||||
|
|
@ -332,6 +335,7 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
.keySchema(leaseSerializer.getKeySchema())
|
.keySchema(leaseSerializer.getKeySchema())
|
||||||
.attributeDefinitions(leaseSerializer.getAttributeDefinitions())
|
.attributeDefinitions(leaseSerializer.getAttributeDefinitions())
|
||||||
.provisionedThroughput(throughput)
|
.provisionedThroughput(throughput)
|
||||||
|
.deletionProtectionEnabled(DELETION_PROTECTION_ENABLED)
|
||||||
.tags(tags)
|
.tags(tags)
|
||||||
.build();
|
.build();
|
||||||
when(dynamoDbClient.createTable(createTableRequest)).thenReturn(mockCreateTableFuture);
|
when(dynamoDbClient.createTable(createTableRequest)).thenReturn(mockCreateTableFuture);
|
||||||
|
|
@ -369,6 +373,39 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
Assert.assertTrue(result);
|
Assert.assertTrue(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateLeaseTableProvisionedWithDeletionProtectionIfNotExists() throws Exception {
|
||||||
|
leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
|
||||||
|
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PROVISIONED, true);
|
||||||
|
|
||||||
|
when(dynamoDbClient.describeTable(describeTableRequest)).thenReturn(mockDescribeTableFuture);
|
||||||
|
when(mockDescribeTableFuture.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS)))
|
||||||
|
.thenThrow(ResourceNotFoundException.builder().message("Table doesn't exist").build());
|
||||||
|
|
||||||
|
final ProvisionedThroughput throughput = ProvisionedThroughput.builder().readCapacityUnits(10L)
|
||||||
|
.writeCapacityUnits(10L).build();
|
||||||
|
final CreateTableRequest createTableRequest = CreateTableRequest.builder()
|
||||||
|
.tableName(TABLE_NAME)
|
||||||
|
.keySchema(leaseSerializer.getKeySchema())
|
||||||
|
.attributeDefinitions(leaseSerializer.getAttributeDefinitions())
|
||||||
|
.provisionedThroughput(throughput)
|
||||||
|
.deletionProtectionEnabled(true)
|
||||||
|
.build();
|
||||||
|
when(dynamoDbClient.createTable(createTableRequest)).thenReturn(mockCreateTableFuture);
|
||||||
|
when(mockCreateTableFuture.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS)))
|
||||||
|
.thenReturn(null);
|
||||||
|
|
||||||
|
final boolean result = leaseRefresher.createLeaseTableIfNotExists(10L, 10L);
|
||||||
|
|
||||||
|
verify(dynamoDbClient, times(1)).describeTable(describeTableRequest);
|
||||||
|
verify(dynamoDbClient, times(1)).createTable(createTableRequest);
|
||||||
|
verify(mockDescribeTableFuture, times(1))
|
||||||
|
.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS));
|
||||||
|
verify(mockCreateTableFuture, times(1))
|
||||||
|
.get(eq(LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT.toMillis()), eq(TimeUnit.MILLISECONDS));
|
||||||
|
Assert.assertTrue(result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateLeaseTableIfNotExists_throwsDependencyException() throws Exception {
|
public void testCreateLeaseTableIfNotExists_throwsDependencyException() throws Exception {
|
||||||
when(dynamoDbClient.describeTable(describeTableRequest)).thenReturn(mockDescribeTableFuture);
|
when(dynamoDbClient.describeTable(describeTableRequest)).thenReturn(mockDescribeTableFuture);
|
||||||
|
|
@ -462,7 +499,7 @@ public class DynamoDBLeaseRefresherTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCreateLeaseTableProvisionedBillingModeTimesOut() throws Exception {
|
public void testCreateLeaseTableProvisionedBillingModeTimesOut() throws Exception {
|
||||||
leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
|
leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
|
||||||
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PROVISIONED);
|
tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PROVISIONED, false);
|
||||||
TimeoutException te = setRuleForDependencyTimeout();
|
TimeoutException te = setRuleForDependencyTimeout();
|
||||||
|
|
||||||
when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
|
when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue