Skip to content
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

Add support for processing test contexts ahead-of-time #28204

Closed
snicoll opened this issue Mar 21, 2022 · 1 comment
Closed

Add support for processing test contexts ahead-of-time #28204

snicoll opened this issue Mar 21, 2022 · 1 comment
Assignees
Labels
in: test Issues in the test module theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Mar 21, 2022

Overview

Now that we can process an application context for AOT optimizations, we'd like to extend that feature by providing support in other parts of the portfolio. One that we have experimented with in Spring Native is processing the application contexts that the TCF uses for a module so that they are "native-friendly".

In practice, this would mean introducing something like TestContextAotProcessor that builds on top of ApplicationContextAotProcessor, pre-processing the test infrastructure for each context identified amongst a set of test classes.

We'd need at least one additional context to provide a "prepared" GenericApplicationContext for a MergedContextConfiguration as each "bootstrapper" can have its own logic baked in.

Related Issues

@snicoll snicoll added in: test Issues in the test module type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels Mar 21, 2022
@snicoll snicoll added this to the 6.0.0-M4 milestone Mar 21, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-M4, 6.0.0-M5 May 9, 2022
@sbrannen sbrannen self-assigned this Jun 7, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-M5, 6.0.0-M6 Jul 10, 2022
@sbrannen sbrannen changed the title Add support for processing test contexts Ahead-of-time Add support for processing test contexts ahead-of-time Jul 14, 2022
@sbrannen
Copy link
Member

sbrannen commented Aug 2, 2022

Current work on this feature can be viewed in the following feature branch.

As individual aspects of the feature set mature, I incorporate them into the main branch.

sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 22, 2022
This commit introduces TestContextAotGenerator for processing Spring
integration test classes and generating AOT artifacts. Specifically,
this class performs the following.

- bootstraps the TCF for a given test class
- builds the MergedContextConfiguration for each test class and tracks
  all test classes that share the same MergedContextConfiguration
- loads each test ApplicationContext without refreshing it
- passes the test ApplicationContext to ApplicationContextAotGenerator
  to generate the AOT optimized ApplicationContextInitializer
  - The GenerationContext passed to ApplicationContextAotGenerator uses
    a feature name of the form "TestContext###_", where "###" is a
    3-digit sequence ID left padded with zeros.

This commit also includes tests using the TestCompiler to verify that
each generated ApplicationContextInitializer can be used to populate a
GenericApplicationContext as expected.

See spring-projectsgh-28204
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 22, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 22, 2022
TestContextAotGenerator now uses AotTestMappingsCodeGenerator to
generate a AotTestMappings__Generated.java class which is loaded in
AotTestMappings via reflection in order to retrieve access to
ApplicationContextIntializers generated during AOT processing.

Furthermore, the processAheadOfTimeAndGenerateAotTestMappings() method
in TestContextAotGeneratorTests now performs a rather extensive test
including:

- emulating TestClassScanner to find test classes
- processing all test classes and generating ApplicationContextIntializers
- generating mappings for AotTestMappings
- compiling all generated code
- loading AotTestMappings
- using AotTestMappings to instantiate the generated ApplicationContextIntializers
- using AotRuntimeContextLoader to load the AOT-optimized ApplicationContext
- asserting the behavior of the loaded ApplicationContext

See spring-projectsgh-28205
Closes spring-projectsgh-28204
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 23, 2022
This commit introduces TestContextAotGenerator for processing Spring
integration test classes and generating AOT artifacts. Specifically,
this class performs the following.

- bootstraps the TCF for a given test class
- builds the MergedContextConfiguration for each test class and tracks
  all test classes that share the same MergedContextConfiguration
- loads each test ApplicationContext without refreshing it
- passes the test ApplicationContext to ApplicationContextAotGenerator
  to generate the AOT optimized ApplicationContextInitializer
  - The GenerationContext passed to ApplicationContextAotGenerator uses
    a feature name of the form "TestContext###_", where "###" is a
    3-digit sequence ID left padded with zeros.

This commit also includes tests using the TestCompiler to verify that
each generated ApplicationContextInitializer can be used to populate a
GenericApplicationContext as expected.

See spring-projectsgh-28204
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 23, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 23, 2022
TestContextAotGenerator now uses AotTestMappingsCodeGenerator to
generate a AotTestMappings__Generated.java class which is loaded in
AotTestMappings via reflection in order to retrieve access to
ApplicationContextIntializers generated during AOT processing.

Furthermore, the processAheadOfTimeAndGenerateAotTestMappings() method
in TestContextAotGeneratorTests now performs a rather extensive test
including:

- emulating TestClassScanner to find test classes
- processing all test classes and generating ApplicationContextIntializers
- generating mappings for AotTestMappings
- compiling all generated code
- loading AotTestMappings
- using AotTestMappings to instantiate the generated ApplicationContextIntializer
- using the AotContextLoader API to load the AOT-optimized ApplicationContext
- asserting the behavior of the loaded ApplicationContext

See spring-projectsgh-28205
Closes spring-projectsgh-28204
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 23, 2022
This commit introduces TestContextAotGenerator for processing Spring
integration test classes and generating AOT artifacts. Specifically,
this class performs the following.

- bootstraps the TCF for a given test class
- builds the MergedContextConfiguration for each test class and tracks
  all test classes that share the same MergedContextConfiguration
- loads each test ApplicationContext without refreshing it
- passes the test ApplicationContext to ApplicationContextAotGenerator
  to generate the AOT optimized ApplicationContextInitializer
  - The GenerationContext passed to ApplicationContextAotGenerator uses
    a feature name of the form "TestContext###_", where "###" is a
    3-digit sequence ID left padded with zeros.

This commit also includes tests using the TestCompiler to verify that
each generated ApplicationContextInitializer can be used to populate a
GenericApplicationContext as expected.

See spring-projectsgh-28204
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 23, 2022
sbrannen added a commit that referenced this issue Sep 13, 2022
- for consistency with AotTestAttributes and similar classes

See gh-28205, gh-28204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants