com.amazonaws.services.dynamodbv2.model.KeysAndAttributes Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.KeysAndAttributes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems,
        String returnConsumedCapacity) throws AmazonServiceException,
        AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #2
Source File: GetDynamoDBTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringHashStringNoRangeGetUnprocessed() {
    unprocessed.clear();
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    kaa.withKeys(map);
    unprocessed.put(stringHashStringRangeTableName, kaa);

    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.HASH_KEY_NAME, "hashS");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
    getRunner.enqueue(new byte[] {});

    getRunner.run(1);

    getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_UNPROCESSED, 1);

    List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_UNPROCESSED);
    for (MockFlowFile flowFile : flowFiles) {
        assertNotNull(flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_UNPROCESSED));
    }
}
 
Example #3
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems)
        throws AmazonServiceException, AmazonClientException {
    BatchGetItemRequest request = new BatchGetItemRequest()
            .withRequestItems(requestItems);
    return batchGetItem(request);
}
 
Example #4
Source File: AmazonDynamoDBStubTest.java    From aws-java-sdk-stubs with Apache License 2.0 5 votes vote down vote up
@Test
public void test_batchGetItem_WithAllParameters() throws Exception {
  String TEST_ATTRIBUTE_2 = "Attribute2";
  String TEST_ATTRIBUTE_VALUE_2 = "AttributeValue2";

  createTable();
  putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);
  putItem(TEST_ATTRIBUTE_2, TEST_ATTRIBUTE_VALUE_2);

  List<Map<String, AttributeValue>> keys = new ArrayList<Map<String, AttributeValue>>();
  Map<String, AttributeValue> key1 = new HashMap<String, AttributeValue>();
  key1.put(TEST_ATTRIBUTE, new AttributeValue()
    .withS(TEST_ATTRIBUTE_VALUE));
  keys.add(key1);
  Map<String, AttributeValue> key2 = new HashMap<String, AttributeValue>();
  key2.put(TEST_ATTRIBUTE_2, new AttributeValue()
    .withS(TEST_ATTRIBUTE_VALUE_2));
  keys.add(key2);

  Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
  requestItems.put(TEST_TABLE_NAME, new KeysAndAttributes()
    .withKeys(keys));
  String returnConsumedCapacity = "";

  BatchGetItemResult result = dynamoDb.batchGetItem(requestItems,returnConsumedCapacity);
  String tableName = result.getResponses().keySet().toArray(new String[1])[0];
  List<Map<String, AttributeValue>> items = result.getResponses().get(tableName);
  AttributeValue value1 = items.get(0).get(TEST_ATTRIBUTE);
  AttributeValue value2 = items.get(1).get(TEST_ATTRIBUTE_2);

  assertThat(tableName, equalTo(TEST_TABLE_NAME));
  assertThat(items.size(), equalTo(keys.size()));
  assertThat(value1.getS(), equalTo(TEST_ATTRIBUTE_VALUE));
  assertThat(value2.getS(), equalTo(TEST_ATTRIBUTE_VALUE_2));
}
 
Example #5
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public Iterator<GeoWaveRow> getRowsFromDataIndex(
    final byte[][] dataIds,
    final short adapterId,
    final String typeName) {
  final Map<ByteArray, GeoWaveRow> resultMap = new HashMap<>();
  final Iterator<byte[]> dataIdIterator = Arrays.stream(dataIds).iterator();
  while (dataIdIterator.hasNext()) {
    // fill result map
    final Collection<Map<String, AttributeValue>> dataIdsForRequest = new ArrayList<>();
    int i = 0;
    while (dataIdIterator.hasNext() && (i < MAX_ROWS_FOR_BATCHGETITEM)) {
      dataIdsForRequest.add(
          Collections.singletonMap(
              DynamoDBRow.GW_PARTITION_ID_KEY,
              new AttributeValue().withB(ByteBuffer.wrap(dataIdIterator.next()))));
      i++;
    }
    BatchGetItemResult result =
        getResults(
            Collections.singletonMap(
                typeName + "_" + getQualifiedTableName(DataIndexUtils.DATA_ID_INDEX.getName()),
                new KeysAndAttributes().withKeys(dataIdsForRequest)),
            adapterId,
            resultMap);
    while (!result.getUnprocessedKeys().isEmpty()) {
      result = getResults(result.getUnprocessedKeys(), adapterId, resultMap);
    }
  }
  return Arrays.stream(dataIds).map(d -> resultMap.get(new ByteArray(d))).filter(
      r -> r != null).iterator();
}
 
Example #6
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
private BatchGetItemResult getResults(
    final Map<String, KeysAndAttributes> requestItems,
    final short adapterId,
    final Map<ByteArray, GeoWaveRow> resultMap) {
  final BatchGetItemRequest request = new BatchGetItemRequest(requestItems);

  final BatchGetItemResult result = client.batchGetItem(request);
  result.getResponses().values().forEach(results -> results.stream().forEach(objMap -> {
    final byte[] dataId = objMap.get(DynamoDBRow.GW_PARTITION_ID_KEY).getB().array();
    final AttributeValue valueAttr = objMap.get(DynamoDBRow.GW_VALUE_KEY);
    final byte[] value = valueAttr == null ? null : valueAttr.getB().array();
    final AttributeValue visAttr = objMap.get(DynamoDBRow.GW_VISIBILITY_KEY);
    final byte[] vis = visAttr == null ? new byte[0] : visAttr.getB().array();
    resultMap.put(
        new ByteArray(dataId),
        DataIndexUtils.deserializeDataIndexRow(dataId, adapterId, value, vis));
  }));
  return result;
}
 
Example #7
Source File: GetDynamoDBTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    outcome = new BatchGetItemOutcome(result);
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    map.put("rangeS", new AttributeValue("r1"));
    kaa.withKeys(map);
    unprocessed = new HashMap<>();
    unprocessed.put(stringHashStringRangeTableName, kaa);

    result.withUnprocessedKeys(unprocessed);

    Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
    List<Map<String,AttributeValue>> items = new ArrayList<>();
    responses.put("StringHashStringRangeTable", items);
    result.withResponses(responses);

    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            return outcome;
        }

    };

    getDynamoDB = new GetDynamoDB() {
        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };

}
 
Example #8
Source File: GetDynamoDBTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    outcome = new BatchGetItemOutcome(result);
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    map.put("rangeS", new AttributeValue("r1"));
    kaa.withKeys(map);
    unprocessed = new HashMap<>();
    unprocessed.put(stringHashStringRangeTableName, kaa);

    result.withUnprocessedKeys(unprocessed);

    Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
    List<Map<String,AttributeValue>> items = new ArrayList<>();
    responses.put("StringHashStringRangeTable", items);
    result.withResponses(responses);

    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            return outcome;
        }

    };

    getDynamoDB = new GetDynamoDB() {
        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };

}
 
Example #9
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems,
        String returnConsumedCapacity) throws AmazonServiceException,
        AmazonClientException {
    BatchGetItemRequest request = new BatchGetItemRequest()
            .withRequestItems(requestItems)
            .withReturnConsumedCapacity(returnConsumedCapacity);
    return batchGetItem(request);
}
 
Example #10
Source File: GetDynamoDBTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringHashStringNoRangeGetUnprocessed() {
    unprocessed.clear();
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    kaa.withKeys(map);
    unprocessed.put(stringHashStringRangeTableName, kaa);

    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.HASH_KEY_NAME, "hashS");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
    getRunner.enqueue(new byte[] {});

    getRunner.run(1);

    getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_UNPROCESSED, 1);

    List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_UNPROCESSED);
    for (MockFlowFile flowFile : flowFiles) {
        assertNotNull(flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_UNPROCESSED));
    }
}
 
Example #11
Source File: TransactionManagerDBFacadeIntegrationTest.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
private BatchGetItemRequest createBatchGetItemRequest(final boolean filterAttributes) {
    KeysAndAttributes keysAndAttributes = new KeysAndAttributes()
            .withKeys(key0);
    if (filterAttributes) {
        keysAndAttributes.withAttributesToGet(attributesToGet);
    }
    return new BatchGetItemRequest()
            .withRequestItems(
                    Collections.singletonMap(
                            INTEG_HASH_TABLE_NAME,
                            keysAndAttributes));
}
 
