Search in sources :

Example 1 with WriteRequest

use of software.amazon.awssdk.services.dynamodb.model.WriteRequest in project beam by apache.

the class DynamoDBIOWriteTest method testWritePutItemsWithPartialSuccess.

@Test
public void testWritePutItemsWithPartialSuccess() {
    List<WriteRequest> writes = putRequests(Item.range(0, 10));
    when(client.batchWriteItem(any(BatchWriteItemRequest.class))).thenReturn(partialWriteSuccess(writes.subList(4, 10))).thenReturn(partialWriteSuccess(writes.subList(8, 10))).thenReturn(BatchWriteItemResponse.builder().build());
    pipeline.apply(// number if items to produce
    Create.of(10)).apply(// 10 items in one bundle
    ParDo.of(new GenerateItems())).apply("write", DynamoDBIO.<Item>write().withWriteRequestMapperFn(putRequestMapper));
    PipelineResult result = pipeline.run();
    result.waitUntilFinish();
    verify(client, times(3)).batchWriteItem(any(BatchWriteItemRequest.class));
    InOrder ordered = inOrder(client);
    ordered.verify(client).batchWriteItem(argThat(matchWritesUnordered(writes)));
    ordered.verify(client).batchWriteItem(argThat(matchWritesUnordered(writes.subList(4, 10))));
    ordered.verify(client).batchWriteItem(argThat(matchWritesUnordered(writes.subList(8, 10))));
}
Also used : InOrder(org.mockito.InOrder) WriteRequest(software.amazon.awssdk.services.dynamodb.model.WriteRequest) PipelineResult(org.apache.beam.sdk.PipelineResult) BatchWriteItemRequest(software.amazon.awssdk.services.dynamodb.model.BatchWriteItemRequest) Test(org.junit.Test)

Aggregations

PipelineResult (org.apache.beam.sdk.PipelineResult)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 BatchWriteItemRequest (software.amazon.awssdk.services.dynamodb.model.BatchWriteItemRequest)1 WriteRequest (software.amazon.awssdk.services.dynamodb.model.WriteRequest)1