mboudreau / Alternator

A mock DynamoDB that runs locally for testing purposes - DEPRECATED, PLEASE USE DYNAMODB LOCAL: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
Apache License 2.0
78 stars 39 forks source link

Difference with AWS when requesting TableDescription after table deletion #26

Closed statelessness closed 12 years ago

statelessness commented 12 years ago

After table deletion you should wait some time in order DynamoDB propagates changes. Amazon provides some examples on how to implement this wait. Basically you keep in a loop asking for table description periodically:

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10L * 60L * 1000L);
    while (System.currentTimeMillis() < endTime) {
        try {Thread.sleep(1000 * 20);} catch (Exception e) {}
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = client.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            logger.debug("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString())) {
                return;
            }
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true) {
                logger.debug("Table " + tableName + " is not found. It was deleted.");
                return;
            }
            else {
                throw ase;
            }
        }
    }

When table is deleted, you should get a ResourceNotFoundException, but Alternator does not generate this exception and tableDescription gets null value.

KR,

mboudreau commented 12 years ago

The point of Alternator is not to behave exactly like DynamoDB, it's meant for quick testing. There shouldn't be any waiting involved.

I'll have to look at the table description after the table has been deleted, you're right, it's suppose to throw a ResourceNotFoundException.