software.amazon.awssdk.core.retry.RetryPolicy Java Examples

The following examples show how to use software.amazon.awssdk.core.retry.RetryPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsyncSqsClientFactory.java    From dynein with Apache License 2.0 7 votes vote down vote up
private SqsAsyncClient getAsyncSQSClient(AsyncSqsClientConfiguration config) {
  if (config.getType().equals(AsyncSqsClientConfiguration.Type.PRODUCTION)) {
    SqsAsyncClientBuilder builder =
        SqsAsyncClient.builder()
            .region(Region.of(config.getRegion()))
            .endpointOverride(config.getEndpoint());

    OverrideConfiguration overrideConfig = config.getOverrideConfiguration();

    if (overrideConfig != null) {

      RetryPolicy retry = buildRetryPolicy(overrideConfig.getRetryPolicyConfiguration());
      ClientOverrideConfiguration clientOverrideConfiguration =
          ClientOverrideConfiguration.builder()
              .apiCallAttemptTimeout(Duration.ofMillis(overrideConfig.getApiCallAttemptTimeout()))
              .apiCallTimeout(Duration.ofMillis(overrideConfig.getApiCallTimeout()))
              .retryPolicy(retry)
              .build();

      builder = builder.overrideConfiguration(clientOverrideConfiguration);
    }
    return builder.build();
  } else {
    throw new IllegalArgumentException("Doesn't support this Type " + config.getType());
  }
}
 
Example #2
Source File: AsyncApiCallAttemptsTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    client = ProtocolRestJsonAsyncClient.builder()
                                        .region(Region.US_WEST_1)
                                        .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                        .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                        .overrideConfiguration(b -> b.apiCallAttemptTimeout(Duration.ofMillis(API_CALL_ATTEMPT_TIMEOUT))
                                                                     .retryPolicy(RetryPolicy.none()))
                                        .build();

    clientWithRetry = ProtocolRestJsonAsyncClient.builder()
                                                 .region(Region.US_WEST_1)
                                                 .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                                 .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                                 .overrideConfiguration(b -> b.apiCallAttemptTimeout(Duration.ofMillis(API_CALL_ATTEMPT_TIMEOUT))
                                                                              .retryPolicy(RetryPolicy.builder()
                                                                                                      .numRetries(1)
                                                                                                      .build()))
                                                 .build();

}
 
Example #3
Source File: AwsDefaultClientBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private RetryPolicy resolveAwsRetryPolicy(SdkClientConfiguration config) {
    RetryPolicy policy = config.option(SdkClientOption.RETRY_POLICY);

    if (policy != null) {
        if (policy.additionalRetryConditionsAllowed()) {
            return AwsRetryPolicy.addRetryConditions(policy);
        } else {
            return policy;
        }
    }

    RetryMode retryMode = RetryMode.resolver()
                                   .profileFile(() -> config.option(SdkClientOption.PROFILE_FILE))
                                   .profileName(config.option(SdkClientOption.PROFILE_NAME))
                                   .resolve();
    return AwsRetryPolicy.forRetryMode(retryMode);
}
 
Example #4
Source File: AsyncApiCallTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    client = ProtocolRestJsonAsyncClient.builder()
                                        .region(Region.US_WEST_1)
                                        .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                        .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                        .overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMillis(TIMEOUT))
                                                                     .retryPolicy(RetryPolicy.none()))
                                        .build();

    clientWithRetry = ProtocolRestJsonAsyncClient.builder()
                                                 .region(Region.US_WEST_1)
                                                 .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                                 .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                                 .overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMillis(TIMEOUT))
                                                                              .retryPolicy(RetryPolicy.builder().numRetries(1).build()))
                                                 .build();
}
 
