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

Document that testing with ApplicationContextRunner in a native image is not supported #34007

Closed
ruben-garciapariente opened this issue Jan 30, 2023 · 1 comment
Labels
theme: aot An issue related to Ahead-of-time processing type: documentation A documentation update
Milestone

Comments

@ruben-garciapariente
Copy link

Hello,

I am using Spring Boot 3.0.2. I have tried to compile natively with mvn -PnativeTest clean test a test that uses the class ApplicationContextRunner. Without adding any 'RuntimeHints' it returns me the following error:

Failures (1):
  JUnit Jupiter:ContextRunnerTests:testContextRunner()
    MethodSource [className = 'com.example.errorcontextrunner.ContextRunnerTests', methodName = 'testContextRunner', methodParameterTypes = '']
    => com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.springframework.context.ConfigurableApplicationContext, interface org.springframework.boot.test.context.assertj.AssertableApplicationContext] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options.
       org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
       org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.proxy.DynamicProxySupport.getProxyClass(DynamicProxySupport.java:171)
       [email protected]/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:47)
       [email protected]/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037)
       org.springframework.boot.test.context.assertj.ApplicationContextAssertProvider.get(ApplicationContextAssertProvider.java:112)
       org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.createAssertableContext(AbstractApplicationContextRunner.java:389)
       org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.consumeAssertableContext(AbstractApplicationContextRunner.java:362)
       org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.lambda$run$0(AbstractApplicationContextRunner.java:341)
       org.springframework.boot.test.util.TestPropertyValues.lambda$applyToSystemProperties$1(TestPropertyValues.java:174)
       org.springframework.boot.test.util.TestPropertyValues.applyToSystemProperties(TestPropertyValues.java:188)
       [...]

It can be replicated using the following example https://github.com/ruben-garciapariente/error-context-runner-native

If I add the "RuntimeHints" for the application configuration class it returns the following error (example at https://github.com/ruben-garciapariente/error-context-runner-native/tree/2e07cbca3b716fc871c663593b0f326b5aabdf3a):

Failures (1):
  JUnit Jupiter:ContextRunnerTests:testContextRunner()
    MethodSource [className = 'com.example.errorcontextrunner.ContextRunnerTests', methodName = 'notWeb', methodParameterTypes = '']
    => java.lang.IllegalStateException: Unable to read meta-data for class com.example.errorcontextrunner.AutoConfig
       org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationMetadata(AutoConfigurationSorter.java:237)
       org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationValue(AutoConfigurationSorter.java:219)
       org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAfter(AutoConfigurationSorter.java:198)
       org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClasses.getClassesRequestedAfter(AutoConfigurationSorter.java:143)
       org.springframework.boot.autoconfigure.AutoConfigurationSorter.doSortByAfterAnnotation(AutoConfigurationSorter.java:90)
       [...]
     Caused by: java.io.FileNotFoundException: class path resource [com/example/errorcontextrunner/AutoConfig.class] cannot be opened because it does not exist
       org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211)
       org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:54)
       org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:48)
       org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
       org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)
       [...]

Apparently there is no support for native compilation of an ApplicationContextRunner test. I have reviewed the following documentation and I have not found that it is indicated that it is not supported:

Thank you very much

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 30, 2023
@wilkinsona wilkinsona changed the title Error compiling natively a test with ApplicationContextRunner Document that testing with ApplicationContextRunner in a native image is not supported Jan 30, 2023
@wilkinsona
Copy link
Member

Thanks for raising this.

Apparently there is no support for native compilation of an ApplicationContextRunner test

That's correct. There are no hooks for performing AOT processing of the context created by the runner. We'll update the documentation to reflect this limitation.

@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 30, 2023
@wilkinsona wilkinsona added this to the 3.0.x milestone Jan 30, 2023
@mhalbritter mhalbritter added the theme: aot An issue related to Ahead-of-time processing label Oct 27, 2023
@mhalbritter mhalbritter modified the milestones: 3.0.x, 3.0.13 Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

4 participants