DDB is considered healthy in UPDATING status

This commit is contained in:
Cai41 2020-06-05 15:45:22 -07:00 committed by Cory-Bradshaw
parent be1e3cd112
commit 87677255e1
2 changed files with 46 additions and 1 deletions

View file

@ -190,7 +190,8 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
*/ */
@Override @Override
public boolean leaseTableExists() throws DependencyException { public boolean leaseTableExists() throws DependencyException {
return TableStatus.ACTIVE == tableStatus(); TableStatus tableStatus = tableStatus();
return TableStatus.ACTIVE == tableStatus || TableStatus.UPDATING == tableStatus;
} }
private TableStatus tableStatus() throws DependencyException { private TableStatus tableStatus() throws DependencyException {

View file

@ -15,6 +15,8 @@
package software.amazon.kinesis.leases.dynamodb; package software.amazon.kinesis.leases.dynamodb;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyLong;
@ -54,6 +56,8 @@ import software.amazon.awssdk.services.dynamodb.model.PutItemResponse;
import software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException; import software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException;
import software.amazon.awssdk.services.dynamodb.model.ScanRequest; import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
import software.amazon.awssdk.services.dynamodb.model.ScanResponse; import software.amazon.awssdk.services.dynamodb.model.ScanResponse;
import software.amazon.awssdk.services.dynamodb.model.TableDescription;
import software.amazon.awssdk.services.dynamodb.model.TableStatus;
import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest; import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest;
import software.amazon.awssdk.services.dynamodb.model.UpdateItemResponse; import software.amazon.awssdk.services.dynamodb.model.UpdateItemResponse;
import software.amazon.awssdk.services.dynamodb.model.BillingMode; import software.amazon.awssdk.services.dynamodb.model.BillingMode;
@ -149,6 +153,46 @@ public class DynamoDBLeaseRefresherTest {
verifyCancel(mockPutItemFuture, () -> leaseRefresher.createLeaseIfNotExists(lease)); verifyCancel(mockPutItemFuture, () -> leaseRefresher.createLeaseIfNotExists(lease));
} }
@Test
public void testWaitUntilLeaseTableExistsUpdatingStatus() throws Exception {
when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
when(mockDescribeTableFuture.get(anyLong(), any()))
.thenReturn(DescribeTableResponse.builder()
.table(TableDescription.builder().tableStatus(TableStatus.UPDATING).build())
.build());
assertTrue(leaseRefresher.waitUntilLeaseTableExists(0, 0));
}
@Test
public void testWaitUntilLeaseTableExistsActiveStatus() throws Exception {
when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
when(mockDescribeTableFuture.get(anyLong(), any()))
.thenReturn(DescribeTableResponse.builder()
.table(TableDescription.builder().tableStatus(TableStatus.ACTIVE).build())
.build());
assertTrue(leaseRefresher.waitUntilLeaseTableExists(0, 0));
}
@Test
public void testWaitUntilLeaseTableExistsCreatingStatus() throws Exception {
when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
when(mockDescribeTableFuture.get(anyLong(), any()))
.thenReturn(DescribeTableResponse.builder()
.table(TableDescription.builder().tableStatus(TableStatus.CREATING).build())
.build());
assertFalse(leaseRefresher.waitUntilLeaseTableExists(0, 0));
}
@Test
public void testWaitUntilLeaseTableExistsDeletingStatus() throws Exception {
when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
when(mockDescribeTableFuture.get(anyLong(), any()))
.thenReturn(DescribeTableResponse.builder()
.table(TableDescription.builder().tableStatus(TableStatus.DELETING).build())
.build());
assertFalse(leaseRefresher.waitUntilLeaseTableExists(0, 0));
}
@Test @Test
public void testGetLeaseTimesOut() throws Exception { public void testGetLeaseTimesOut() throws Exception {
TimeoutException te = setRuleForDependencyTimeout(); TimeoutException te = setRuleForDependencyTimeout();