Example #5
Source File: SyncApiCallAttemptTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    client = ProtocolRestJsonClient.builder()
                                   .region(Region.US_WEST_1)
                                   .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                   .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                   .overrideConfiguration(
                                       b -> b.apiCallAttemptTimeout(Duration.ofMillis(API_CALL_ATTEMPT_TIMEOUT))
                                             .retryPolicy(RetryPolicy.none()))
                                   .build();

    clientWithRetry = ProtocolRestJsonClient.builder()
                                            .region(Region.US_WEST_1)
                                            .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                            .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                            .overrideConfiguration(
                                                b -> b.apiCallAttemptTimeout(Duration.ofMillis(API_CALL_ATTEMPT_TIMEOUT))
                                                      .retryPolicy(RetryPolicy.builder()
                                                                              .numRetries(1)
                                                                              .build()))
                                            .build();

}
 
Example #6
Source File: SyncApiCallTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    client = ProtocolRestJsonClient.builder()
                                   .region(Region.US_WEST_1)
                                   .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                   .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                   .overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMillis(TIMEOUT))
                                                                .retryPolicy(RetryPolicy.none()))
                                   .build();

    clientWithRetry = ProtocolRestJsonClient.builder()
                                            .region(Region.US_WEST_1)
                                            .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                            .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                            .overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMillis(TIMEOUT))
                                                                         .retryPolicy(RetryPolicy.builder().numRetries(1)
                                                                                                 .build()))
                                            .build();
}
 
Example #7
Source File: KinesisRetryPolicy.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
public static RetryPolicy resolveRetryPolicy(SdkClientConfiguration config) {
    RetryPolicy configuredRetryPolicy = config.option(SdkClientOption.RETRY_POLICY);
    if (configuredRetryPolicy != null) {
        return addRetryConditions(configuredRetryPolicy);
    }

    RetryMode retryMode = RetryMode.resolver()
                                   .profileFile(() -> config.option(SdkClientOption.PROFILE_FILE))
                                   .profileName(config.option(SdkClientOption.PROFILE_NAME))
                                   .resolve();
    return AwsRetryPolicy.forRetryMode(retryMode)
                         .toBuilder()
                         .applyMutation(KinesisRetryPolicy::addRetryConditions)
                         .additionalRetryConditionsAllowed(false)
                         .build();

}
 
Example #8
Source File: DynamoDbRetryPolicy.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
public static RetryPolicy resolveRetryPolicy(SdkClientConfiguration config) {
    RetryPolicy configuredRetryPolicy = config.option(SdkClientOption.RETRY_POLICY);
    if (configuredRetryPolicy != null) {
        return configuredRetryPolicy;
    }

    RetryMode retryMode = RetryMode.resolver()
                                   .profileFile(() -> config.option(SdkClientOption.PROFILE_FILE))
                                   .profileName(config.option(SdkClientOption.PROFILE_NAME))
                                   .resolve();

    if (retryMode != RetryMode.LEGACY) {
        return AwsRetryPolicy.forRetryMode(retryMode)
                             .toBuilder()
                             .additionalRetryConditionsAllowed(false)
                             .build();
    }

    return AwsRetryPolicy.forRetryMode(RetryMode.LEGACY)
                         .toBuilder()
                         .additionalRetryConditionsAllowed(false)
                         .numRetries(LEGACY_MAX_ERROR_RETRY)
                         .backoffStrategy(LEGACY_BACKOFF_STRATEGY)
                         .build();
}
 
Example #9
Source File: HttpTestUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public static SdkClientConfiguration testClientConfiguration() {
    return SdkClientConfiguration.builder()
                                 .option(SdkClientOption.EXECUTION_INTERCEPTORS, new ArrayList<>())
                                 .option(SdkClientOption.ENDPOINT, URI.create("http://localhost:8080"))
                                 .option(SdkClientOption.RETRY_POLICY, RetryPolicy.defaultRetryPolicy())
                                 .option(SdkClientOption.ADDITIONAL_HTTP_HEADERS, new HashMap<>())
                                 .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
                                 .option(SdkAdvancedClientOption.SIGNER, new NoOpSigner())
                                 .option(SdkAdvancedClientOption.USER_AGENT_PREFIX, "")
                                 .option(SdkAdvancedClientOption.USER_AGENT_SUFFIX, "")
                                 .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run)
                                 .option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE, Executors.newScheduledThreadPool(1))
                                 .build();
}
 
