Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

MockitoPostProcessor should be disabled in AOT since not supported yet #1343

Closed
sdeleuze opened this issue Dec 6, 2021 · 5 comments
Closed
Assignees
Labels
type: bug A general bug
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 6, 2021

While working on #1084 updated to Spring Native 0.11.0-SNAPSHOT and following the same repro instructions with https://github.com/sdeleuze/spring-cloud-stream-event-routing-cloudevents, I see the following error during AOT code generation:

2021-12-06 08:23:22.861  INFO 20452 --- [           main] .b.t.c.SpringBootTestContextBootstrapper : Found @SpringBootConfiguration com.mycompany.producerservice.ProducerServiceApplication for test class com.mycompany.producerservice.kafka.news.NewsEventProducerTest
java.lang.IllegalArgumentException: Code should not be empty
	at org.springframework.aot.context.bootstrap.generator.bean.support.MultiCodeBlock.add(MultiCodeBlock.java:53)
	at org.springframework.aot.context.bootstrap.generator.bean.support.MultiCodeBlock.add(MultiCodeBlock.java:44)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.lambda$writeAll$10(ParameterWriter.java:174)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeAll(ParameterWriter.java:174)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:127)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:79)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:68)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.writeArgumentValue(DefaultBeanRegistrationWriter.java:258)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.handleArgumentValues(DefaultBeanRegistrationWriter.java:242)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.handleBeanDefinitionMetadata(DefaultBeanRegistrationWriter.java:222)

Any thoughts @snicoll ?

@sdeleuze sdeleuze added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 6, 2021
@snicoll
Copy link
Contributor

snicoll commented Dec 6, 2021

Yes. One parameter there is not supported, I'll have a look.

@snicoll
Copy link
Contributor

snicoll commented Dec 6, 2021

That's MockitoPostProcessor that contains a set of Definition and these are quite complex so I don't think it is reasonable to pre-process them at build time. I'll see what we can do.

@snicoll snicoll added theme: aot type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 6, 2021
@snicoll snicoll added this to the 0.11.0 milestone Dec 6, 2021
@snicoll snicoll self-assigned this Dec 6, 2021
@snicoll snicoll changed the title Code should not be empty error during AOT code generation MockitoPostProcessor should only be created at runtime Dec 6, 2021
@snicoll snicoll changed the title MockitoPostProcessor should only be created at runtime MockitoPostProcessor should only be created at build-time Dec 6, 2021
snicoll added a commit to snicoll/spring-native that referenced this issue Dec 6, 2021
@snicoll snicoll changed the title MockitoPostProcessor should only be created at build-time MockitoPostProcessor should be disabled in AOT as it is not supported with Native Dec 6, 2021
@snicoll
Copy link
Contributor

snicoll commented Dec 6, 2021

So I've managed to disable it but as we don't trigger any initializer at runtime anymore, the infrastructure is not created at all and it fails with:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.test.mock.mockito.MockitoPostProcessor' available

	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1172)
	at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.postProcessFields(MockitoTestExecutionListener.java:111)
	at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.injectFields(MockitoTestExecutionListener.java:94)
	at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.prepareTestInstance(MockitoTestExecutionListener.java:61)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248)
	at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$8(ClassBasedTestDescriptor.java:363)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:368)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$9(ClassBasedTestDescriptor.java:363)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)

Considering that mockito doesn't work in native, it would be nice to go a little further and skip the whole infrastructure but no injection would be equally confusing as this stacktrace IMO.

@snicoll snicoll modified the milestones: 0.11.0, Backlog Dec 6, 2021
@snicoll snicoll removed their assignment Dec 6, 2021
@sdeleuze
Copy link
Contributor Author

Can be reproduced via https://github.com/ddn4/spring-stocks with ./mvnw -pl :market-service clean package -Pnative -Dspring.aot.debug=true.

@sdeleuze sdeleuze modified the milestones: Backlog, 0.11.1 Dec 13, 2021
@sdeleuze sdeleuze self-assigned this Dec 13, 2021
@sdeleuze sdeleuze changed the title MockitoPostProcessor should be disabled in AOT as it is not supported with Native MockitoPostProcessor should be disabled in AOT since not supported yet Dec 20, 2021
@sdeleuze
Copy link
Contributor Author

Meaningful error messages are now provided when @MockBean or @SpyBean are used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

2 participants