Add unit test
This commit is contained in:
parent
8c8e933071
commit
49499f6697
1 changed files with 33 additions and 0 deletions
|
|
@ -373,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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue