Search in sources :

Example 1 with BackoffStrategy

use of software.amazon.awssdk.core.retry.backoff.BackoffStrategy in project aws-sdk-java-v2 by aws.

the class EcsWaiterTest method waitUntilServicesStableWorks.

@Test(timeout = 30_000)
@SuppressWarnings("unchecked")
public void waitUntilServicesStableWorks() {
    DescribeServicesRequest request = DescribeServicesRequest.builder().build();
    DescribeServicesResponse response1 = DescribeServicesResponse.builder().services(s -> s.deployments(Deployment.builder().build()).desiredCount(2).runningCount(1)).build();
    DescribeServicesResponse response2 = DescribeServicesResponse.builder().services(s -> s.deployments(Deployment.builder().build()).desiredCount(2).runningCount(2)).build();
    when(client.describeServices(any(DescribeServicesRequest.class))).thenReturn(response1, response2);
    EcsWaiter waiter = EcsWaiter.builder().overrideConfiguration(WaiterOverrideConfiguration.builder().maxAttempts(3).backoffStrategy(BackoffStrategy.none()).build()).client(client).build();
    WaiterResponse<DescribeServicesResponse> response = waiter.waitUntilServicesStable(request);
    assertThat(response.attemptsExecuted()).isEqualTo(2);
    assertThat(response.matched().response()).hasValueSatisfying(r -> assertThat(r).isEqualTo(response2));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Deployment(software.amazon.awssdk.services.ecs.model.Deployment) BackoffStrategy(software.amazon.awssdk.core.retry.backoff.BackoffStrategy) DescribeServicesRequest(software.amazon.awssdk.services.ecs.model.DescribeServicesRequest) EcsClient(software.amazon.awssdk.services.ecs.EcsClient) WaiterResponse(software.amazon.awssdk.core.waiters.WaiterResponse) WaiterOverrideConfiguration(software.amazon.awssdk.core.waiters.WaiterOverrideConfiguration) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) DescribeServicesResponse(software.amazon.awssdk.services.ecs.model.DescribeServicesResponse) DescribeServicesRequest(software.amazon.awssdk.services.ecs.model.DescribeServicesRequest) DescribeServicesResponse(software.amazon.awssdk.services.ecs.model.DescribeServicesResponse) Test(org.junit.Test)

Example 2 with BackoffStrategy

use of software.amazon.awssdk.core.retry.backoff.BackoffStrategy in project aws-sdk-java-v2 by aws.

the class DynamoDbRetryPolicyTest method test_backoffBaseDelay_with_standardRetryPolicy.

@Test
public void test_backoffBaseDelay_with_standardRetryPolicy() {
    environmentVariableHelper.set(SdkSystemSetting.AWS_RETRY_MODE.environmentVariable(), "standard");
    SdkClientConfiguration sdkClientConfiguration = SdkClientConfiguration.builder().build();
    RetryPolicy retryPolicy = DynamoDbRetryPolicy.resolveRetryPolicy(sdkClientConfiguration);
    BackoffStrategy backoffStrategy = retryPolicy.backoffStrategy();
    assertThat(backoffStrategy).isInstanceOfSatisfying(FullJitterBackoffStrategy.class, fjbs -> {
        assertThat(fjbs.toBuilder().baseDelay()).isEqualTo(Duration.ofMillis(25));
    });
}
Also used : SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) BackoffStrategy(software.amazon.awssdk.core.retry.backoff.BackoffStrategy) FullJitterBackoffStrategy(software.amazon.awssdk.core.retry.backoff.FullJitterBackoffStrategy) RetryPolicy(software.amazon.awssdk.core.retry.RetryPolicy) Test(org.junit.jupiter.api.Test)

Example 3 with BackoffStrategy

use of software.amazon.awssdk.core.retry.backoff.BackoffStrategy in project aws-sdk-java-v2 by aws.

the class DefaultQueryAsyncWaiter method postOperationSuccessWaiterConfig.

private static WaiterOverrideConfiguration postOperationSuccessWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
    Optional<WaiterOverrideConfiguration> optionalOverrideConfig = Optional.ofNullable(overrideConfig);
    int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(40);
    BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(FixedDelayBackoffStrategy.create(Duration.ofSeconds(1)));
    Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
    return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy).waitTimeout(waitTimeout).build();
}
Also used : BackoffStrategy(software.amazon.awssdk.core.retry.backoff.BackoffStrategy) FixedDelayBackoffStrategy(software.amazon.awssdk.core.retry.backoff.FixedDelayBackoffStrategy) Duration(java.time.Duration) WaiterOverrideConfiguration(software.amazon.awssdk.core.waiters.WaiterOverrideConfiguration)

Example 4 with BackoffStrategy

use of software.amazon.awssdk.core.retry.backoff.BackoffStrategy in project aws-sdk-java-v2 by aws.

the class DefaultQueryWaiter method postOperationSuccessWaiterConfig.

