@Test public void testWaitForTableToBecomeActiveAlreadyActive() { final TableDescription table = new TableDescription(); final DescribeTableResult result = new DescribeTableResult().withTable(table); table.setTableStatus(TableStatus.ACTIVE); dynamoDB.describeTable(tableName); PowerMock.expectLastCall().andReturn(result); PowerMock.expectLastCall().andReturn(result); PowerMock.replayAll(); DynamoDBManager.waitForTableToBecomeActive(dynamoDB, tableName); }
public static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName) { int numTries = 0; TableStatus currentState; try { currentState = getTableStatus(dynamoDB, tableName); } catch (final ResourceNotFoundException e) { throw new IllegalStateException("Table " + tableName + " does not exist"); } while (numTries < RETRY_COUNT) { try { Thread.sleep(RETRY_DELAY); } catch (final InterruptedException e) { LOGGER.severe(e.getMessage()); } currentState = getTableStatus(dynamoDB, tableName); numTries++; LOGGER.info("Table " + tableName + " is in " + currentState + " state"); switch (currentState) { case ACTIVE: return; case DELETING: throw new IllegalStateException("Table " + tableName + " has DELETING status and will never become active"); case UPDATING: break; case CREATING: break; default: throw new IllegalStateException("Unknown table status: " + currentState); } } final DescribeTableResult result = dynamoDB.describeTable(tableName); throw new IllegalStateException("Table " + tableName + " never went ACTIVE" + result); }
DynamoDBManager { public static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName) { int numTries = 0; TableStatus currentState; try { currentState = getTableStatus(dynamoDB, tableName); } catch (final ResourceNotFoundException e) { throw new IllegalStateException("Table " + tableName + " does not exist"); } while (numTries < RETRY_COUNT) { try { Thread.sleep(RETRY_DELAY); } catch (final InterruptedException e) { LOGGER.severe(e.getMessage()); } currentState = getTableStatus(dynamoDB, tableName); numTries++; LOGGER.info("Table " + tableName + " is in " + currentState + " state"); switch (currentState) { case ACTIVE: return; case DELETING: throw new IllegalStateException("Table " + tableName + " has DELETING status and will never become active"); case UPDATING: break; case CREATING: break; default: throw new IllegalStateException("Unknown table status: " + currentState); } } final DescribeTableResult result = dynamoDB.describeTable(tableName); throw new IllegalStateException("Table " + tableName + " never went ACTIVE" + result); } }
DynamoDBManager { public static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName) { int numTries = 0; TableStatus currentState; try { currentState = getTableStatus(dynamoDB, tableName); } catch (final ResourceNotFoundException e) { throw new IllegalStateException("Table " + tableName + " does not exist"); } while (numTries < RETRY_COUNT) { try { Thread.sleep(RETRY_DELAY); } catch (final InterruptedException e) { LOGGER.severe(e.getMessage()); } currentState = getTableStatus(dynamoDB, tableName); numTries++; LOGGER.info("Table " + tableName + " is in " + currentState + " state"); switch (currentState) { case ACTIVE: return; case DELETING: throw new IllegalStateException("Table " + tableName + " has DELETING status and will never become active"); case UPDATING: break; case CREATING: break; default: throw new IllegalStateException("Unknown table status: " + currentState); } } final DescribeTableResult result = dynamoDB.describeTable(tableName); throw new IllegalStateException("Table " + tableName + " never went ACTIVE" + result); } private  DynamoDBManager(); }
DynamoDBManager { public static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName) { int numTries = 0; TableStatus currentState; try { currentState = getTableStatus(dynamoDB, tableName); } catch (final ResourceNotFoundException e) { throw new IllegalStateException("Table " + tableName + " does not exist"); } while (numTries < RETRY_COUNT) { try { Thread.sleep(RETRY_DELAY); } catch (final InterruptedException e) { LOGGER.severe(e.getMessage()); } currentState = getTableStatus(dynamoDB, tableName); numTries++; LOGGER.info("Table " + tableName + " is in " + currentState + " state"); switch (currentState) { case ACTIVE: return; case DELETING: throw new IllegalStateException("Table " + tableName + " has DELETING status and will never become active"); case UPDATING: break; case CREATING: break; default: throw new IllegalStateException("Unknown table status: " + currentState); } } final DescribeTableResult result = dynamoDB.describeTable(tableName); throw new IllegalStateException("Table " + tableName + " never went ACTIVE" + result); } private  DynamoDBManager(); static TableDescription createTable(final AmazonDynamoDB dynamoDB, final CreateTableRequest request); static boolean doesTableExist(final AmazonDynamoDB dynamoDB, final String tableName); static TableStatus getTableStatus(final AmazonDynamoDB dynamoDB, final String tableName); static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName); }
DynamoDBManager { public static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName) { int numTries = 0; TableStatus currentState; try { currentState = getTableStatus(dynamoDB, tableName); } catch (final ResourceNotFoundException e) { throw new IllegalStateException("Table " + tableName + " does not exist"); } while (numTries < RETRY_COUNT) { try { Thread.sleep(RETRY_DELAY); } catch (final InterruptedException e) { LOGGER.severe(e.getMessage()); } currentState = getTableStatus(dynamoDB, tableName); numTries++; LOGGER.info("Table " + tableName + " is in " + currentState + " state"); switch (currentState) { case ACTIVE: return; case DELETING: throw new IllegalStateException("Table " + tableName + " has DELETING status and will never become active"); case UPDATING: break; case CREATING: break; default: throw new IllegalStateException("Unknown table status: " + currentState); } } final DescribeTableResult result = dynamoDB.describeTable(tableName); throw new IllegalStateException("Table " + tableName + " never went ACTIVE" + result); } private  DynamoDBManager(); static TableDescription createTable(final AmazonDynamoDB dynamoDB, final CreateTableRequest request); static boolean doesTableExist(final AmazonDynamoDB dynamoDB, final String tableName); static TableStatus getTableStatus(final AmazonDynamoDB dynamoDB, final String tableName); static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName);  }