Example #12
Source File: GetDynamoDBTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testStringHashStringRangeGetJsonObjectNull() {
    outcome = new BatchGetItemOutcome(result);
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    map.put("rangeS", new AttributeValue("r1"));
    kaa.withKeys(map);
    unprocessed = new HashMap<>();
    result.withUnprocessedKeys(unprocessed);

    Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
    List<Map<String,AttributeValue>> items = new ArrayList<>();
    Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
    item.put("j1",null);
    item.put("hashS", new AttributeValue("h1"));
    item.put("rangeS", new AttributeValue("r1"));
    items.add(item);
    responses.put("StringHashStringRangeTable", items);
    result.withResponses(responses);

    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            return outcome;
        }

    };

    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_SUCCESS, 1);

    List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
    for (MockFlowFile flowFile : flowFiles) {
        assertNull(flowFile.getContentClaim());
    }

}
 
Example #13
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems)
        throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #14
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems) throws AmazonServiceException, AmazonClientException {
    return getBackend().batchGetItem(requestItems);
}
 
Example #15
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems, String returnConsumedCapacity) throws AmazonServiceException, AmazonClientException {
    return getBackend().batchGetItem(requestItems, returnConsumedCapacity);
}
 
Example #16
Source File: DocumentAPIBatchGet.java    From aws-dynamodb-examples with Apache License 2.0 4 votes vote down vote up
private static void retrieveMultipleItemsBatchGet() {        
    
    try {
        
        TableKeysAndAttributes forumTableKeysAndAttributes = new TableKeysAndAttributes(forumTableName);
        forumTableKeysAndAttributes.addHashOnlyPrimaryKeys("Name", "Amazon S3", "Amazon DynamoDB");
        
        TableKeysAndAttributes threadTableKeysAndAttributes = new TableKeysAndAttributes(threadTableName);
        threadTableKeysAndAttributes.addHashAndRangePrimaryKeys("ForumName", "Subject", 
            "Amazon DynamoDB","DynamoDB Thread 1",
            "Amazon DynamoDB","DynamoDB Thread 2",
            "Amazon S3","S3 Thread 1");
        
         Map<String, TableKeysAndAttributes> requestItems = new HashMap<String, TableKeysAndAttributes>();
         requestItems.put(forumTableName, forumTableKeysAndAttributes);
         requestItems.put(threadTableName, threadTableKeysAndAttributes);
         
         System.out.println("Making the request.");

         BatchGetItemOutcome outcome = dynamoDB.batchGetItem(forumTableKeysAndAttributes,
                        threadTableKeysAndAttributes);

        do {

            for (String tableName : outcome.getTableItems().keySet()) {
                System.out.println("Items in table " + tableName);
                List<Item> items = outcome.getTableItems().get(tableName);
                for (Item item : items) {
                    System.out.println(item.toJSONPretty());
                }
            }
            
            // Check for unprocessed keys which could happen if you exceed provisioned
            // throughput or reach the limit on response size.
            
            Map<String, KeysAndAttributes> unprocessedKeys = outcome.getUnprocessedKeys();
        
            if (outcome.getUnprocessedKeys().size() == 0) {
                System.out.println("No unprocessed keys found");
            } else {
                System.out.println("Retrieving the unprocessed keys");
                outcome = dynamoDB.batchGetItemUnprocessed(unprocessedKeys);
            }
            
        } while (outcome.getUnprocessedKeys().size() > 0);
 
 
    }  catch (Exception e) {
        System.err.println("Failed to retrieve items.");
        System.err.println(e.getMessage());
    }  

}
 
Example #17
Source File: GetDynamoDBTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testStringHashStringRangeGetJsonObjectValid() throws IOException {
    outcome = new BatchGetItemOutcome(result);
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    map.put("rangeS", new AttributeValue("r1"));
    kaa.withKeys(map);
    unprocessed = new HashMap<>();
    result.withUnprocessedKeys(unprocessed);

    Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
    List<Map<String,AttributeValue>> items = new ArrayList<>();
    Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
    String jsonDocument = "{\"name\": \"john\"}";
    item.put("j1",new AttributeValue(jsonDocument));
    item.put("hashS", new AttributeValue("h1"));
    item.put("rangeS", new AttributeValue("r1"));
    items.add(item);
    responses.put("StringHashStringRangeTable", items);
    result.withResponses(responses);

    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            return outcome;
        }

    };

    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_SUCCESS, 1);
}
 
