|
@@ -20,10 +20,6 @@ package org.apache.hadoop.fs.s3a.s3guard;
|
|
|
|
|
|
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
|
|
|
import com.amazonaws.services.dynamodbv2.document.Table;
|
|
|
-import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
|
|
|
-import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
|
|
|
-import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
|
|
|
-import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
|
|
|
import com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException;
|
|
|
import org.apache.hadoop.fs.s3a.S3AFileSystem;
|
|
|
import org.apache.hadoop.fs.s3a.s3guard.S3GuardTool.DestroyMetadata;
|
|
@@ -31,7 +27,6 @@ import org.apache.hadoop.fs.s3a.s3guard.S3GuardTool.InitMetadata;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Collection;
|
|
|
import java.util.Random;
|
|
|
|
|
|
import static org.apache.hadoop.fs.s3a.s3guard.S3GuardTool.SUCCESS;
|
|
@@ -66,91 +61,50 @@ public class ITestS3GuardToolDynamoDB extends S3GuardToolTestBase {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testInitDynamoDBMetadataStore() throws IOException {
|
|
|
- final String testS3Url = getTestPath("init");
|
|
|
- String testTableName = "initDynamoDBMetadataStore" +
|
|
|
- new Random().nextInt();
|
|
|
-
|
|
|
- InitMetadata cmd = new InitMetadata(getFs().getConf());
|
|
|
- Table table = null;
|
|
|
-
|
|
|
- try {
|
|
|
- String[] args = new String[]{
|
|
|
- "init", "-m", "dynamodb://" + testTableName, testS3Url
|
|
|
- };
|
|
|
- assertEquals("Init command did not exit successfully - see output",
|
|
|
- SUCCESS, cmd.run(args));
|
|
|
- // Verify the existence of the dynamodb table.
|
|
|
- try {
|
|
|
- MetadataStore ms = getMetadataStore();
|
|
|
- assertTrue("metadata store should be DynamoDBMetadataStore",
|
|
|
- ms instanceof DynamoDBMetadataStore);
|
|
|
- DynamoDBMetadataStore dynamoMs = (DynamoDBMetadataStore) ms;
|
|
|
- DynamoDB db = dynamoMs.getDynamoDB();
|
|
|
- table = db.getTable(testTableName);
|
|
|
- table.describe();
|
|
|
- } catch (ResourceNotFoundException e) {
|
|
|
- fail(String.format("DynamoDB table %s does not exist",
|
|
|
- testTableName));
|
|
|
- }
|
|
|
- } finally {
|
|
|
- // Clean the table.
|
|
|
- try {
|
|
|
- if (table != null) {
|
|
|
- table.delete();
|
|
|
- }
|
|
|
- } catch (ResourceNotFoundException e) {
|
|
|
- // Ignore
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testDestroyDynamoDBMetadataStore()
|
|
|
- throws IOException, InterruptedException {
|
|
|
- final String testS3Url = getTestPath("destroy");
|
|
|
- String testTableName = "destroyDynamoDBMetadataStore" +
|
|
|
- new Random().nextInt();
|
|
|
-
|
|
|
+ public void testDynamoDBInitDestroyCycle() throws IOException,
|
|
|
+ InterruptedException {
|
|
|
+ String testTableName = "testDynamoDBInitDestroy" + new Random().nextInt();
|
|
|
+ String testS3Url = getTestPath(testTableName);
|
|
|
S3AFileSystem fs = getFs();
|
|
|
- DestroyMetadata cmd = new DestroyMetadata(fs.getConf());
|
|
|
-
|
|
|
- // Pre-alloc DynamoDB table.
|
|
|
- DynamoDB db = DynamoDBMetadataStore.createDynamoDB(fs);
|
|
|
- try {
|
|
|
- Table table = db.getTable(testTableName);
|
|
|
- table.delete();
|
|
|
- table.waitForDelete();
|
|
|
- } catch (ResourceNotFoundException e) {
|
|
|
- // Ignore.
|
|
|
- }
|
|
|
- Collection<KeySchemaElement> elements =
|
|
|
- PathMetadataDynamoDBTranslation.keySchema();
|
|
|
- Collection<AttributeDefinition> attrs =
|
|
|
- PathMetadataDynamoDBTranslation.attributeDefinitions();
|
|
|
- ProvisionedThroughput pt = new ProvisionedThroughput(100L, 200L);
|
|
|
- Table table = db.createTable(new CreateTableRequest()
|
|
|
- .withAttributeDefinitions(attrs)
|
|
|
- .withKeySchema(elements)
|
|
|
- .withTableName(testTableName)
|
|
|
- .withProvisionedThroughput(pt));
|
|
|
+ DynamoDB db = null;
|
|
|
try {
|
|
|
- table.waitForActive();
|
|
|
- assertTrue("Table does not exist", exist(db, testTableName));
|
|
|
+ // Initialize MetadataStore
|
|
|
+ InitMetadata initCmd = new InitMetadata(fs.getConf());
|
|
|
+ assertEquals("Init command did not exit successfully - see output",
|
|
|
+ SUCCESS, initCmd.run(new String[]{
|
|
|
+ "init", "-m", "dynamodb://" + testTableName, testS3Url
|
|
|
+ }));
|
|
|
+ // Verify it exists
|
|
|
+ MetadataStore ms = getMetadataStore();
|
|
|
+ assertTrue("metadata store should be DynamoDBMetadataStore",
|
|
|
+ ms instanceof DynamoDBMetadataStore);
|
|
|
+ DynamoDBMetadataStore dynamoMs = (DynamoDBMetadataStore) ms;
|
|
|
+ db = dynamoMs.getDynamoDB();
|
|
|
+ assertTrue(String.format("%s does not exist", testTableName),
|
|
|
+ exist(db, testTableName));
|
|
|
|
|
|
- String[] args = new String[]{
|
|
|
- "destroy", "-m", "dynamodb://" + testTableName, testS3Url
|
|
|
- };
|
|
|
+ // Destroy MetadataStore
|
|
|
+ DestroyMetadata destroyCmd = new DestroyMetadata(fs.getConf());
|
|
|
assertEquals("Destroy command did not exit successfully - see output",
|
|
|
- SUCCESS, cmd.run(args));
|
|
|
+ SUCCESS, destroyCmd.run(new String[]{
|
|
|
+ "destroy", "-m", "dynamodb://" + testTableName, testS3Url
|
|
|
+ }));
|
|
|
+ // Verify it does not exist
|
|
|
assertFalse(String.format("%s still exists", testTableName),
|
|
|
exist(db, testTableName));
|
|
|
+ } catch (ResourceNotFoundException e) {
|
|
|
+ fail(String.format("DynamoDB table %s does not exist", testTableName));
|
|
|
} finally {
|
|
|
- if (table != null) {
|
|
|
- try {
|
|
|
- table.delete();
|
|
|
- table.waitForDelete();
|
|
|
- } catch (ResourceNotFoundException e) {}
|
|
|
+ System.out.println("Warning! Table may have not been cleaned up: " +
|
|
|
+ testTableName);
|
|
|
+ if (db != null) {
|
|
|
+ Table table = db.getTable(testTableName);
|
|
|
+ if (table != null) {
|
|
|
+ try {
|
|
|
+ table.delete();
|
|
|
+ table.waitForDelete();
|
|
|
+ } catch (ResourceNotFoundException e) { /* Ignore */ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|