Skip to content

Commit 120d062

Browse files
committed
Add longer retries for TracingE2ET and capability to pass custom retry config to RetryUtils.
1 parent 90218d7 commit 120d062

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/RetryUtils.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,21 @@ private RetryUtils() {
4747
*/
4848
@SafeVarargs
4949
public static Retry createRetry(String name, Class<? extends Throwable>... retryOnThrowables) {
50-
RetryConfig config = RetryConfig.from(DEFAULT_RETRY_CONFIG)
50+
return createRetry(name, DEFAULT_RETRY_CONFIG, retryOnThrowables);
51+
}
52+
53+
/**
54+
* Creates a retry instance with custom configuration for the specified throwable types.
55+
*
56+
* @param name the name for the retry instance
57+
* @param customConfig the custom retry configuration
58+
* @param retryOnThrowables the throwable classes to retry on
59+
* @return configured Retry instance
60+
*/
61+
@SafeVarargs
62+
public static Retry createRetry(String name, RetryConfig customConfig,
63+
Class<? extends Throwable>... retryOnThrowables) {
64+
RetryConfig config = RetryConfig.from(customConfig)
5165
.retryExceptions(retryOnThrowables)
5266
.build();
5367

@@ -72,4 +86,20 @@ public static <T> Supplier<T> withRetry(Supplier<T> supplier, String name,
7286
Retry retry = createRetry(name, retryOnThrowables);
7387
return Retry.decorateSupplier(retry, supplier);
7488
}
89+
90+
/**
91+
* Decorates a supplier with custom retry logic for the specified throwable types.
92+
*
93+
* @param supplier the supplier to decorate
94+
* @param name the name for the retry instance
95+
* @param customConfig the custom retry configuration
96+
* @param retryOnThrowables the throwable classes to retry on
97+
* @return decorated supplier with retry logic
98+
*/
99+
@SafeVarargs
100+
public static <T> Supplier<T> withRetry(Supplier<T> supplier, String name, RetryConfig customConfig,
101+
Class<? extends Throwable>... retryOnThrowables) {
102+
Retry retry = createRetry(name, customConfig, retryOnThrowables);
103+
return Retry.decorateSupplier(retry, supplier);
104+
}
75105
}

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/tracing/TraceFetcher.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package software.amazon.lambda.powertools.testutils.tracing;
1616

17+
import java.time.Duration;
1718
import java.time.Instant;
1819
import java.time.temporal.ChronoUnit;
1920
import java.util.Arrays;
@@ -31,6 +32,7 @@
3132
import com.fasterxml.jackson.databind.ObjectMapper;
3233
import com.fasterxml.jackson.databind.json.JsonMapper;
3334

35+
import io.github.resilience4j.retry.RetryConfig;
3436
import software.amazon.awssdk.http.SdkHttpClient;
3537
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
3638
import software.amazon.awssdk.regions.Region;
@@ -93,7 +95,12 @@ public Trace fetchTrace() {
9395
return getTrace(traceIds);
9496
};
9597

96-
return RetryUtils.withRetry(supplier, "trace-fetcher", TraceNotFoundException.class).get();
98+
RetryConfig customConfig = RetryConfig.custom()
99+
.maxAttempts(120) // 120 attempts over 10 minutes
100+
.waitDuration(Duration.ofSeconds(5)) // 5 seconds between attempts
101+
.build();
102+
103+
return RetryUtils.withRetry(supplier, "trace-fetcher", customConfig, TraceNotFoundException.class).get();
97104
}
98105

99106
/**

0 commit comments

Comments
 (0)