Example #18
Source File: DocumentAPIBatchGet.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
private static void retrieveMultipleItemsBatchGet() {

        try {

            TableKeysAndAttributes forumTableKeysAndAttributes = new TableKeysAndAttributes(forumTableName);
            // Add a partition key
            forumTableKeysAndAttributes.addHashOnlyPrimaryKeys("Name", "Amazon S3", "Amazon DynamoDB");

            TableKeysAndAttributes threadTableKeysAndAttributes = new TableKeysAndAttributes(threadTableName);
            // Add a partition key and a sort key
            threadTableKeysAndAttributes.addHashAndRangePrimaryKeys("ForumName", "Subject", "Amazon DynamoDB",
                "DynamoDB Thread 1", "Amazon DynamoDB", "DynamoDB Thread 2", "Amazon S3", "S3 Thread 1");

            System.out.println("Making the request.");

            BatchGetItemOutcome outcome = dynamoDB.batchGetItem(forumTableKeysAndAttributes,
                threadTableKeysAndAttributes);

            Map<String, KeysAndAttributes> unprocessed = null;

            do {
                for (String tableName : outcome.getTableItems().keySet()) {
                    System.out.println("Items in table " + tableName);
                    List<Item> items = outcome.getTableItems().get(tableName);
                    for (Item item : items) {
                        System.out.println(item.toJSONPretty());
                    }
                }

                // Check for unprocessed keys which could happen if you exceed
                // provisioned
                // throughput or reach the limit on response size.
                unprocessed = outcome.getUnprocessedKeys();

                if (unprocessed.isEmpty()) {
                    System.out.println("No unprocessed keys found");
                }
                else {
                    System.out.println("Retrieving the unprocessed keys");
                    outcome = dynamoDB.batchGetItemUnprocessed(unprocessed);
                }

            } while (!unprocessed.isEmpty());

        }
        catch (Exception e) {
            System.err.println("Failed to retrieve items.");
            System.err.println(e.getMessage());
        }

    }
 
Example #19
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems) {
	throw new UnsupportedOperationException();
}
 
Example #20
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems, String returnConsumedCapacity) {
	throw new UnsupportedOperationException();
}
 
Example #21
Source File: GetDynamoDBTest.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testStringHashStringRangeGetJsonObjectValid() throws IOException {
    outcome = new BatchGetItemOutcome(result);
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    map.put("rangeS", new AttributeValue("r1"));
    kaa.withKeys(map);
    unprocessed = new HashMap<>();
    result.withUnprocessedKeys(unprocessed);

    Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
    List<Map<String,AttributeValue>> items = new ArrayList<>();
    Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
    String jsonDocument = "{\"name\": \"john\"}";
    item.put("j1",new AttributeValue(jsonDocument));
    item.put("hashS", new AttributeValue("h1"));
    item.put("rangeS", new AttributeValue("r1"));
    items.add(item);
    responses.put("StringHashStringRangeTable", items);
    result.withResponses(responses);

    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            return outcome;
        }

    };

    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_SUCCESS, 1);
}
 
Example #22
Source File: GetDynamoDBTest.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testStringHashStringRangeGetJsonObjectNull() {
    outcome = new BatchGetItemOutcome(result);
    KeysAndAttributes kaa = new KeysAndAttributes();
    Map<String,AttributeValue> map = new HashMap<>();
    map.put("hashS", new AttributeValue("h1"));
    map.put("rangeS", new AttributeValue("r1"));
    kaa.withKeys(map);
    unprocessed = new HashMap<>();
    result.withUnprocessedKeys(unprocessed);

    Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
    List<Map<String,AttributeValue>> items = new ArrayList<>();
    Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
    item.put("j1",null);
    item.put("hashS", new AttributeValue("h1"));
    item.put("rangeS", new AttributeValue("r1"));
    items.add(item);
    responses.put("StringHashStringRangeTable", items);
    result.withResponses(responses);

    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {

        @Override
        public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
            return outcome;
        }

    };

    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_SUCCESS, 1);

    List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
    for (MockFlowFile flowFile : flowFiles) {
        assertNull(flowFile.getContentClaim());
    }

}