Search in sources :

Example 1 with BatchGetResultPageIterable

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

the class BatchGetItemTest method getRecordsFromMultipleTables_viaFlattenedItems.

@Test
public void getRecordsFromMultipleTables_viaFlattenedItems() {
    insertRecords();
    BatchGetResultPageIterable results = getBatchGetResultPagesForBothTables();
    SdkIterable<Record1> recordsList1 = results.resultsForTable(mappedTable1);
    assertThat(recordsList1, containsInAnyOrder(RECORDS_1.toArray()));
    SdkIterable<Record2> recordsList2 = results.resultsForTable(mappedTable2);
    assertThat(recordsList2, containsInAnyOrder(RECORDS_2.toArray()));
}
Also used : BatchGetResultPageIterable(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable) Test(org.junit.Test)

Example 2 with BatchGetResultPageIterable

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

the class BatchGetItemTest method successfulResponseWithoutUnprocessedKeys_NoNextPage_viaFlattenedItems.

@Test
public void successfulResponseWithoutUnprocessedKeys_NoNextPage_viaFlattenedItems() {
    stubSuccessfulResponse();
    BatchGetResultPageIterable batchGetResultPages = enhancedClient.batchGetItem(r -> r.readBatches(ReadBatch.builder(Record.class).mappedTableResource(table).addGetItem(i -> i.key(k -> k.partitionValue(0))).build()));
    assertThat(batchGetResultPages.resultsForTable(table)).hasSize(3);
}
Also used : DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) ReadBatch(software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch) DynamoDbTable(software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable) Iterator(java.util.Iterator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SdkIterable(software.amazon.awssdk.core.pagination.sync.SdkIterable) BatchGetTestUtils.stubResponseWithUnprocessedKeys(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubResponseWithUnprocessedKeys) Test(org.junit.Test) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) Collectors(java.util.stream.Collectors) BatchGetResultPageIterable(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable) StaticAttributeTags.primaryPartitionKey(software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) List(java.util.List) Rule(org.junit.Rule) BatchGetTestUtils.stubSuccessfulResponse(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubSuccessfulResponse) URI(java.net.URI) StaticTableSchema(software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) Before(org.junit.Before) BatchGetResultPageIterable(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) Test(org.junit.Test)

Example 3 with BatchGetResultPageIterable

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

the class BatchGetItemTest method responseWithUnprocessedKeys_iterateItems_shouldFetchUnprocessedKeys.

@Test
public void responseWithUnprocessedKeys_iterateItems_shouldFetchUnprocessedKeys() {
    stubResponseWithUnprocessedKeys();
    BatchGetResultPageIterable batchGetResultPages = enhancedClient.batchGetItem(r -> r.readBatches(ReadBatch.builder(Record.class).mappedTableResource(table).addGetItem(i -> i.key(k -> k.partitionValue("1"))).build()));
    SdkIterable<Record> results = batchGetResultPages.resultsForTable(table);
    assertThat(results.stream().count()).isEqualTo(3);
}
Also used : DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) ReadBatch(software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch) DynamoDbTable(software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable) Iterator(java.util.Iterator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SdkIterable(software.amazon.awssdk.core.pagination.sync.SdkIterable) BatchGetTestUtils.stubResponseWithUnprocessedKeys(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubResponseWithUnprocessedKeys) Test(org.junit.Test) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) Collectors(java.util.stream.Collectors) BatchGetResultPageIterable(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable) StaticAttributeTags.primaryPartitionKey(software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) List(java.util.List) Rule(org.junit.Rule) BatchGetTestUtils.stubSuccessfulResponse(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubSuccessfulResponse) URI(java.net.URI) StaticTableSchema(software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) Before(org.junit.Before) BatchGetResultPageIterable(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) Test(org.junit.Test)

Example 4 with BatchGetResultPageIterable

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

the class BatchGetItemTest method notFoundRecordIgnored_viaFlattenedItems.

@Test
public void notFoundRecordIgnored_viaFlattenedItems() {
    insertRecords();
    BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = batchGetItemEnhancedRequestWithNotFoundRecord();
    BatchGetResultPageIterable pageIterable = enhancedClient.batchGetItem(batchGetItemEnhancedRequest);
    assertThat(pageIterable.stream().count(), is(1L));
    List<Record1> recordsList1 = pageIterable.resultsForTable(mappedTable1).stream().collect(Collectors.toList());
    assertThat(recordsList1, is(RECORDS_1.subList(0, 1)));
    SdkIterable<Record2> recordsList2 = pageIterable.resultsForTable(mappedTable2);
    assertThat(recordsList2, containsInAnyOrder(RECORDS_2.toArray()));
}
Also used : BatchGetItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest) BatchGetResultPageIterable(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 BatchGetResultPageIterable (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable)4 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)2 URI (java.net.URI)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)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 StaticAttributeTags.primaryPartitionKey (software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey)2 StaticTableSchema (software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema)2 Record (software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record)2 BatchGetTestUtils.stubResponseWithUnprocessedKeys (software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubResponseWithUnprocessedKeys)2 BatchGetTestUtils.stubSuccessfulResponse (software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubSuccessfulResponse)2 BatchGetResultPage (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage)2