dadrus / jpa-unit

JUnit extension to test javax.persistence entities
Apache License 2.0
29 stars 9 forks source link

In-Memory database is not removed after the execution of a preceding test class #6

Closed dadrus closed 6 years ago

dadrus commented 7 years ago

Usually one would like to run specific JPA tests using an in-memory database to have a clean entry point. Executing tests of a single test class will not reveal any limitations of this approach. However running multiple test classes in a batch, like done in CI environments or by just typing mvn test might expose an unexpected limitation: a database (schema and contents) from the execution of a previous test class might still be there and interfere with the execution of the current test class. This is mainly related to when an in-memory database is removed. Most vendors do this when the last connection to the database is closed. Since JPA provider implement and rely on connection pooling, additional time is required to close these connections after closing of the EntityManagerFactory instance. This limitation can only occur if no database cleanup is done by the preceding test class or during the bootstrapping of the current test class.

Here some examples which also describe possible workarounds:

dadrus commented 6 years ago

This issue seems to occur with EclipseLink only and can not be reproduced with e.g Hibernate.