private ScanResult getHashKeyItems(String[] hashKeys, String type) { List<Map<String, AttributeValue>> items = new ArrayList<>(); for (String key : hashKeys) { Map<String, AttributeValue> item = new HashMap<>(); if (type.equals("S")) { item.put("hashKey", new AttributeValue(key)); } else { item.put("hashKey", new AttributeValue().withN(key)); } items.add(item); } return new ScanResult().withScannedCount(items.size()).withItems(items).withConsumedCapacity (new ConsumedCapacity().withCapacityUnits(1d)); }
private ScanResult getHashNumberRangeKeyItems(String[] hashKeys, String hashType) { List<Map<String, AttributeValue>> items = new ArrayList<>(); for (String key : hashKeys) { for (Integer i = 0; i < NUM_RANGE_KEYS_PER_HASH_KEY; i++) { Map<String, AttributeValue> item = new HashMap<>(); if (hashType.equals("S")) { item.put("hashKey", new AttributeValue(key)); } else { item.put("hashKey", new AttributeValue().withN(key)); } item.put("rangeKey", new AttributeValue().withN("0" + i.toString())); items.add(item); } } return new ScanResult().withScannedCount(items.size()).withItems(items).withConsumedCapacity (new ConsumedCapacity().withCapacityUnits(1d)); }
@Test public void fetchPageReturnsZeroConsumedCapacityWhenResultsConsumedCapacityIsNull() { RetryResult stubbedResult = new RetryResult<>(new ScanResult().withConsumedCapacity(null) .withItems(new HashMap<String, AttributeValue>()), 0); stubScanTableWith(stubbedResult); when(context.getClient()).thenReturn(client); when(context.getConf()).thenReturn(new JobConf()); when(context.getSplit()).thenReturn(new DynamoDBSegmentsSplit()); ScanReadManager readManager = Mockito.mock(ScanReadManager.class); ScanRecordReadRequest readRequest = new ScanRecordReadRequest(readManager, context, 0, null); PageResults<Map<String, AttributeValue>> pageResults = readRequest.fetchPage(new RequestLimit(0, 0)); assertEquals(0.0, pageResults.consumedRcu, 0.0); }
@Override public RetryResult<ScanResult> scanTable(String tableName, DynamoDBQueryFilter dynamoDBQueryFilter, Integer segment, Integer totalSegments, Map<String, AttributeValue> exclusiveStartKey, long limit, Reporter reporter) { List<Map<String, AttributeValue>> items = getItems(); if (i == 0) { Map<String, AttributeValue> lastEvaluatedKey = new HashMap<>(); lastEvaluatedKey.put("test", new AttributeValue("test")); i++; return new RetryResult<>(new ScanResult().withScannedCount(items.size()) .withConsumedCapacity(new ConsumedCapacity().withCapacityUnits(1d)).withItems (items).withLastEvaluatedKey(lastEvaluatedKey), 0); } else { assertEquals("test", exclusiveStartKey.get("test").getS()); return new RetryResult<>(new ScanResult().withScannedCount(items.size()) .withConsumedCapacity(new ConsumedCapacity().withCapacityUnits(1d)).withItems (items), 0); } }