Search in sources :

Example 1 with Record

use of software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record in project aws-sdk-java-v2 by aws.

the class AsyncBatchGetItemTest method successfulResponseWithoutUnprocessedKeys_viaFlattenedItems_NoNextPage.

@Test
public void successfulResponseWithoutUnprocessedKeys_viaFlattenedItems_NoNextPage() {
    stubSuccessfulResponse();
    BatchGetResultPagePublisher publisher = enhancedClient.batchGetItem(r -> r.readBatches(ReadBatch.builder(Record.class).mappedTableResource(table).build()));
    List<Record> records = drainPublisher(publisher.resultsForTable(table), 3);
    assertThat(records.size()).isEqualTo(3);
}
Also used : Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) BatchGetResultPagePublisher(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPagePublisher) Test(org.junit.Test)

Example 2 with Record

use of software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record in project aws-sdk-java-v2 by aws.

the class BatchGetItemTest method setup.

@Before
public void setup() {
    DynamoDbClient dynamoDbClient = DynamoDbClient.builder().region(Region.US_WEST_2).credentialsProvider(() -> AwsBasicCredentials.create("foo", "bar")).endpointOverride(URI.create("http://localhost:" + wireMock.port())).endpointDiscoveryEnabled(false).build();
    enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(dynamoDbClient).build();
    StaticTableSchema<Record> tableSchema = StaticTableSchema.builder(Record.class).newItemSupplier(Record::new).addAttribute(Integer.class, a -> a.name("id").getter(Record::getId).setter(Record::setId).tags(primaryPartitionKey())).build();
    table = enhancedClient.table("table", tableSchema);
}
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) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) Before(org.junit.Before)

Example 3 with Record

use of software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record 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 Record

use of software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record in project aws-sdk-java-v2 by aws.

the class AsyncBatchGetItemTest method responseWithUnprocessedKeys_iterateItems_shouldFetchUnprocessedKeys.

@Test
public void responseWithUnprocessedKeys_iterateItems_shouldFetchUnprocessedKeys() throws InterruptedException {
    stubResponseWithUnprocessedKeys();
    BatchGetResultPagePublisher publisher = enhancedClient.batchGetItem(r -> r.readBatches(ReadBatch.builder(Record.class).mappedTableResource(table).build()));
    List<Record> records = drainPublisher(publisher.resultsForTable(table), 3);
    assertThat(records.size()).isEqualTo(3);
}
Also used : Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) BatchGetResultPagePublisher(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPagePublisher) Test(org.junit.Test)

Example 5 with Record

use of software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record in project aws-sdk-java-v2 by aws.

the class AsyncBatchGetItemTest method setup.

@Before
public void setup() {
    DynamoDbAsyncClient dynamoDbClient = DynamoDbAsyncClient.builder().region(Region.US_WEST_2).credentialsProvider(() -> AwsBasicCredentials.create("foo", "bar")).endpointOverride(URI.create("http://localhost:" + wireMock.port())).endpointDiscoveryEnabled(false).build();
    enhancedClient = DynamoDbEnhancedAsyncClient.builder().dynamoDbClient(dynamoDbClient).build();
    StaticTableSchema<Record> tableSchema = StaticTableSchema.builder(Record.class).newItemSupplier(Record::new).addAttribute(Integer.class, a -> a.name("id").getter(Record::getId).setter(Record::setId).tags(primaryPartitionKey())).build();
    table = enhancedClient.table("table", tableSchema);
}
Also used : Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) ReadBatch(software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch) BatchGetResultPagePublisher(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPagePublisher) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) BatchGetTestUtils.stubResponseWithUnprocessedKeys(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubResponseWithUnprocessedKeys) Test(org.junit.Test) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) DynamoDbEnhancedAsyncClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient) BatchGetResultPage(software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage) 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) After(org.junit.After) BatchGetTestUtils.stubSuccessfulResponse(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubSuccessfulResponse) DynamoDbAsyncTable(software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable) 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) LocalDynamoDbAsyncTestBase.drainPublisher(software.amazon.awssdk.enhanced.dynamodb.functionaltests.LocalDynamoDbAsyncTestBase.drainPublisher) Before(org.junit.Before) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Record(software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)6 Record (software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.Record)6 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)4 URI (java.net.URI)4 List (java.util.List)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Before (org.junit.Before)4 Rule (org.junit.Rule)4 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)4 StaticAttributeTags.primaryPartitionKey (software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags.primaryPartitionKey)4 StaticTableSchema (software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema)4 BatchGetTestUtils.stubResponseWithUnprocessedKeys (software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubResponseWithUnprocessedKeys)4 BatchGetTestUtils.stubSuccessfulResponse (software.amazon.awssdk.enhanced.dynamodb.mocktests.BatchGetTestUtils.stubSuccessfulResponse)4 BatchGetResultPage (software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage)4 ReadBatch (software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch)4 Region (software.amazon.awssdk.regions.Region)4 Iterator (java.util.Iterator)3 Collectors (java.util.stream.Collectors)3 SdkIterable (software.amazon.awssdk.core.pagination.sync.SdkIterable)3 DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)3