/** * A convenient blocking call that can be used, typically during table * deletion, to wait for the table to become deleted. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. */ public void waitForDelete() throws InterruptedException { Waiter waiter = client.waiters().tableNotExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); } catch (Exception exception) { throw new IllegalArgumentException("Table " + tableName + " is not deleted.", exception); } }
/** * A convenient blocking call that can be used, typically during table * creation, to wait for the table to become active. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. * * @return the table description when the table has become active * * @throws IllegalArgumentException if the table is being deleted * @throws ResourceNotFoundException if the table doesn't exist */ public TableDescription waitForActive() throws InterruptedException { Waiter waiter = client.waiters().tableExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); return describe(); } catch (Exception exception) { // The additional describe call is to return ResourceNotFoundException if the table doesn't exist. // This is to preserve backwards compatibility. describe(); throw new IllegalArgumentException("Table " + tableName + " did not transition into ACTIVE state.", exception); } }
@Override public AmazonDynamoDBWaiters waiters() { return getBackend().waiters(); }
@Test public void delete_whenTableAlreadyExists_deletesTable() { DeleteDynamoDBTable deleteDynamoDBTable = new DeleteDynamoDBTable(dynamoDB, "asdf", "asdf"); //setup when(dynamoDB.deleteTable("asdf")).thenReturn(new DeleteTableResult()); when(dynamoDB.waiters()).thenReturn(waiters); when(waiters.tableNotExists()).thenReturn(tableNotExists); doNothing().when(tableNotExists).run(any()); when(dynamoDB.describeTable("asdf")).thenThrow(new ResourceNotFoundException("")); //test deleteDynamoDBTable.delete(); //verify verify(dynamoDB).deleteTable("asdf"); verify(tableNotExists).run(any()); }
@Test public void delete_whenTableNotExistsWaiterThrows_deletesTableAndThrows() { DeleteDynamoDBTable deleteDynamoDBTable = new DeleteDynamoDBTable(dynamoDB, "asdf", "asdf"); //setup when(dynamoDB.deleteTable("asdf")).thenReturn(new DeleteTableResult()); when(dynamoDB.waiters()).thenReturn(waiters); when(waiters.tableNotExists()).thenReturn(tableNotExists); doThrow(new IllegalArgumentException()).when(tableNotExists).run(any()); when(dynamoDB.describeTable("asdf")).thenThrow(new ResourceNotFoundException("")); //test try { deleteDynamoDBTable.delete(); fail(); } catch(IllegalStateException e) { //verify exception assertTrue(e.getCause() instanceof IllegalArgumentException); } verify(dynamoDB).deleteTable("asdf"); verify(tableNotExists).run(any()); }
/** * A convenient blocking call that can be used, typically during table * deletion, to wait for the table to become deleted. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. */ public void waitForDelete() throws InterruptedException { Waiter waiter = client.waiters().tableNotExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); } catch (Exception exception) { throw new IllegalArgumentException("Table " + tableName + " is not deleted.", exception); } }
/** * A convenient blocking call that can be used, typically during table * creation, to wait for the table to become active. This method uses * {@link com.amazonaws.services.dynamodbv2.waiters.AmazonDynamoDBWaiters} * to poll the status of the table every 5 seconds. * * @return the table description when the table has become active * * @throws IllegalArgumentException if the table is being deleted * @throws ResourceNotFoundException if the table doesn't exist */ public TableDescription waitForActive() throws InterruptedException { Waiter waiter = client.waiters().tableExists(); try { waiter.run(new WaiterParameters<DescribeTableRequest>(new DescribeTableRequest(tableName)) .withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(25), new FixedDelayStrategy(5)))); return describe(); } catch (Exception exception) { // The additional describe call is to return ResourceNotFoundException if the table doesn't exist. // This is to preserve backwards compatibility. describe(); throw new IllegalArgumentException("Table " + tableName + " did not transition into ACTIVE state.", exception); } }