Search in sources :

Example 1 with BatchGetItemEnhancedRequest

use of software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest in project aws-sdk-java-v2 by aws.

the class BatchGetItemTest method notFoundRecordIgnored.

@Test
public void notFoundRecordIgnored() {
    insertRecords();
    BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = batchGetItemEnhancedRequestWithNotFoundRecord();
    SdkIterable<BatchGetResultPage> results = enhancedClient.batchGetItem(batchGetItemEnhancedRequest);
    assertThat(results.stream().count(), is(1L));
    results.iterator().forEachRemaining((page) -> {
        List<Record1> mappedTable1Results = page.resultsForTable(mappedTable1);
        assertThat(mappedTable1Results.size(), is(1));
        assertThat(mappedTable1Results.get(0).id, is(0));
        assertThat(page.resultsForTable(mappedTable2).size(), is(2));
    });
}
Also used : BatchGetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) Test(org.junit.Test)

Example 2 with BatchGetItemEnhancedRequest

use of software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest in project aws-sdk-java-v2 by aws.

the class AsyncBatchGetItemTest method notFoundRecordReturnsNull.

@Test
public void notFoundRecordReturnsNull() {
    insertRecords();
    BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = requestWithNotFoundRecord();
    SdkPublisher<BatchGetResultPage> publisher = enhancedAsyncClient.batchGetItem(batchGetItemEnhancedRequest);
    List<BatchGetResultPage> results = drainPublisher(publisher, 1);
    assertThat(results.size(), is(1));
    BatchGetResultPage page = results.get(0);
    List<Record1> record1List = page.resultsForTable(mappedTable1);
    assertThat(record1List.size(), is(1));
    assertThat(record1List.get(0).getId(), is(0));
    List<Record2> record2List = page.resultsForTable(mappedTable2);
    assertThat(record2List.size(), is(2));
    assertThat(record2List, containsInAnyOrder(RECORDS_2.get(0), RECORDS_2.get(1)));
}
Also used : BatchGetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) Test(org.junit.Test)

Example 3 with BatchGetItemEnhancedRequest

use of software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest in project aws-sdk-java-v2 by aws.

the class BatchGetItemOperationTest method generateRequest_multipleBatches_multipleTableSchemas_ConflictingConsistentReadStartingWithNull.

@Test(expected = IllegalArgumentException.class)
public void generateRequest_multipleBatches_multipleTableSchemas_ConflictingConsistentReadStartingWithNull() {
    BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = BatchGetItemEnhancedRequest.builder().readBatches(ReadBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addGetItem(GetItemEnhancedRequest.builder().key(FAKE_ITEM_KEYS.get(0)).consistentRead(true).build()).addGetItem(GetItemEnhancedRequest.builder().key(FAKE_ITEM_KEYS.get(1)).consistentRead(true).build()).addGetItem(GetItemEnhancedRequest.builder().key(FAKE_ITEM_KEYS.get(2)).consistentRead(true).build()).build(), ReadBatch.builder(FakeItemWithSort.class).mappedTableResource(fakeItemWithSortMappedTable).addGetItem(GetItemEnhancedRequest.builder().key(FAKESORT_ITEM_KEYS.get(0)).build()).addGetItem(GetItemEnhancedRequest.builder().key(FAKESORT_ITEM_KEYS.get(1)).consistentRead(true).build()).addGetItem(GetItemEnhancedRequest.builder().key(FAKESORT_ITEM_KEYS.get(2)).consistentRead(true).build()).build()).build();
    BatchGetItemOperation operation = BatchGetItemOperation.create(batchGetItemEnhancedRequest);
    operation.generateRequest(mockExtension);
}
Also used : BatchGetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest) FakeItemWithSort.createUniqueFakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort.createUniqueFakeItemWithSort) FakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Example 4 with BatchGetItemEnhancedRequest

use of software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest in project aws-sdk-java-v2 by aws.

the class BatchGetItemOperationTest method getServiceCall_usingShortcutForm_makesTheRightCallAndReturnsResponse.

