spring-projects/spring-data-commons

Spring Data AOT Repositories failed in the AOT processed Spring Boot tests with multiple contexts being involved

Closed this issue · 2 comments

This issue originates from this Spring Boot ticket. Stéphane stated that this issue should be re-opened here, so I did.

The full story behind the question can be read in the original ticket, but the idea is that when in Spring Boot tests we have multiple versions of cached contexts being build, then AOT generation engine fails with exception:

Caused by: java.lang.IllegalStateException: /home/user/OpenSource/spring-petclinic/target/spring-aot/test/sources/org/springframework/samples/petclinic/owner/OwnerRepositoryImpl__Aot.java already exists
	at org.springframework.aot.generate.GeneratedFiles$FileHandler.create(GeneratedFiles.java:279)
	at org.springframework.aot.generate.GeneratedFiles.lambda$addFile$1(GeneratedFiles.java:170)

We concluded, that this is probably because for each test context, the engine tries to re-generate the Spring Data AOT repositories fragments.

Small addition: I tend to believe the conclusion, since when I've ensured that only one test context is created in Spring PetClinic, then AOT generation goes just fine (including AOT Repositories). Here is the branch in Spring PetClinic's fork that've used for this small testing purposes.

I'm willing to contribute, if core team would allow.

CC: @odrotbohm @mp911de

Thank you @mipo256 for the report & reproducer. Give us a little time to see which way we want to go to solve this issue.

@mipo256 there's a first draft (#3345) for a temporary fix. Due to the proximity to the next milestone we decided to create a follow up ticket to further decouple the code generation. Testing with the provided reproducer the generated aot repositories will be OwnerRepositoryImpl__AotRepository respectively OwnerRepositoryImpl__TestContext001_AotRepository, etc. However the tests failed due to an SQL parsing/enhancing issue when using FOR UPDATE OF ... along with Sort. Maybe switch to the JSQLParser, just in case you want to give the snapshots a try.