Search in sources :

Example 1 with ConsumedCapacity

use of com.amazonaws.services.dynamodbv2.model.ConsumedCapacity in project camel by apache.

the class AmazonDDBClientMock method query.

@SuppressWarnings("unchecked")
@Override
public QueryResult query(QueryRequest queryRequest) {
    this.queryRequest = queryRequest;
    ConsumedCapacity consumed = new ConsumedCapacity();
    consumed.setCapacityUnits(1.0);
    Map<String, AttributeValue> lastEvaluatedKey = new HashMap<String, AttributeValue>();
    lastEvaluatedKey.put("1", new AttributeValue("LAST_KEY"));
    return new QueryResult().withConsumedCapacity(consumed).withCount(1).withItems(getAttributes()).withLastEvaluatedKey(lastEvaluatedKey);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) QueryResult(com.amazonaws.services.dynamodbv2.model.QueryResult) HashMap(java.util.HashMap) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)

Example 2 with ConsumedCapacity

use of com.amazonaws.services.dynamodbv2.model.ConsumedCapacity in project camel by apache.

the class AmazonDDBClientMock method scan.

@SuppressWarnings("unchecked")
@Override
public ScanResult scan(ScanRequest scanRequest) {
    this.scanRequest = scanRequest;
    ConsumedCapacity consumed = new ConsumedCapacity();
    consumed.setCapacityUnits(1.0);
    Map<String, AttributeValue> lastEvaluatedKey = new HashMap<String, AttributeValue>();
    lastEvaluatedKey.put("1", new AttributeValue("LAST_KEY"));
    return new ScanResult().withConsumedCapacity(consumed).withCount(1).withItems(getAttributes()).withScannedCount(10).withLastEvaluatedKey(lastEvaluatedKey);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) HashMap(java.util.HashMap) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)

Example 3 with ConsumedCapacity

use of com.amazonaws.services.dynamodbv2.model.ConsumedCapacity in project camel by apache.

the class QueryCommandTest method execute.

@Test
public void execute() {
    Map<String, AttributeValue> startKey = new HashMap<String, AttributeValue>();
    startKey.put("1", new AttributeValue("startKey"));
    List<String> attributeNames = Arrays.asList("attrNameOne", "attrNameTwo");
    exchange.getIn().setHeader(DdbConstants.ATTRIBUTE_NAMES, attributeNames);
    exchange.getIn().setHeader(DdbConstants.CONSISTENT_READ, true);
    exchange.getIn().setHeader(DdbConstants.START_KEY, startKey);
    exchange.getIn().setHeader(DdbConstants.LIMIT, 10);
    exchange.getIn().setHeader(DdbConstants.SCAN_INDEX_FORWARD, true);
    Map<String, Condition> keyConditions = new HashMap<String, Condition>();
    Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withN("1985"));
    keyConditions.put("1", condition);
    exchange.getIn().setHeader(DdbConstants.KEY_CONDITIONS, keyConditions);
    command.execute();
    Map<String, AttributeValue> mapAssert = new HashMap<String, AttributeValue>();
    mapAssert.put("1", new AttributeValue("LAST_KEY"));
    ConsumedCapacity consumed = (ConsumedCapacity) exchange.getIn().getHeader(DdbConstants.CONSUMED_CAPACITY);
    assertEquals(Integer.valueOf(1), exchange.getIn().getHeader(DdbConstants.COUNT, Integer.class));
    assertEquals(Double.valueOf(1.0), consumed.getCapacityUnits());
    assertEquals(mapAssert, exchange.getIn().getHeader(DdbConstants.LAST_EVALUATED_KEY, Map.class));
    assertEquals(keyConditions, exchange.getIn().getHeader(DdbConstants.KEY_CONDITIONS, Map.class));
    Map<?, ?> items = (Map<?, ?>) exchange.getIn().getHeader(DdbConstants.ITEMS, List.class).get(0);
    assertEquals(new AttributeValue("attrValue"), items.get("attrName"));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity) Test(org.junit.Test)

Example 4 with ConsumedCapacity

use of com.amazonaws.services.dynamodbv2.model.ConsumedCapacity in project camel by apache.

the class ScanCommandTest method execute.

@Test
public void execute() {
    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withN("1985"));
    scanFilter.put("year", condition);
    exchange.getIn().setHeader(DdbConstants.SCAN_FILTER, scanFilter);
    command.execute();
    Map<String, AttributeValue> mapAssert = new HashMap<String, AttributeValue>();
    mapAssert.put("1", new AttributeValue("LAST_KEY"));
    ConsumedCapacity consumed = (ConsumedCapacity) exchange.getIn().getHeader(DdbConstants.CONSUMED_CAPACITY);
    assertEquals(scanFilter, ddbClient.scanRequest.getScanFilter());
    assertEquals(Integer.valueOf(10), exchange.getIn().getHeader(DdbConstants.SCANNED_COUNT, Integer.class));
    assertEquals(Integer.valueOf(1), exchange.getIn().getHeader(DdbConstants.COUNT, Integer.class));
    assertEquals(Double.valueOf(1.0), consumed.getCapacityUnits());
    assertEquals(mapAssert, exchange.getIn().getHeader(DdbConstants.LAST_EVALUATED_KEY, Map.class));
    Map<?, ?> items = (Map<?, ?>) exchange.getIn().getHeader(DdbConstants.ITEMS, List.class).get(0);
    assertEquals(new AttributeValue("attrValue"), items.get("attrName"));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity) Test(org.junit.Test)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)4 HashMap (java.util.HashMap)4 Condition (com.amazonaws.services.dynamodbv2.model.Condition)2 Map (java.util.Map)2 Test (org.junit.Test)2 QueryResult (com.amazonaws.services.dynamodbv2.model.QueryResult)1 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)1