@Test
public void getServiceCall_usingShortcutForm_makesTheRightCallAndReturnsResponse() {
    BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = BatchGetItemEnhancedRequest.builder().readBatches(ReadBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addGetItem(FAKE_ITEM_KEYS.get(0)).build()).build();
    BatchGetItemOperation operation = BatchGetItemOperation.create(batchGetItemEnhancedRequest);
    BatchGetItemRequest batchGetItemRequest = BatchGetItemRequest.builder().requestItems(singletonMap("test-table", KeysAndAttributes.builder().keys(singletonList(FAKE_ITEM_MAPS.get(0))).build())).build();
    BatchGetItemIterable expectedResponse = mock(BatchGetItemIterable.class);
    when(mockDynamoDbClient.batchGetItemPaginator(any(BatchGetItemRequest.class))).thenReturn(expectedResponse);
    SdkIterable<BatchGetItemResponse> response = operation.serviceCall(mockDynamoDbClient).apply(batchGetItemRequest);
    assertThat(response, sameInstance(expectedResponse));
    verify(mockDynamoDbClient).batchGetItemPaginator(batchGetItemRequest);
}
Also used : BatchGetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest) BatchGetItemRequest(software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest) BatchGetItemResponse(software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse) BatchGetItemIterable(software.amazon.awssdk.services.dynamodb.paginators.BatchGetItemIterable) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Example 5 with BatchGetItemEnhancedRequest

use of software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest in project aws-sdk-java-v2 by aws.

the class BatchGetItemOperationTest method generateRequest_multipleBatches_multipleTableSchemas.

@Test
public void generateRequest_multipleBatches_multipleTableSchemas() {
    BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = BatchGetItemEnhancedRequest.builder().readBatches(ReadBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addGetItem(r -> r.key(FAKE_ITEM_KEYS.get(0))).addGetItem(r -> r.key(FAKE_ITEM_KEYS.get(1))).addGetItem(r -> r.key(FAKE_ITEM_KEYS.get(2))).build(), ReadBatch.builder(FakeItemWithSort.class).mappedTableResource(fakeItemWithSortMappedTable).addGetItem(r -> r.key(FAKESORT_ITEM_KEYS.get(0))).addGetItem(r -> r.key(FAKESORT_ITEM_KEYS.get(1))).addGetItem(r -> r.key(FAKESORT_ITEM_KEYS.get(2))).build()).build();
    BatchGetItemOperation operation = BatchGetItemOperation.create(batchGetItemEnhancedRequest);
    BatchGetItemRequest batchGetItemRequest = operation.generateRequest(mockExtension);
    KeysAndAttributes keysAndAttributes1 = batchGetItemRequest.requestItems().get(TABLE_NAME);
    KeysAndAttributes keysAndAttributes2 = batchGetItemRequest.requestItems().get(TABLE_NAME_2);
    assertThat(keysAndAttributes1.keys(), containsInAnyOrder(FAKE_ITEM_MAPS.subList(0, 3).toArray()));
    assertThat(keysAndAttributes2.keys(), containsInAnyOrder(FAKESORT_ITEM_MAPS.subList(0, 3).toArray()));
    assertThat(keysAndAttributes1.consistentRead(), is(nullValue()));
    assertThat(keysAndAttributes2.consistentRead(), is(nullValue()));
    verifyNoMoreInteractions(mockExtension);
}
Also used : BatchGetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient) BatchGetItemRequest(software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest) Arrays(java.util.Arrays) KeysAndAttributes(software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) BatchGetItemIterable(software.amazon.awssdk.services.dynamodb.paginators.BatchGetItemIterable) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) Mockito.doReturn(org.mockito.Mockito.doReturn) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Collections.emptyList(java.util.Collections.emptyList) SdkIterable(software.amazon.awssdk.core.pagination.sync.SdkIterable) Key(software.amazon.awssdk.enhanced.dynamodb.Key) ReadModification(software.amazon.awssdk.enhanced.dynamodb.extensions.ReadModification) List(java.util.List) DynamoDbEnhancedClientExtension(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension) BatchGetItemResponse(software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) FakeItemWithSort.createUniqueFakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort.createUniqueFakeItemWithSort) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Matchers.is(org.hamcrest.Matchers.is) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) ReadBatch(software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) FakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort) HashMap(java.util.HashMap) BatchGetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) Collections.singletonMap(java.util.Collections.singletonMap) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) DynamoDbTable(software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable) GetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Collections(java.util.Collections) BatchGetItemRequest(software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest) FakeItemWithSort.createUniqueFakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort.createUniqueFakeItemWithSort) FakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort) KeysAndAttributes(software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 BatchGetItemEnhancedRequest (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest)10 FakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem)6 FakeItem.createUniqueFakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem)6 FakeItemWithSort (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort)4 FakeItemWithSort.createUniqueFakeItemWithSort (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort.createUniqueFakeItemWithSort)4 BatchGetItemRequest (software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest)4 BatchGetResultPage (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage)3 BatchGetItemResponse (software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse)3 BatchGetItemIterable (software.amazon.awssdk.services.dynamodb.paginators.BatchGetItemIterable)3 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1