Example #10
Source File: AmazonHttpClientSslHandshakeTimeoutIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60 * 1000)
public void testSslHandshakeTimeout() {
    AmazonSyncHttpClient httpClient = HttpTestUtils.testClientBuilder()
                                                   .retryPolicy(RetryPolicy.none())
                                                   .httpClient(ApacheHttpClient.builder()
                                                                           .socketTimeout(CLIENT_SOCKET_TO)
                                                                           .build())
                                                   .build();

    System.out.println("Sending request to localhost...");

    try {
        SdkHttpFullRequest request = server.configureHttpsEndpoint(SdkHttpFullRequest.builder())
                                           .method(SdkHttpMethod.GET)
                                           .build();
        httpClient.requestExecutionBuilder()
                  .request(request)
                  .originalRequest(NoopTestRequest.builder().build())
                  .executionContext(executionContext(request))
                  .execute(combinedSyncResponseHandler(null, new NullErrorResponseHandler()));
        fail("Client-side socket read timeout is expected!");

    } catch (SdkClientException e) {
        /**
         * Http client catches the SocketTimeoutException and throws a
         * ConnectTimeoutException.
         * {@link DefaultHttpClientConnectionOperator#connect(ManagedHttpClientConnection, HttpHost,
         * InetSocketAddress, int, SocketConfig, HttpContext)}
         */
        Assert.assertTrue(e.getCause() instanceof ConnectTimeoutException);

        ConnectTimeoutException cte = (ConnectTimeoutException) e.getCause();
        Assert.assertThat(cte.getMessage(), org.hamcrest.Matchers
                .containsString("Read timed out"));
    }
}
 
Example #11
Source File: HttpTestUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public static SdkClientConfiguration testClientConfiguration() {
    return SdkClientConfiguration.builder()
                                 .option(SdkClientOption.EXECUTION_INTERCEPTORS, new ArrayList<>())
                                 .option(SdkClientOption.ENDPOINT, URI.create("http://localhost:8080"))
                                 .option(SdkClientOption.RETRY_POLICY, RetryPolicy.defaultRetryPolicy())
                                 .option(SdkClientOption.ADDITIONAL_HTTP_HEADERS, new HashMap<>())
                                 .option(SdkClientOption.CRC32_FROM_COMPRESSED_DATA_ENABLED, false)
                                 .option(SdkAdvancedClientOption.SIGNER, new NoOpSigner())
                                 .option(SdkAdvancedClientOption.USER_AGENT_PREFIX, "")
                                 .option(SdkAdvancedClientOption.USER_AGENT_SUFFIX, "")
                                 .option(SdkClientOption.SCHEDULED_EXECUTOR_SERVICE, Executors.newScheduledThreadPool(1))
                                 .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run)
                                 .build();
}
 
Example #12
Source File: RetryCountInUserAgentTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private void executeRequest(boolean throttlingEnabled) throws Exception {
    RetryPolicy policy = RetryPolicy.builder()
                                    .backoffStrategy(new SimpleArrayBackoffStrategy(BACKOFF_VALUES))
                                    .applyMutation(b -> {
                                        if (!throttlingEnabled) {
                                            b.retryCapacityCondition(null);
                                        }
                                    })
                                    .build();

    SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder()
                                                 .option(SdkClientOption.SYNC_HTTP_CLIENT, HttpTestUtils.testSdkHttpClient())
                                                 .option(SdkClientOption.RETRY_POLICY, policy)
                                                 .build();

    AmazonSyncHttpClient httpClient = new AmazonSyncHttpClient(config);
    try {
        SdkHttpFullRequest request = newGetRequest(RESOURCE_PATH).build();
        httpClient.requestExecutionBuilder()
                  .request(request)
                  .originalRequest(NoopTestRequest.builder().build())
                  .executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(request))
                  .execute(combinedSyncResponseHandler(null, stubErrorHandler()));
        fail("Expected exception");
    } catch (SdkServiceException expected) {
        // Ignored or expected.
    }
}
 
