zonkyio / embedded-database-spring-test

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

All data providers being required when only a specific one is specified #252

Closed dwi-mfbcs closed 9 months ago

dwi-mfbcs commented 9 months ago

I’m experiencing problem with running unit tests that involve spinning up an embedded database (postgres).

In this case, I specifies that I want to use specific provider (ZONKY).

@AutoConfigureEmbeddedDatabase(type = AutoConfigureEmbeddedDatabase.DatabaseType.POSTGRES, provider = ZONKY)
public class BaseComponentTest {
....
}

However it seems that it asks for all data providers being instantiated.

Example of error (in this case it asks for the opentable provider that I don’t ask):

Caused by: io.zonky.test.db.config.MissingProviderDependencyException: You have to add the following dependency to your project: 'com.opentable.components:otj-pg-embedded' (https://mvnrepository.com/artifact/com.opentable.components/otj-pg-embedded)

Version of libraries being used:

springframework 3.1.5
io.zonky.test:embedded-postgres:2.0.4
io.zonky.test:embedded-database-spring-test:2.3.0
io.zonky.test.postgres:embedded-postgres-binaries-bom:14.10.0

Am I missing something here? Looking for help with resolving this issue..

tomix26 commented 9 months ago

Please try the following steps:

dwi-mfbcs commented 9 months ago

Thanks @tomix26 - I have ensured the settings that you suggested. I even explicitly set the lazy initialization to true. Unfortunately, still experiencing the same issue. Is there any debugging that you can suggest?

tomix26 commented 9 months ago

I would suggest placing a breakpoint at the location where the exception is thrown. Then, examine the call stack and go through the methods where new Spring beans are being created (like in the doCreateBean method). This way, you can trace back to the bean that is forcing the initialization of all database providers, including those that shouldn't normally be initialized. It's likely related to a direct dependency on a database provider in your project or possibly a bean postprocessor that disrupts the lazy initialization of spring beans in general. However, I expect it should not be caused by any bean from the embedded database library.

dwi-mfbcs commented 9 months ago

Thank you @tomix26 - it turns out it's a subtle mistake on my part. I was referencing an internal library with a wrong version (0.0.1.13 instead of 0.1.13, duh..). My apology for causing trouble here.

tomix26 commented 9 months ago

Ok, thanks for letting me know.