Search in sources :

Example 6 with BatchGetItemOutcome

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

the class GetDynamoDBTest method testStringHashStringRangeGetThrowsClientException.

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

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            throw new AmazonClientException("clientException");
        }
    };
    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("clientException", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) AmazonClientException(com.amazonaws.AmazonClientException) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) TableKeysAndAttributes(com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes) Test(org.junit.Test)

Example 7 with BatchGetItemOutcome

use of com.amazonaws.services.dynamodbv2.document.BatchGetItemOutcome 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 8 with BatchGetItemOutcome

use of com.amazonaws.services.dynamodbv2.document.BatchGetItemOutcome 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)

Aggregations

DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)8 TableKeysAndAttributes (com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes)8 TestRunner (org.apache.nifi.util.TestRunner)6 Test (org.junit.Test)6 BatchGetItemOutcome (com.amazonaws.services.dynamodbv2.document.BatchGetItemOutcome)5 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 KeysAndAttributes (com.amazonaws.services.dynamodbv2.model.KeysAndAttributes)4 ArrayList (java.util.ArrayList)4 AmazonClientException (com.amazonaws.AmazonClientException)2 AmazonServiceException (com.amazonaws.AmazonServiceException)2 Item (com.amazonaws.services.dynamodbv2.document.Item)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 Before (org.junit.Before)1