Example #13
Source File: AsyncClientHandlerExceptionTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void methodSetup() throws Exception {
    executionParams = new ClientExecutionParams<SdkRequest, SdkResponse>()
            .withInput(request)
            .withMarshaller(marshaller)
            .withResponseHandler(responseHandler)
            .withErrorResponseHandler(errorResponseHandler);

    SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder()
            .option(SdkClientOption.ASYNC_HTTP_CLIENT, asyncHttpClient)
            .option(SdkClientOption.RETRY_POLICY, RetryPolicy.none())
            .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run)
            .build();

    clientHandler = new SdkAsyncClientHandler(config);

    when(request.overrideConfiguration()).thenReturn(Optional.empty());

    when(marshaller.marshall(eq(request))).thenReturn(ValidSdkObjects.sdkHttpFullRequest().build());

    when(responseHandler.handle(any(SdkHttpFullResponse.class), any(ExecutionAttributes.class)))
            .thenReturn(VoidSdkResponse.builder().build());

    when(asyncHttpClient.execute(any(AsyncExecuteRequest.class))).thenAnswer((Answer<CompletableFuture<Void>>) invocationOnMock -> {
        SdkAsyncHttpResponseHandler handler = invocationOnMock.getArgumentAt(0, AsyncExecuteRequest.class).responseHandler();
        handler.onHeaders(SdkHttpFullResponse.builder()
                .statusCode(200)
                .build());
        handler.onStream(new EmptyPublisher<>());
        return CompletableFuture.completedFuture(null);
    });
}
 
Example #14
Source File: HttpClientApiCallAttemptTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    httpClient = testClientBuilder()
        .retryPolicy(RetryPolicy.none())
        .apiCallAttemptTimeout(API_CALL_TIMEOUT)
        .build();
}
 
Example #15
Source File: HttpClientApiCallTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    httpClient = testClientBuilder()
        .retryPolicy(RetryPolicy.none())
        .apiCallTimeout(API_CALL_TIMEOUT)
        .build();
}
 
Example #16
Source File: AsyncHttpClientApiCallTimeoutTests.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    httpClient = testAsyncClientBuilder()
        .retryPolicy(RetryPolicy.none())
        .apiCallTimeout(API_CALL_TIMEOUT)
        .build();
}
 
Example #17
Source File: ITTracingExecutionInterceptor.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override protected DynamoDbClient newClient(int port) throws IOException {
  ClientOverrideConfiguration configuration = ClientOverrideConfiguration.builder()
      .retryPolicy(RetryPolicy.builder().numRetries(3).build())
      .apiCallTimeout(Duration.ofSeconds(1))
      .addExecutionInterceptor(AwsSdkTracing.create(httpTracing).executionInterceptor())
      .build();

  return client = DynamoDbClient.builder()
      .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x")))
      .httpClient(primeHttpClient())
      .region(Region.US_EAST_1)
      .overrideConfiguration(configuration)
      .endpointOverride(URI.create("http://127.0.0.1:" + port))
      .build();
}
 
Example #18
Source File: SqsAutoConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(SqsAsyncClient.class)
public SqsAsyncClient sqsAsyncClient(final AwsCredentialsProvider credentialsProvider, final RetryPolicy sqsRetryPolicy) {
    return SqsAsyncClient.builder()
            .credentialsProvider(credentialsProvider)
            .region(Region.of(awsProperties.getRegion()))
            .overrideConfiguration(ClientOverrideConfiguration.builder()
                    .apiCallAttemptTimeout(Duration.ofSeconds(5))
                    .retryPolicy(sqsRetryPolicy).build())
            .build();
}
 
Example #19
Source File: ConnectionPoolMaxConnectionsIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60 * 1000)
public void leasing_a_new_connection_fails_with_connection_pool_timeout() {

    AmazonSyncHttpClient httpClient = HttpTestUtils.testClientBuilder()
                                                   .retryPolicy(RetryPolicy.none())
                                                   .httpClient(ApacheHttpClient.builder()
                                                                               .connectionTimeout(Duration.ofMillis(100))
                                                                               .maxConnections(1)
                                                                               .build())
                                                   .build();

    SdkHttpFullRequest request = server.configureHttpEndpoint(SdkHttpFullRequest.builder())
                                       .method(SdkHttpMethod.GET)
                                       .build();

    // Block the first connection in the pool with this request.
    httpClient.requestExecutionBuilder()
              .request(request)
              .originalRequest(NoopTestRequest.builder().build())
              .executionContext(executionContext(request))
              .execute(combinedSyncResponseHandler(new EmptySdkResponseHandler(), null));

    try {
        // A new connection will be leased here which would fail in
        // ConnectionPoolTimeoutException.
        httpClient.requestExecutionBuilder()
                  .request(request)
                  .originalRequest(NoopTestRequest.builder().build())
                  .executionContext(executionContext(request))
                  .execute(combinedSyncResponseHandler(null, null));
        Assert.fail("Connection pool timeout exception is expected!");
    } catch (SdkClientException e) {
        Assert.assertTrue(e.getCause() instanceof ConnectionPoolTimeoutException);
    }
}
 
Example #20
Source File: SqsAutoConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(name = "sqsRetryPolicy", value = RetryPolicy.class)
public RetryPolicy sqsRetryPolicy() {
    return RetryPolicy.defaultRetryPolicy().toBuilder()
            .retryCondition(defaultRetryCondition())
            .numRetries(Integer.MAX_VALUE)
            .backoffStrategy(FullJitterBackoffStrategy.builder()
                    .baseDelay(Duration.ofSeconds(1))
                    .maxBackoffTime(SdkDefaultRetrySetting.MAX_BACKOFF)
                    .build())
            .build();
}
 
Example #21
Source File: KinesisAutoConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(name = "kinesisRetryPolicy", value = RetryPolicy.class)
public RetryPolicy kinesisRetryPolicy() {
    return RetryPolicy.defaultRetryPolicy().toBuilder()
            .retryCondition(new DefaultLoggingRetryCondition(5, 10))
            .numRetries(Integer.MAX_VALUE)
            .backoffStrategy(FullJitterBackoffStrategy.builder()
                    .baseDelay(Duration.ofSeconds(1))
                    .maxBackoffTime(SdkDefaultRetrySetting.MAX_BACKOFF)
                    .build())
            .build();
}
 
Example #22
Source File: KinesisTestConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
public KinesisAsyncClient kinesisAsyncClient(final @Value("${test.environment:local}") String testEnvironment,
                                             final AwsCredentialsProvider credentialsProvider,
                                             final RetryPolicy kinesisRetryPolicy) {
    // kinesalite does not support cbor at the moment (v1.11.6)
    System.setProperty("aws.cborEnabled", "false");
    LOG.info("kinesis client for local tests");
    final KinesisAsyncClient kinesisClient;
    if (testEnvironment.equals("local")) {
        kinesisClient = KinesisAsyncClient.builder()
                .httpClient(
                        // Disables HTTP2 because of problems with LocalStack
                        NettyNioAsyncHttpClient.builder()
                                .protocol(Protocol.HTTP1_1)
                                .build())
                .endpointOverride(URI.create("http://localhost:4568"))
                .region(Region.EU_CENTRAL_1)
                .credentialsProvider(credentialsProvider)
                .overrideConfiguration(ClientOverrideConfiguration.builder().retryPolicy(kinesisRetryPolicy).build())
                .build();
    } else {
        kinesisClient = KinesisAsyncClient.builder()
                .credentialsProvider(credentialsProvider)
                .build();
    }
    createChannelIfNotExists(kinesisClient, KINESIS_INTEGRATION_TEST_CHANNEL, EXPECTED_NUMBER_OF_SHARDS);
    return kinesisClient;
}
 
Example #23
Source File: KinesisAutoConfigurationTest.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRegisterRetryPolicyWithMaxRetries() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(KinesisAutoConfiguration.class);
    context.refresh();

    assertThat(context.containsBean("kinesisRetryPolicy"), is(true));
    RetryPolicy retryPolicy = context.getBean("kinesisRetryPolicy", RetryPolicy.class);
    assertThat(retryPolicy.numRetries(), is(Integer.MAX_VALUE));
}
 
Example #24
Source File: KinesisAutoConfiguration.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(KinesisAsyncClient.class)
public KinesisAsyncClient kinesisAsyncClient(final AwsCredentialsProvider credentialsProvider,
                                             final RetryPolicy kinesisRetryPolicy) {
    return KinesisAsyncClient.builder()
            .credentialsProvider(credentialsProvider)
            .region(Region.of(awsProperties.getRegion()))
            .overrideConfiguration(ClientOverrideConfiguration.builder().retryPolicy(kinesisRetryPolicy).build())
            .build();
}
 
Example #25
Source File: SdkDefaultClientBuilder.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private RetryPolicy resolveRetryPolicy(SdkClientConfiguration config) {
    RetryPolicy policy = config.option(SdkClientOption.RETRY_POLICY);
    if (policy != null) {
        return policy;
    }

    RetryMode retryMode = RetryMode.resolver()
                                   .profileFile(() -> config.option(SdkClientOption.PROFILE_FILE))
                                   .profileName(config.option(SdkClientOption.PROFILE_NAME))
                                   .resolve();
    return RetryPolicy.forRetryMode(retryMode);
}
 
Example #26
Source File: KinesisRetryPolicy.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public static RetryPolicy addRetryConditions(RetryPolicy policy) {
    if (!policy.additionalRetryConditionsAllowed()) {
        return policy;
    }

    return policy.toBuilder()
                 .applyMutation(KinesisRetryPolicy::addRetryConditions)
                 .build();
}
 
Example #27
Source File: ServiceIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    iam = IamClient.builder()
                   .credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
                   .overrideConfiguration(c -> c.retryPolicy(RetryPolicy.builder().numRetries(50).build()))
                   .region(Region.AWS_GLOBAL)
                   .build();
}
 
Example #28
Source File: SyncTimeoutTests.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    client = ProtocolRestJsonClient.builder()
                                   .region(Region.US_WEST_1)
                                   .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                                   .credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"))
                                   .overrideConfiguration(
                                       b -> b.apiCallTimeout(Duration.ofMillis(API_CALL_TIMEOUT))
                                             .apiCallAttemptTimeout(Duration.ofMillis(API_CALL_ATTEMPT_TIMEOUT))
                                             .retryPolicy(RetryPolicy.none()))
                                   .build();
}
 
Example #29
Source File: SyncStreamingOperationApiCallTimeoutTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
ClientOverrideConfiguration clientOverrideConfiguration() {
    return ClientOverrideConfiguration.builder()
                                      .apiCallTimeout(Duration.ofMillis(TIMEOUT))
                                      .retryPolicy(RetryPolicy.none())
                                      .build();
}
 
Example #30
Source File: AwsJsonRetryTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void retryPolicyNone_shouldNotRetry() {
    stubFor(post(urlEqualTo(PATH))
                .inScenario("retry at 500")
                .whenScenarioStateIs(Scenario.STARTED)
                .willSetStateTo("first attempt")
                .willReturn(aResponse()
                                .withStatus(500)));

    stubFor(post(urlEqualTo(PATH))
                .inScenario("retry at 500")
                .whenScenarioStateIs("first attempt")
                .willSetStateTo("second attempt")
                .willReturn(aResponse()
                                .withStatus(200)
                                .withBody(JSON_BODY)));

    ProtocolJsonRpcClient clientWithNoRetry =
        ProtocolJsonRpcClient.builder()
                             .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid",
                                                                                                              "skid")))
                             .region(Region.US_EAST_1)
                             .endpointOverride(URI.create("http://localhost:" + wireMock.port()))
                             .overrideConfiguration(c -> c.retryPolicy(RetryPolicy.none()))
                             .build();

    assertThatThrownBy(() -> clientWithNoRetry.allTypes(AllTypesRequest.builder().build())).isInstanceOf(ProtocolJsonRpcException.class);
}