zonkyio / embedded-database-spring-test

A library for creating isolated embedded databases for Spring-powered integration tests.
Apache License 2.0
412 stars 37 forks source link

Tests using @FlywayTest(locationsForMigrate) failing after changing spring and flyway versions #255

Closed MateusTymoniuk closed 10 months ago

MateusTymoniuk commented 10 months ago

Hi!

We've been using zonky to test our repositories and it's been great! Our application uses springboot version 2.7.10, embedded-database-spring-test version 2.4.0 and flyway-core version 7.0.4.

Lately we've started to upgrade to springboot version 3.1.6, and with this, we needed to upgrade the flyway-core lib as well to version 9.22.3. With this update, our tests started to fail, because they couldn't initialize the application, as the following exception was thrown:

java.lang.NullPointerException: Cannot invoke "org.flywaydb.core.api.ResourceProvider.getResources(String, String[])" because "resourceProvider" is null

    at org.flywaydb.core.api.migration.baseline.BaselineMigrationResolver.addMigrations(BaselineMigrationResolver.java:77)
    at org.flywaydb.core.api.migration.baseline.BaselineMigrationResolver.resolveMigrations(BaselineMigrationResolver.java:53)
    at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.lambda$collectMigrations$0(CompositeMigrationResolver.java:127)
    at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:128)
    at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:117)
    at org.flywaydb.core.internal.resolver.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:107)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:285)
    at io.zonky.test.db.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:75)
    at io.zonky.test.db.flyway.FlywayWrapper.getMigrations(FlywayWrapper.java:99)
    at io.zonky.test.db.flyway.FlywayDatabaseExtension.lambda$resolveMigrations$6(FlywayDatabaseExtension.java:349)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
    at io.zonky.test.db.flyway.FlywayDatabaseExtension.resolveMigrations(FlywayDatabaseExtension.java:349)
    at io.zonky.test.db.flyway.FlywayDatabaseExtension.findFirstVersion(FlywayDatabaseExtension.java:327)
    at io.zonky.test.db.flyway.FlywayDatabaseExtension.isAppendable(FlywayDatabaseExtension.java:310)
    at io.zonky.test.db.flyway.FlywayDatabaseExtension.isAppendable(FlywayDatabaseExtension.java:293)
    at io.zonky.test.db.flyway.FlywayDatabaseExtension.processPendingOperations(FlywayDatabaseExtension.java:127)
    at io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener.processPendingFlywayOperations(OptimizedFlywayTestExecutionListener.java:108)
    at io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener.beforeTestClass(OptimizedFlywayTestExecutionListener.java:60)
    at org.springframework.test.context.TestContextManager.beforeTestClass(TestContextManager.java:220)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

This seems to be caused because I use a different path for some test migrations, so my test class includes the @FlywayTest(locationsForMigrate = "testdata") annotation, and once it tries to get and execute those migrations, the context that FlywayWrapper passes to BaselineMigrationResolver is null.

Can you help me find out what the problem is? I wonder if there is any configuration that I'm missing to set, because I had to upgrade major versions for both springboot and flyway so this might be the case.

I've created a sample repository, where I could reproduce the error I was getting, so you can analyse and reproduce it as well.

Here's the link to the repo

Thanks in advance for your time!

tomix26 commented 10 months ago

Hi @MateusTymoniuk, thanks for reporting the issue and for the reproducer. I'll try to fix it as soon as possible.

tomix26 commented 10 months ago

The new version has been released, you can try it out.

MateusTymoniuk commented 10 months ago

Hey @tomix26, thanks a lot for the fix! I changed all my tests back using @FlywayTest. Works like a charm now!