use of software.amazon.awssdk.services.dynamodb.model.DeleteRequest in project aws-sdk-java-v2 by aws.
the class WriteBatchTest method builder_maximal_consumer_style.
@Test
public void builder_maximal_consumer_style() {
FakeItem fakeItem = createUniqueFakeItem();
WriteBatch builtObject = WriteBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addPutItem(r -> r.item(fakeItem)).addDeleteItem(r -> r.key(k -> k.partitionValue(fakeItem.getId()))).build();
Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, FakeItem.getTableMetadata().primaryKeys());
assertThat(builtObject.tableName(), is(TABLE_NAME));
assertThat(builtObject.writeRequests(), containsInAnyOrder(putRequest(fakeItemMap), deleteRequest(fakeItemMap)));
}
use of software.amazon.awssdk.services.dynamodb.model.DeleteRequest in project aws-sdk-java-v2 by aws.
the class BatchWriteItemOperationTest method generateRequest_multipleTables_extensionOnlyTransformsPutsAndNotDeletes.
@Test
public void generateRequest_multipleTables_extensionOnlyTransformsPutsAndNotDeletes() {
// Use the mock extension to transform every item based on table name
IntStream.range(0, 3).forEach(i -> {
lenient().doReturn(WriteModification.builder().transformedItem(FAKE_ITEM_MAPS.get(i + 3)).build()).when(mockExtension).beforeWrite(argThat(extensionContext -> extensionContext.operationContext().tableName().equals(TABLE_NAME) && extensionContext.items().equals(FAKE_ITEM_MAPS.get(i))));
lenient().doReturn(WriteModification.builder().transformedItem(FAKESORT_ITEM_MAPS.get(i + 3)).build()).when(mockExtension).beforeWrite(argThat(extensionContext -> extensionContext.operationContext().tableName().equals(TABLE_NAME_2) && extensionContext.items().equals(FAKESORT_ITEM_MAPS.get(i))));
});
BatchWriteItemEnhancedRequest batchWriteItemEnhancedRequest = BatchWriteItemEnhancedRequest.builder().writeBatches(WriteBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTableWithExtension).addPutItem(r -> r.item(FAKE_ITEMS.get(0))).addDeleteItem(r -> r.key(FAKE_ITEM_KEYS.get(1))).addPutItem(r -> r.item(FAKE_ITEMS.get(2))).build(), WriteBatch.builder(FakeItemWithSort.class).mappedTableResource(fakeItemWithSortMappedTableWithExtension).addDeleteItem(r -> r.key(FAKESORT_ITEM_KEYS.get(0))).addPutItem(r -> r.item(FAKESORT_ITEMS.get(1))).addDeleteItem(r -> r.key(FAKESORT_ITEM_KEYS.get(2))).build()).build();
BatchWriteItemOperation operation = BatchWriteItemOperation.create(batchWriteItemEnhancedRequest);
BatchWriteItemRequest request = operation.generateRequest(mockExtension);
List<WriteRequest> writeRequests1 = request.requestItems().get(TABLE_NAME);
List<WriteRequest> writeRequests2 = request.requestItems().get(TABLE_NAME_2);
// Only PutItem requests should have their attributes transformed
assertThat(writeRequests1, containsInAnyOrder(putRequest(FAKE_ITEM_MAPS.get(3)), deleteRequest(FAKE_ITEM_MAPS.get(1)), putRequest(FAKE_ITEM_MAPS.get(5))));
assertThat(writeRequests2, containsInAnyOrder(deleteRequest(FAKESORT_ITEM_MAPS.get(0)), putRequest(FAKESORT_ITEM_MAPS.get(4)), deleteRequest(FAKESORT_ITEM_MAPS.get(2))));
}
use of software.amazon.awssdk.services.dynamodb.model.DeleteRequest in project aws-sdk-java-v2 by aws.
the class WriteBatchTest method builder_maximal_builder_style.
@Test
public void builder_maximal_builder_style() {
FakeItem fakeItem = createUniqueFakeItem();
PutItemEnhancedRequest<FakeItem> putItem = PutItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).build();
DeleteItemEnhancedRequest deleteItem = DeleteItemEnhancedRequest.builder().key(k -> k.partitionValue(fakeItem.getId())).build();
WriteBatch builtObject = WriteBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addPutItem(putItem).addDeleteItem(deleteItem).build();
Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, FakeItem.getTableMetadata().primaryKeys());
assertThat(builtObject.tableName(), is(TABLE_NAME));
assertThat(builtObject.writeRequests(), containsInAnyOrder(putRequest(fakeItemMap), deleteRequest(fakeItemMap)));
}
use of software.amazon.awssdk.services.dynamodb.model.DeleteRequest 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)));
}
Aggregations