Search in sources :

Example 11 with BatchWriteItemOutcome

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

the class PutDynamoDBTest method testStringHashStringRangePutThrowsRuntimeException.

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

        @Override
        public BatchWriteItemOutcome batchWriteItem(TableWriteItems... tableWriteItems) {
            throw new RuntimeException("runtimeException");
        }
    };
    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("runtimeException", 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) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) Test(org.junit.Test)

Aggregations

DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)10 TableWriteItems (com.amazonaws.services.dynamodbv2.document.TableWriteItems)10 MockFlowFile (org.apache.nifi.util.MockFlowFile)6 TestRunner (org.apache.nifi.util.TestRunner)6 Test (org.junit.Test)6 AmazonClientException (com.amazonaws.AmazonClientException)4 AmazonServiceException (com.amazonaws.AmazonServiceException)4 BatchWriteItemOutcome (com.amazonaws.services.dynamodbv2.document.BatchWriteItemOutcome)4 List (java.util.List)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FlowFile (org.apache.nifi.flowfile.FlowFile)2 Before (org.junit.Before)2 Item (com.amazonaws.services.dynamodbv2.document.Item)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 BatchWriteItemResult (com.amazonaws.services.dynamodbv2.model.BatchWriteItemResult)1 WriteRequest (com.amazonaws.services.dynamodbv2.model.WriteRequest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1