Search in sources :

Example 1 with SdkIterable

use of software.amazon.awssdk.core.pagination.sync.SdkIterable 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 2 with SdkIterable

use of software.amazon.awssdk.core.pagination.sync.SdkIterable in project aws-sdk-java-v2 by aws.

the class BatchGetItemTest method responseWithUnprocessedKeys_iteratePage_shouldFetchUnprocessedKeys.

@Test
public void responseWithUnprocessedKeys_iteratePage_shouldFetchUnprocessedKeys() {
    stubResponseWithUnprocessedKeys();
    SdkIterable<BatchGetResultPage> batchGetResultPages = enhancedClient.batchGetItem(r -> r.readBatches(ReadBatch.builder(Record.class).mappedTableResource(table).addGetItem(i -> i.key(k -> k.partitionValue("1"))).build()));
    Iterator<BatchGetResultPage> iterator = batchGetResultPages.iterator();
    BatchGetResultPage firstPage = iterator.next();
    List<Record> resultsForTable = firstPage.resultsForTable(table);
    assertThat(resultsForTable.size()).isEqualTo(2);
    BatchGetResultPage secondPage = iterator.next();
    assertThat(secondPage.resultsForTable(table).size()).isEqualTo(1);
    assertThat(iterator).isExhausted();
}
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) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) Test(org.junit.Test)

Aggregations

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 Test (org.junit.Test)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 BatchGetResultPageIterable (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPageIterable)2