|
| 1 | +/* |
| 2 | + * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.services.ec2; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | + |
| 20 | +import java.time.Instant; |
| 21 | +import java.util.stream.Stream; |
| 22 | +import org.junit.Test; |
| 23 | +import software.amazon.awssdk.regions.Region; |
| 24 | +import software.amazon.awssdk.services.ec2.model.SpotPrice; |
| 25 | +import software.amazon.awssdk.services.ec2.paginators.DescribeSpotPriceHistoryPublisher; |
| 26 | +import software.amazon.awssdk.testutils.service.AwsIntegrationTestBase; |
| 27 | + |
| 28 | +public class Ec2AutoPaginatorIntegrationTest extends AwsIntegrationTestBase { |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testSpotPriceHistorySyncPaginator() { |
| 32 | + Ec2Client ec2Client = Ec2Client.builder() |
| 33 | + .region(Region.US_EAST_1) |
| 34 | + .credentialsProvider(CREDENTIALS_PROVIDER_CHAIN) |
| 35 | + .build(); |
| 36 | + |
| 37 | + Stream<SpotPrice> spotPrices = ec2Client.describeSpotPriceHistoryPaginator(builder -> { |
| 38 | + builder.availabilityZone("us-east-1a") |
| 39 | + .productDescriptions("Linux/UNIX (Amazon VPC)") |
| 40 | + .instanceTypesWithStrings("t1.micro") |
| 41 | + .startTime(Instant.now().minusMillis(1)); |
| 42 | + }).spotPriceHistory().stream(); |
| 43 | + |
| 44 | + assertThat(spotPrices.count()).isEqualTo(1); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testSpotPriceHistoryAsyncPaginator() { |
| 49 | + Ec2AsyncClient ec2Client = Ec2AsyncClient.builder() |
| 50 | + .region(Region.US_EAST_1) |
| 51 | + .credentialsProvider(CREDENTIALS_PROVIDER_CHAIN) |
| 52 | + .build(); |
| 53 | + |
| 54 | + DescribeSpotPriceHistoryPublisher publisher = ec2Client.describeSpotPriceHistoryPaginator(builder -> { |
| 55 | + builder.availabilityZone("us-east-1a") |
| 56 | + .productDescriptions("Linux/UNIX (Amazon VPC)") |
| 57 | + .instanceTypesWithStrings("t1.micro") |
| 58 | + .startTime(Instant.now().minusMillis(1)); |
| 59 | + }); |
| 60 | + |
| 61 | + publisher.subscribe(r -> assertThat(r.spotPriceHistory().size()).isEqualTo(1)) |
| 62 | + .join(); |
| 63 | + } |
| 64 | +} |
0 commit comments