Search in sources :

Example 1 with BatchGetResultPage

use of software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage 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 BatchGetResultPage

use of software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage 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 BatchGetResultPage

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

the class AsyncBatchGetItemTest method getRecordsFromMultipleTables.

@Test
public void getRecordsFromMultipleTables() {
    insertRecords();
    SdkPublisher<BatchGetResultPage> publisher = batchGetResultPageSdkPublisherForBothTables();
    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(2));
    assertThat(record1List, containsInAnyOrder(RECORDS_1.get(0), RECORDS_1.get(1)));
    List<Record2> record2List = page.resultsForTable(mappedTable2);
    assertThat(record2List.size(), is(2));
    assertThat(record2List, containsInAnyOrder(RECORDS_2.get(0), RECORDS_2.get(1)));
}
Also used : BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) Test(org.junit.Test)

Example 4 with BatchGetResultPage

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

the class BatchGetItemOperationTest method transformResponse_multipleTables_multipleItems_no_unprocessedKeys.

@Test
public void transformResponse_multipleTables_multipleItems_no_unprocessedKeys() {
    BatchGetItemResponse fakeResponse = BatchGetItemResponse.builder().build();
    BatchGetItemOperation operation = BatchGetItemOperation.create(emptyRequest());
    BatchGetResultPage resultsPage = operation.transformResponse(fakeResponse, null);
    List<Key> fakeItemResults1 = resultsPage.unprocessedKeysForTable(fakeItemMappedTable);
    List<Key> fakeItemResults2 = resultsPage.unprocessedKeysForTable(fakeItemWithSortMappedTable);
    assertThat(fakeItemResults1, empty());
    assertThat(fakeItemResults2, empty());
}
Also used : BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) BatchGetItemResponse(software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Test(org.junit.Test)

Example 5 with BatchGetResultPage

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

the class BatchGetItemOperationTest method transformResponse_multipleTables_multipleItems_unprocessedKeys.

@Test
public void transformResponse_multipleTables_multipleItems_unprocessedKeys() {
    KeysAndAttributes keysAndAttributes1 = KeysAndAttributes.builder().keys(Arrays.asList(FAKE_ITEM_MAPS.get(0), FAKE_ITEM_MAPS.get(1))).build();
    KeysAndAttributes keysAndAttributes2 = KeysAndAttributes.builder().keys(Collections.singletonList(FAKESORT_ITEM_MAPS.get(0))).build();
    Map<String, KeysAndAttributes> keysAndAttributesMap = new HashMap<>();
    keysAndAttributesMap.put(TABLE_NAME, keysAndAttributes1);
    keysAndAttributesMap.put(TABLE_NAME_2, keysAndAttributes2);
    BatchGetItemResponse fakeResponse = BatchGetItemResponse.builder().unprocessedKeys(keysAndAttributesMap).build();
    BatchGetItemOperation operation = BatchGetItemOperation.create(emptyRequest());
    BatchGetResultPage resultsPage = operation.transformResponse(fakeResponse, null);
    List<Key> fakeItemResults1 = resultsPage.unprocessedKeysForTable(fakeItemMappedTable);
    List<Key> fakeItemResults2 = resultsPage.unprocessedKeysForTable(fakeItemWithSortMappedTable);
    assertThat(fakeItemResults1, containsInAnyOrder(FAKE_ITEM_KEYS.get(0), FAKE_ITEM_KEYS.get(1)));
    assertThat(fakeItemResults2, containsInAnyOrder(FAKESORT_ITEM_KEYS.get(0)));
}
Also used : HashMap(java.util.HashMap) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) BatchGetItemResponse(software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse) KeysAndAttributes(software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 BatchGetResultPage (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage)10 BatchGetItemResponse (software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse)6 HashMap (java.util.HashMap)4 Key (software.amazon.awssdk.enhanced.dynamodb.Key)4 List (java.util.List)3 KeysAndAttributes (software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes)3 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 Collectors.toList (java.util.stream.Collectors.toList)2 Before (org.junit.Before)2 SdkIterable (software.amazon.awssdk.core.pagination.sync.SdkIterable)2 DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)2 DynamoDbTable (software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable)2 BatchGetItemEnhancedRequest (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest)2 ReadBatch (software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch)2 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)2 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1