use of software.amazon.awssdk.enhanced.dynamodb.model.BatchWriteResult in project aws-sdk-java-v2 by aws.
the class BatchWriteItemOperationTest method transformResults_multipleUnprocessedOperations_extensionTransformsPutsNotDeletes.
@Test
public void transformResults_multipleUnprocessedOperations_extensionTransformsPutsNotDeletes() {
BatchWriteItemOperation operation = BatchWriteItemOperation.create(emptyRequest());
List<WriteRequest> writeRequests1 = Arrays.asList(putRequest(FAKE_ITEM_MAPS.get(0)), deleteRequest(FAKE_ITEM_MAPS.get(1)), deleteRequest(FAKE_ITEM_MAPS.get(2)));
List<WriteRequest> writeRequests2 = Arrays.asList(deleteRequest(FAKESORT_ITEM_MAPS.get(0)), putRequest(FAKESORT_ITEM_MAPS.get(1)), putRequest(FAKESORT_ITEM_MAPS.get(2)));
Map<String, List<WriteRequest>> writeRequests = new HashMap<>();
writeRequests.put(TABLE_NAME, writeRequests1);
writeRequests.put(TABLE_NAME_2, writeRequests2);
BatchWriteItemResponse response = BatchWriteItemResponse.builder().unprocessedItems(writeRequests).build();
// Use the mock extension to transform every item based on table name
IntStream.range(0, 3).forEach(i -> {
doReturn(ReadModification.builder().transformedItem(FAKE_ITEM_MAPS.get(i + 3)).build()).when(mockExtension).afterRead(argThat(extensionContext -> extensionContext.operationContext().tableName().equals(TABLE_NAME) && extensionContext.items().equals(FAKE_ITEM_MAPS.get(i))));
doReturn(ReadModification.builder().transformedItem(FAKESORT_ITEM_MAPS.get(i + 3)).build()).when(mockExtension).afterRead(argThat(extensionContext -> extensionContext.operationContext().tableName().equals(TABLE_NAME_2) && extensionContext.items().equals(FAKESORT_ITEM_MAPS.get(i))));
});
BatchWriteResult results = operation.transformResponse(response, mockExtension);
assertThat(results.unprocessedDeleteItemsForTable(fakeItemMappedTableWithExtension), containsInAnyOrder(FAKE_ITEM_KEYS.get(1), FAKE_ITEM_KEYS.get(2)));
assertThat(results.unprocessedPutItemsForTable(fakeItemMappedTableWithExtension), containsInAnyOrder(FAKE_ITEMS.get(3)));
assertThat(results.unprocessedDeleteItemsForTable(fakeItemWithSortMappedTableWithExtension), containsInAnyOrder(FAKESORT_ITEM_KEYS.get(0)));
assertThat(results.unprocessedPutItemsForTable(fakeItemWithSortMappedTableWithExtension), containsInAnyOrder(FAKESORT_ITEMS.get(4), FAKESORT_ITEMS.get(5)));
}
use of software.amazon.awssdk.enhanced.dynamodb.model.BatchWriteResult in project aws-sdk-java-v2 by aws.
the class BatchWriteItemOperationTest method transformResults_noUnprocessedOperations.
@Test
public void transformResults_noUnprocessedOperations() {
BatchWriteItemOperation operation = BatchWriteItemOperation.create(emptyRequest());
BatchWriteItemResponse response = BatchWriteItemResponse.builder().unprocessedItems(emptyMap()).build();
BatchWriteResult results = operation.transformResponse(response, mockExtension);
assertThat(results.unprocessedDeleteItemsForTable(fakeItemMappedTable), is(emptyList()));
assertThat(results.unprocessedPutItemsForTable(fakeItemMappedTable), is(emptyList()));
}
use of software.amazon.awssdk.enhanced.dynamodb.model.BatchWriteResult in project aws-sdk-java-v2 by aws.
the class BatchWriteItemOperationTest method transformResults_multipleUnprocessedOperations.
@Test
public void transformResults_multipleUnprocessedOperations() {
BatchWriteItemOperation operation = BatchWriteItemOperation.create(emptyRequest());
List<WriteRequest> writeRequests1 = Arrays.asList(putRequest(FAKE_ITEM_MAPS.get(0)), deleteRequest(FAKE_ITEM_MAPS.get(1)), deleteRequest(FAKE_ITEM_MAPS.get(2)));
List<WriteRequest> writeRequests2 = Arrays.asList(deleteRequest(FAKESORT_ITEM_MAPS.get(0)), putRequest(FAKESORT_ITEM_MAPS.get(1)), putRequest(FAKESORT_ITEM_MAPS.get(2)));
Map<String, List<WriteRequest>> writeRequests = new HashMap<>();
writeRequests.put(TABLE_NAME, writeRequests1);
writeRequests.put(TABLE_NAME_2, writeRequests2);
BatchWriteItemResponse response = BatchWriteItemResponse.builder().unprocessedItems(writeRequests).build();
BatchWriteResult results = operation.transformResponse(response, mockExtension);
assertThat(results.unprocessedDeleteItemsForTable(fakeItemMappedTableWithExtension), containsInAnyOrder(FAKE_ITEM_KEYS.get(1), FAKE_ITEM_KEYS.get(2)));
assertThat(results.unprocessedPutItemsForTable(fakeItemMappedTableWithExtension), containsInAnyOrder(FAKE_ITEMS.get(0)));
assertThat(results.unprocessedDeleteItemsForTable(fakeItemWithSortMappedTableWithExtension), containsInAnyOrder(FAKESORT_ITEM_KEYS.get(0)));
assertThat(results.unprocessedPutItemsForTable(fakeItemWithSortMappedTableWithExtension), containsInAnyOrder(FAKESORT_ITEMS.get(1), FAKESORT_ITEMS.get(2)));
}
Aggregations