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 in the TCF to use pre-processed AOT contexts #28205

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

Add support in the TCF to use pre-processed AOT contexts #28205

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

Once we've done #28204, we need to be able to configure the TCF so that it uses our optimized context rather than doing all the parsing again. Given that our input is the test class, it would be interesting to see if we can shortcut most of the processing and go straight to starting (or reusing) the context.

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
@snicoll
Copy link
Member Author

snicoll commented Jun 2, 2022

Brainstorming with @jhoeller we believe that AotDetector should be used the same way as it is used when starting an application. When an app determines if it has to use AOT, it uses the detector and load a generated class by convention and use it to initialize the context. If such a class is not present, an exception is thrown.

For the TCF, it could use the AotDetector, check a generated class based on the current test class name and then do whatever. An example of such arrangement could be the following:

/**
 * Bootstrap for {@link MyTest}. Generated code, do not edit
 */
public class MyTest__TestContextInitializer {
	
	public static SmartContextLoader loadContext() {
		return new AotContextLoader(...);
	}
}

The class could also implement an interface or whatever. If multiple test classes share the same context, then the generated code for those test classes would delegate to a common generated class.

Such arrangement makes sure that the check is consistent (and 100% transparent when running tests in a native image).

@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 hook-point in the TCF to use pre-processed context Add hook-point in the TCF to use pre-processed AOT context Jul 14, 2022
@sbrannen sbrannen changed the title Add hook-point in the TCF to use pre-processed AOT context Add support in the TCF to use pre-processed AOT contexts Aug 22, 2022
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 22, 2022
This commit introduces initial AOT run-time support in the Spring
TestContext Framework.

- DefaultCacheAwareContextLoaderDelegate: when running in AOT mode, now
  loads a test's ApplicationContext using the AotRuntimeContextLoader
  instead of via the standard SmartContextLoader and ContextLoader SPIs.

- DependencyInjectionTestExecutionListener: when running in AOT mode,
  now injects dependencies into a test instance using a local instance
  of AutowiredAnnotationBeanPostProcessor instead of relying on
  AutowireCapableBeanFactory support.

Closes spring-projectsgh-28205
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 initial AOT run-time support in the Spring
TestContext Framework.

- DefaultCacheAwareContextLoaderDelegate: when running in AOT mode, now
  loads a test's ApplicationContext via the AotContextLoader SPI
  instead of via the standard SmartContextLoader and ContextLoader SPIs.

- DependencyInjectionTestExecutionListener: when running in AOT mode,
  now injects dependencies into a test instance using a local instance
  of AutowiredAnnotationBeanPostProcessor instead of relying on
  AutowireCapableBeanFactory support.

Closes spring-projectsgh-28205
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 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