private static WaiterOverrideConfiguration postOperationSuccessWaiterConfig(WaiterOverrideConfiguration overrideConfig) {
    Optional<WaiterOverrideConfiguration> optionalOverrideConfig = Optional.ofNullable(overrideConfig);
    int maxAttempts = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::maxAttempts).orElse(40);
    BackoffStrategy backoffStrategy = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::backoffStrategy).orElse(FixedDelayBackoffStrategy.create(Duration.ofSeconds(1)));
    Duration waitTimeout = optionalOverrideConfig.flatMap(WaiterOverrideConfiguration::waitTimeout).orElse(null);
    return WaiterOverrideConfiguration.builder().maxAttempts(maxAttempts).backoffStrategy(backoffStrategy).waitTimeout(waitTimeout).build();
}
Also used : BackoffStrategy(software.amazon.awssdk.core.retry.backoff.BackoffStrategy) FixedDelayBackoffStrategy(software.amazon.awssdk.core.retry.backoff.FixedDelayBackoffStrategy) Duration(java.time.Duration) WaiterOverrideConfiguration(software.amazon.awssdk.core.waiters.WaiterOverrideConfiguration)

Example 5 with BackoffStrategy

use of software.amazon.awssdk.core.retry.backoff.BackoffStrategy in project aws-sdk-java-v2 by aws.

the class AutoScalingWaiterTest method waitUntilGroupInServiceWorks.

@Test(timeout = 30_000)
@SuppressWarnings("unchecked")
public void waitUntilGroupInServiceWorks() {
    DescribeAutoScalingGroupsRequest request = DescribeAutoScalingGroupsRequest.builder().build();
    DescribeAutoScalingGroupsResponse response1 = DescribeAutoScalingGroupsResponse.builder().autoScalingGroups(asg -> asg.minSize(2).instances(i -> i.lifecycleState(PENDING), i -> i.lifecycleState(IN_SERVICE), i -> i.lifecycleState(IN_SERVICE)), asg -> asg.minSize(2).instances(i -> i.lifecycleState(PENDING), i -> i.lifecycleState(PENDING), i -> i.lifecycleState(IN_SERVICE))).build();
    DescribeAutoScalingGroupsResponse response2 = DescribeAutoScalingGroupsResponse.builder().autoScalingGroups(asg -> asg.minSize(2).instances(i -> i.lifecycleState(PENDING), i -> i.lifecycleState(IN_SERVICE), i -> i.lifecycleState(IN_SERVICE)), asg -> asg.minSize(2).instances(i -> i.lifecycleState(IN_SERVICE), i -> i.lifecycleState(IN_SERVICE), i -> i.lifecycleState(IN_SERVICE))).build();
    when(client.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(response1, response2);
    AutoScalingWaiter waiter = AutoScalingWaiter.builder().overrideConfiguration(WaiterOverrideConfiguration.builder().maxAttempts(3).backoffStrategy(BackoffStrategy.none()).build()).client(client).build();
    WaiterResponse<DescribeAutoScalingGroupsResponse> response = waiter.waitUntilGroupInService(request);
    assertThat(response.attemptsExecuted()).isEqualTo(2);
    assertThat(response.matched().response()).hasValueSatisfying(r -> assertThat(r).isEqualTo(response2));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PENDING(software.amazon.awssdk.services.autoscaling.model.LifecycleState.PENDING) AutoScalingClient(software.amazon.awssdk.services.autoscaling.AutoScalingClient) IN_SERVICE(software.amazon.awssdk.services.autoscaling.model.LifecycleState.IN_SERVICE) DescribeAutoScalingGroupsRequest(software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsRequest) DescribeAutoScalingGroupsResponse(software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsResponse) BackoffStrategy(software.amazon.awssdk.core.retry.backoff.BackoffStrategy) WaiterResponse(software.amazon.awssdk.core.waiters.WaiterResponse) WaiterOverrideConfiguration(software.amazon.awssdk.core.waiters.WaiterOverrideConfiguration) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) DescribeAutoScalingGroupsRequest(software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsRequest) DescribeAutoScalingGroupsResponse(software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsResponse) Test(org.junit.Test)

Aggregations

BackoffStrategy (software.amazon.awssdk.core.retry.backoff.BackoffStrategy)5 WaiterOverrideConfiguration (software.amazon.awssdk.core.waiters.WaiterOverrideConfiguration)4 Duration (java.time.Duration)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.when (org.mockito.Mockito.when)2 FixedDelayBackoffStrategy (software.amazon.awssdk.core.retry.backoff.FixedDelayBackoffStrategy)2 WaiterResponse (software.amazon.awssdk.core.waiters.WaiterResponse)2 Test (org.junit.jupiter.api.Test)1 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)1 RetryPolicy (software.amazon.awssdk.core.retry.RetryPolicy)1 FullJitterBackoffStrategy (software.amazon.awssdk.core.retry.backoff.FullJitterBackoffStrategy)1 AutoScalingClient (software.amazon.awssdk.services.autoscaling.AutoScalingClient)1 DescribeAutoScalingGroupsRequest (software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResponse (software.amazon.awssdk.services.autoscaling.model.DescribeAutoScalingGroupsResponse)1 IN_SERVICE (software.amazon.awssdk.services.autoscaling.model.LifecycleState.IN_SERVICE)1 PENDING (software.amazon.awssdk.services.autoscaling.model.LifecycleState.PENDING)1