-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Support bean override features with AOT and native image #32933
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
sbrannen
added
in: test
Issues in the test module
type: enhancement
A general enhancement
labels
Jun 1, 2024
snicoll
added
the
status: blocked
An issue that's blocked on an external project change
label
Jun 1, 2024
snicoll
changed the title
Support bean override features in a GraalVM native image in the TCF
Support bean override features with AOT
Jun 1, 2024
This comment was marked as outdated.
This comment was marked as outdated.
snicoll
removed
the
status: blocked
An issue that's blocked on an external project change
label
Jun 11, 2024
sbrannen
added a commit
that referenced
this issue
Sep 16, 2024
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Sep 16, 2024
Prior to this commit, AOT processing failed for tests that made use of test bean override features, since the Set<OverrideMetadata> constructor argument configured in the bean definition for the BeanOverrideBeanFactoryPostProcessor could not be handled by our AOT support. To address that, this commit registers test bean override infrastructure beans as singletons instead of via bean definitions with the infrastructure role. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Sep 16, 2024
Prior to this commit, test bean overrides were always created programmatically and registered as singletons in the bean factory, alongside "dummy" bean definitions; however, that can lead to issues during AOT processing and in the AOT runtime, especially for Mockito based mocks and spies since the "dummy" bean definitions are not real bean definitions that can be used to create a bean instance in the bean factory. To address that, this commit introduces a new updateOverrideBeanDefinition(BeanDefinition) method in the OverrideMetadata SPI that allows a concrete OverrideMetadata implementation to update the BeanDefinition so that it is suitable for use in AOT -- for example, by registering a static factory method that is responsible for creating the bean instance. This commit updates TestBeanOverrideMetadata and DummyOverrideMetadata in order to verify that this approach could potentially work for @TestBean and custom bean override implementations. However, this commit does not attempt to convert the @MockitoBean or @MockitoSpyBean support to use this approach. In other words, this commit serves merely as a proof of concept for an approach that we could consider. See spring-projectsgh-32933
This comment was marked as outdated.
This comment was marked as outdated.
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Sep 17, 2024
This commit introduces a BeanOverrideReflectiveProcessor which registers runtime hints for any BeanOverrideProcessor configured via @BeanOverride. See spring-projectsgh-32933
This comment was marked as outdated.
This comment was marked as outdated.
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Sep 24, 2024
This commit introduces a BeanOverrideReflectiveProcessor which registers runtime hints for any BeanOverrideProcessor configured via @BeanOverride. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Sep 24, 2024
But create new bean definition for nonexistent bean definitions based on BeanOverrideFactoryBean. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 1, 2024
- Register BeanOverrideBeanFactoryPostProcessor as a manual singleton. - Create new bean definition for nonexistent bean definitions based on BeanOverrideFactoryBean. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 1, 2024
This commit introduces a BeanOverrideReflectiveProcessor which registers runtime hints for any BeanOverrideProcessor configured via @BeanOverride. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 1, 2024
Instead, MockitoResetTestExecutionListener is now only enabled if the current test class uses Mockito annotations or Mockito-related annotations in spring-test. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 7, 2024
Prior to this commit, AOT processing failed for tests that made use of the Bean Override feature, since the Set<OverrideMetadata> constructor argument configured in the bean definition for the BeanOverrideBeanFactoryPostProcessor cannot be properly processed by our AOT support. The reason is that each OverrideMetadata instance is effectively an arbitrary object graph that cannot be automatically converted to a functional bean definition for use at AOT runtime. To address that, this commit registers Bean Override infrastructure beans as manual singletons instead of via bean definitions with the infrastructure role. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 7, 2024
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 7, 2024
This commit introduces a BeanOverrideReflectiveProcessor which registers runtime hints for any BeanOverrideProcessor configured via @BeanOverride. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 7, 2024
Instead, MockitoResetTestExecutionListener is now only enabled if the current test class uses Mockito annotations or Mockito-related annotations in spring-test. See spring-projectsgh-32933
sbrannen
added a commit
to sbrannen/spring-framework
that referenced
this issue
Oct 8, 2024
sbrannen
changed the title
Support bean override features with AOT
Support bean override features with AOT and native image
Oct 8, 2024
sbrannen
added a commit
that referenced
this issue
Oct 8, 2024
Prior to this commit, AOT processing failed for tests that made use of the Bean Override feature, since the Set<OverrideMetadata> constructor argument configured in the bean definition for the BeanOverrideBeanFactoryPostProcessor cannot be properly processed by our AOT support. The reason is that each OverrideMetadata instance is effectively an arbitrary object graph that cannot be automatically converted to a functional bean definition for use at AOT runtime. To address that, this commit registers Bean Override infrastructure beans as manual singletons instead of via bean definitions with the infrastructure role. See gh-32933
sbrannen
added a commit
that referenced
this issue
Oct 8, 2024
Prior to this commit, AOT processing failed for tests that made use of the Bean Override feature to "override" a nonexistent bean. The reason is that we register a "pseudo" bean definition as a placeholder for a nonexistent bean, and our AOT support cannot automatically convert that "pseudo" bean definition to a functional bean definition for use at AOT runtime. To address that, this commit skips registration of "pseudo" bean definitions during AOT processing, and by doing so we enable the JVM runtime and AOT runtime to operate with the same semantics. See gh-32933
sbrannen
added a commit
that referenced
this issue
Oct 8, 2024
This commit introduces a BeanOverrideReflectiveProcessor which registers runtime hints for any BeanOverrideProcessor configured via @BeanOverride. See gh-32933
sbrannen
added a commit
that referenced
this issue
Oct 8, 2024
sbrannen
added a commit
that referenced
this issue
Oct 8, 2024
Instead, MockitoResetTestExecutionListener is now only enabled if the current test class uses Mockito annotations or Mockito-related annotations in spring-test. See gh-32933
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
Overview
Although
@MockitoBean
and@MockitoSpyBean
will not work out-of-the-box within a GraalVM native image due to their dependency on Mockito, the general Bean Override support for tests should ideally work within a native image.In light of that, we need to ensure that basic usage of
@TestBean
is supported within a native image, and (if applicable) we will need to document known use cases that are not supported for some reason.To achieve that, we need to introduce a smoke test application that makes use of
@TestBean
and verify the expected behavior when the associated tests are run within a native image against Spring Framework 6.2 snapshots or milestones.We also have to ensure that the necessary runtime hints are registered for the bean override support. For example, we will need tests which verify that reflection hints are registered for the
BeanOverrideContextCustomizerFactory
, etc.As a bare minimum,
TestContextAotGeneratorIntegrationTests.endToEndTests()
must be modified to include test classes that utilize the basic features of@TestBean
.Related Issues
spring-test
module #29122@TestBean
and@MockitoBean
tests fail in AOT mode #32925The text was updated successfully, but these errors were encountered: