-
Notifications
You must be signed in to change notification settings - Fork 1k
test(warmup): Add warm-up tests that auto-cover the generated provider of every service module #7188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joviegas
merged 6 commits into
feature/master/crac_auto_priming_support
from
joviegas/warmup_all_module_tests
Jul 30, 2026
Merged
test(warmup): Add warm-up tests that auto-cover the generated provider of every service module #7188
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4778e7e
Add test to make sure all the SDK generated services have warmUp prov…
joviegas 822efb5
Merge branch 'feature/master/crac_auto_priming_support' into joviegas…
joviegas 9f74501
Handle review comments
joviegas 4330ff1
Add customization clients
joviegas ab1b00b
trigerring the codebuild test build to see if the codebuild time incr…
joviegas 8834fee
fork test per jvm
joviegas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
...-tests/src/test/java/software/amazon/awssdk/warmup/allservices/AllServicesWarmUpTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.warmup.allservices; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.ServiceLoader; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
| import java.util.stream.StreamSupport; | ||
| import org.apache.logging.log4j.Level; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Named; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import software.amazon.awssdk.core.SdkClient; | ||
| import software.amazon.awssdk.core.crac.SdkWarmUp; | ||
| import software.amazon.awssdk.core.crac.SdkWarmUpProvider; | ||
| import software.amazon.awssdk.testutils.LogCaptor; | ||
| import software.amazon.awssdk.utils.ClassLoaderHelper; | ||
|
|
||
| /** | ||
| * Warms every service on the classpath through the public API: {@link SdkWarmUp#prime(Class[])} per generated | ||
| * client, and {@link SdkWarmUp#prime()} for all of them at once. | ||
| */ | ||
| class AllServicesWarmUpTest { | ||
|
|
||
| private static final String SERVICES_PACKAGE_PREFIX = "software.amazon.awssdk.services."; | ||
|
|
||
| /** | ||
| * Services with no selectable warm-up operation (all operations are streaming or deprecated); warm-up only | ||
| * builds and closes the client. | ||
| */ | ||
| private static final Set<String> KNOWN_NO_OP_SERVICES = new HashSet<>(Arrays.asList( | ||
| // All APIs are deprecated | ||
| "cloudhsm", | ||
| "finspacedata", | ||
| "iotthingsgraph", | ||
| "lexmodelbuilding", | ||
| "proton", | ||
|
|
||
| // All streaming operations | ||
| "kinesisvideomedia", | ||
| "sagemakerruntimehttp2")); | ||
|
|
||
| /** | ||
| * Known warm-up failures. Document the reason per entry. | ||
| */ | ||
| private static final Set<String> KNOWN_WARMUP_FAILURE_SERVICES = new HashSet<>(Collections.singletonList( | ||
| // Endpoint rules require a real CloudFront ARN; the generated dummy ARN is rejected. | ||
| "cloudfrontkeyvaluestore")); | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| OperationRecordingInterceptor.reset(); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "{0}") | ||
| @MethodSource("generatedProviders") | ||
| void prime_syncClient_invokesOperationWithoutErrors(SdkWarmUpProvider provider) { | ||
| verifyWarmUp(provider, provider.syncClientClassName()); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "{0}") | ||
| @MethodSource("generatedProviders") | ||
| void prime_asyncClient_invokesOperationWithoutErrors(SdkWarmUpProvider provider) { | ||
| verifyWarmUp(provider, provider.asyncClientClassName()); | ||
| } | ||
|
|
||
| @Test | ||
| void prime_withAllServicesOnClasspath_noServiceProviderFails() { | ||
| String savedRegionProperty = System.getProperty("aws.region"); | ||
| System.setProperty("aws.region", "us-east-1"); | ||
| try (LogCaptor logCaptor = LogCaptor.create(Level.WARN)) { | ||
| SdkWarmUp.prime(); | ||
|
|
||
| assertThat(serviceWarmUpFailures(logCaptor)) | ||
| .as("SdkWarmUp.prime() must not log a warm-up failure for any generated service provider") | ||
| .isEmpty(); | ||
| } finally { | ||
| restoreRegionProperty(savedRegionProperty); | ||
| } | ||
|
|
||
| // prime() runs once per JVM; an empty recording means it already ran and this test verified nothing. | ||
| assertThat(OperationRecordingInterceptor.operationNames()) | ||
| .as("prime() must have invoked warm-up operations") | ||
| .isNotEmpty(); | ||
| } | ||
|
|
||
| private void verifyWarmUp(SdkWarmUpProvider provider, String clientClassName) { | ||
| assumeTrue(clientClassName != null, | ||
| () -> provider.getClass().getSimpleName() + " does not generate this client type"); | ||
| assumeTrue(!KNOWN_WARMUP_FAILURE_SERVICES.contains(serviceName(provider)), | ||
| () -> provider.getClass().getSimpleName() | ||
| + " is a known warm-up failure; see KNOWN_WARMUP_FAILURE_SERVICES"); | ||
|
|
||
| List<String> sdkWarnings; | ||
| try (LogCaptor logCaptor = LogCaptor.create(Level.WARN)) { | ||
| SdkWarmUp.prime(clientClass(clientClassName)); | ||
| sdkWarnings = sdkWarnings(logCaptor); | ||
| } | ||
|
|
||
| // prime(Class) logs warm-up failures at WARN instead of throwing. | ||
| assertThat(sdkWarnings) | ||
| .as("Warm-up of %s must not emit SDK warn/error logs", clientClassName) | ||
| .isEmpty(); | ||
| assertExpectedOperationRecorded(provider, clientClassName); | ||
| } | ||
|
|
||
| private void assertExpectedOperationRecorded(SdkWarmUpProvider provider, String clientClassName) { | ||
| if (KNOWN_NO_OP_SERVICES.contains(serviceName(provider))) { | ||
| assertThat(OperationRecordingInterceptor.operationNames()) | ||
| .as("%s is listed in KNOWN_NO_OP_SERVICES but recorded an operation; remove the stale entry", | ||
| provider.getClass().getSimpleName()) | ||
| .isEmpty(); | ||
| } else { | ||
| assertThat(OperationRecordingInterceptor.operationNames()) | ||
| .as("Warm-up of %s must invoke its selected warm-up operation", clientClassName) | ||
| .isNotEmpty(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * All generated service providers; excludes this module's hand-written test providers. | ||
| */ | ||
| static Stream<Named<SdkWarmUpProvider>> generatedProviders() { | ||
| return serviceProviders().map(p -> Named.of(p.getClass().getSimpleName(), p)); | ||
| } | ||
|
|
||
| private static Stream<SdkWarmUpProvider> serviceProviders() { | ||
| return StreamSupport.stream(ServiceLoader.load(SdkWarmUpProvider.class).spliterator(), false) | ||
| .filter(p -> p.getClass().getName().startsWith(SERVICES_PACKAGE_PREFIX)); | ||
| } | ||
|
|
||
| private static String serviceName(SdkWarmUpProvider provider) { | ||
| String remainder = provider.getClass().getName().substring(SERVICES_PACKAGE_PREFIX.length()); | ||
| return remainder.substring(0, remainder.indexOf('.')); | ||
| } | ||
|
|
||
| private static Class<? extends SdkClient> clientClass(String clientClassName) { | ||
| try { | ||
| return ClassLoaderHelper.loadClass(clientClassName, SdkWarmUp.class).asSubclass(SdkClient.class); | ||
| } catch (ClassNotFoundException e) { | ||
| throw new IllegalStateException("Client class not on classpath: " + clientClassName, e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Captured warnings from SDK loggers; warnings from the rest of the classpath are ignored. | ||
| */ | ||
| private static List<String> sdkWarnings(LogCaptor logCaptor) { | ||
| return logCaptor.loggedEvents().stream() | ||
| .filter(e -> e.getLoggerName().startsWith("software.amazon.awssdk")) | ||
| .map(e -> e.getLoggerName() + " - " + e.getMessage().getFormattedMessage()) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * Warm-up failures logged by {@code prime()}, excluding {@link #KNOWN_WARMUP_FAILURE_SERVICES}. prime() reports | ||
| * failures by client class name, so known failures are matched by their client names. | ||
| */ | ||
| private static List<String> serviceWarmUpFailures(LogCaptor logCaptor) { | ||
| Set<String> knownFailureClients = knownWarmUpFailureClients(); | ||
| return logCaptor.loggedEvents().stream() | ||
| .map(e -> e.getMessage().getFormattedMessage()) | ||
| .filter(msg -> msg.contains("software.amazon")) | ||
| .filter(msg -> knownFailureClients.stream().noneMatch(msg::contains)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private static Set<String> knownWarmUpFailureClients() { | ||
| return serviceProviders().filter(p -> KNOWN_WARMUP_FAILURE_SERVICES.contains(serviceName(p))) | ||
| .flatMap(p -> Stream.of(p.syncClientClassName(), p.asyncClientClassName())) | ||
| .filter(Objects::nonNull) | ||
| .collect(Collectors.toSet()); | ||
| } | ||
|
|
||
| private static void restoreRegionProperty(String savedValue) { | ||
| if (savedValue != null) { | ||
| System.setProperty("aws.region", savedValue); | ||
| } else { | ||
| System.clearProperty("aws.region"); | ||
| } | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
...rc/test/java/software/amazon/awssdk/warmup/allservices/OperationRecordingInterceptor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.warmup.allservices; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.CopyOnWriteArrayList; | ||
| import software.amazon.awssdk.core.interceptor.Context; | ||
| import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||
| import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; | ||
| import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute; | ||
|
|
||
| /** | ||
| * Records invoked operation names. Registered as a global interceptor via | ||
| * {@code software/amazon/awssdk/global/handlers/execution.interceptors} to observe clients built inside providers. | ||
| */ | ||
| public class OperationRecordingInterceptor implements ExecutionInterceptor { | ||
|
|
||
| private static final List<String> OPERATION_NAMES = new CopyOnWriteArrayList<>(); | ||
|
|
||
| public static List<String> operationNames() { | ||
| return OPERATION_NAMES; | ||
| } | ||
|
|
||
| public static void reset() { | ||
| OPERATION_NAMES.clear(); | ||
| } | ||
|
|
||
| @Override | ||
| public void beforeExecution(Context.BeforeExecution context, ExecutionAttributes executionAttributes) { | ||
| OPERATION_NAMES.add(executionAttributes.getAttribute(SdkExecutionAttribute.OPERATION_NAME)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). | ||
| # You may not use this file except in compliance with the License. | ||
| # A copy of the License is located at | ||
| # | ||
| # http://aws.amazon.com/apache2.0 | ||
| # | ||
| # or in the "license" file accompanying this file. This file is distributed | ||
| # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| # express or implied. See the License for the specific language governing | ||
| # permissions and limitations under the License. | ||
| # | ||
|
|
||
| status = warn | ||
|
|
||
| appender.console.type = Console | ||
| appender.console.name = ConsoleAppender | ||
| appender.console.layout.type = PatternLayout | ||
| appender.console.layout.pattern = %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n%throwable | ||
|
|
||
| # warn keeps CI output manageable while every generated provider warms up; | ||
| # LogCaptor adjusts the root level itself when capturing. | ||
| rootLogger.level = warn | ||
| rootLogger.appenderRef.stdout.ref = ConsoleAppender |
1 change: 1 addition & 0 deletions
1
...up-tests/src/test/resources/software/amazon/awssdk/global/handlers/execution.interceptors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| software.amazon.awssdk.warmup.allservices.OperationRecordingInterceptor |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: any reason we want to run tests for all services? How long does it take to run all tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we run all services because the warm-up operation is selected per service from each service's model; only executing every generated provider proves each one works. The full module runs offline (Canned Req/Response).
These test guard the customer path: a customer with all services on the classpath calls SdkWarmUp.prime(), and a broken provider logs a WARN and skips that service's warm-up. These tests turn that customer-visible WARN into a build failure here.
New services are covered automatically, the aggregate dependency picks up each new service, and the completeness test fails the build if a service ships without a registered provider
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will get the exact time once I merge the PR 7183. The issues mentioned in this PR were caught by these tests
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The building of all the modules without
mvn -T1Cmaven option takes 50 mins.The junits overall take 1 minute.
The overall codebuild takes 94m if executed as part of exsiting jdk Junit buildss(That was because a a failed build performed a retry)Thus I am planning to move this as a separate test similar to v2-migration-test and s3-regression test that can run parallely.
I tested this on codebuild with the below mvn command similar to v2-migration-test
This took 23.9 mins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, the earlier 94 mins was a confusion caused by the new way the builds are handled now. There was a retry of another build (the SonarCloud step), and that retry is what showed the increase.
I pushed a dummy commit, and this time the build passed with no retries and the time is the same as before.
So to answer your question: these tests do not add time to the JDK build. The service modules are already built at that point, and those already built modules are reused by the JUnit tests, which take a minute or less.
IMO we donot need a separate test build just for this .