Search in sources :

Example 36 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project nifi by apache.

the class GetDynamoDBTest method testStringHashStringRangeGetThrowsServiceException.

@Test
public void testStringHashStringRangeGetThrowsServiceException() {
    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            throw new AmazonServiceException("serviceException");
        }
    };
    final GetDynamoDB getDynamoDB = new GetDynamoDB() {

        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };
    final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
    getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY, "abcd");
    getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
    getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
    getRunner.enqueue(new byte[] {});
    getRunner.run(1);
    getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);
    List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
        assertEquals("serviceException (Service: null; Status Code: 0; Error Code: null; Request ID: null)", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) AmazonServiceException(com.amazonaws.AmazonServiceException) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) TableKeysAndAttributes(com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes) Test(org.junit.Test)

Example 37 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project nifi by apache.

the class GetDynamoDBTest method testStringHashStringRangeGetThrowsRuntimeException.

@Test
public void testStringHashStringRangeGetThrowsRuntimeException() {
    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            throw new RuntimeException("runtimeException");
        }
    };
    final GetDynamoDB getDynamoDB = new GetDynamoDB() {

        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };
    final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
    getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY, "abcd");
    getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
    getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
    getRunner.enqueue(new byte[] {});
    getRunner.run(1);
    getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);
    List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
        assertEquals("runtimeException", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) TableKeysAndAttributes(com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes) Test(org.junit.Test)

Example 38 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project nifi by apache.

the class ITAbstractDynamoDBTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    FileInputStream fis = new FileInputStream(CREDENTIALS_FILE);
    final PropertiesCredentials credentials = new PropertiesCredentials(fis);
    amazonDynamoDBClient = new AmazonDynamoDBClient(credentials);
    dynamoDB = new DynamoDB(amazonDynamoDBClient);
    amazonDynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2));
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("hashS").withAttributeType("S"));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("rangeS").withAttributeType("S"));
    ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashS").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeS").withKeyType(KeyType.RANGE));
    CreateTableRequest request = new CreateTableRequest().withTableName(stringHashStringRangeTableName).withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(6L));
    Table stringHashStringRangeTable = dynamoDB.createTable(request);
    stringHashStringRangeTable.waitForActive();
    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("rangeN").withAttributeType("N"));
    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName("rangeN").withKeyType(KeyType.RANGE));
    request = new CreateTableRequest().withTableName(numberHashNumberRangeTableName).withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(6L));
    Table numberHashNumberRangeTable = dynamoDB.createTable(request);
    numberHashNumberRangeTable.waitForActive();
    attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("hashN").withAttributeType("N"));
    keySchema = new ArrayList<KeySchemaElement>();
    keySchema.add(new KeySchemaElement().withAttributeName("hashN").withKeyType(KeyType.HASH));
    request = new CreateTableRequest().withTableName(numberHashOnlyTableName).withKeySchema(keySchema).withAttributeDefinitions(attributeDefinitions).withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(6L));
    Table numberHashOnlyTable = dynamoDB.createTable(request);
    numberHashOnlyTable.waitForActive();
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) ArrayList(java.util.ArrayList) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) FileInputStream(java.io.FileInputStream) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) BeforeClass(org.junit.BeforeClass)

Example 39 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project nifi by apache.

the class PutDynamoDBTest method testStringHashStringRangePutThrowsClientException.

@Test
public void testStringHashStringRangePutThrowsClientException() {
    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchWriteItemOutcome batchWriteItem(TableWriteItems... tableWriteItems) {
            throw new AmazonClientException("clientException");
        }
    };
    putDynamoDB = new PutDynamoDB() {

        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };
    final TestRunner putRunner = TestRunners.newTestRunner(putDynamoDB);
    putRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY, "abcd");
    putRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
    putRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    putRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document");
    String document = "{\"name\":\"john\"}";
    putRunner.enqueue(document.getBytes());
    putRunner.run(1);
    putRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);
    List<MockFlowFile> flowFiles = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
        assertEquals("clientException", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TableWriteItems(com.amazonaws.services.dynamodbv2.document.TableWriteItems) TestRunner(org.apache.nifi.util.TestRunner) AmazonClientException(com.amazonaws.AmazonClientException) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) Test(org.junit.Test)

Example 40 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project nifi by apache.

the class PutDynamoDBTest method testStringHashStringRangePutThrowsServiceException.

@Test
public void testStringHashStringRangePutThrowsServiceException() {
    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchWriteItemOutcome batchWriteItem(TableWriteItems... tableWriteItems) {
            throw new AmazonServiceException("serviceException");
        }
    };
    putDynamoDB = new PutDynamoDB() {

        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };
    final TestRunner putRunner = TestRunners.newTestRunner(putDynamoDB);
    putRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY, "abcd");
    putRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
    putRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    putRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document");
    String document = "{\"name\":\"john\"}";
    putRunner.enqueue(document.getBytes());
    putRunner.run(1);
    putRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);
    List<MockFlowFile> flowFiles = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
        assertEquals("serviceException (Service: null; Status Code: 0; Error Code: null; Request ID: null)", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TableWriteItems(com.amazonaws.services.dynamodbv2.document.TableWriteItems) TestRunner(org.apache.nifi.util.TestRunner) AmazonServiceException(com.amazonaws.AmazonServiceException) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) Test(org.junit.Test)

Aggregations

DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)24 Test (org.junit.Test)16 TestRunner (org.apache.nifi.util.TestRunner)15 MockFlowFile (org.apache.nifi.util.MockFlowFile)14 AmazonClientException (com.amazonaws.AmazonClientException)12 AmazonServiceException (com.amazonaws.AmazonServiceException)10 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)10 TableWriteItems (com.amazonaws.services.dynamodbv2.document.TableWriteItems)10 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 List (java.util.List)9 TableKeysAndAttributes (com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes)8 Map (java.util.Map)8 IOException (java.io.IOException)6 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)5 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)5 BatchGetItemOutcome (com.amazonaws.services.dynamodbv2.document.BatchGetItemOutcome)5 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)5 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)5