1

I have two persistence-units, which are identical except other uses Hibernate's hbm2ddl create-drop and the other uses validate and there the database is created by liquiBase.

Now running any of the tests (HSQLDB named in-mem db) from eclipse, they work fine. But running all of them from maven, they brake with strange foreign key violations.

What I think is strange is that I get messages from 4 different threads and for example closing one of the Persistence Units happens while table drops are still written to console.

Why do I get four threads, all with their own ApplicationContexts? I have no parallel parameters set for surefire and I'm not using -T switch for maven either.

Edit:

Here's a snippet from the commandline output of Maven

Hibernate: drop table PostalCodeDistribution if exists
Hibernate: drop table PublicationAudit if exists
15:21:13.672 [Thread-2] INFO  org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'TestPU-nocreate'
Hibernate: drop table PostalCodeDistributionAudit if exists
Hibernate: drop table PublicationInvoicing if exists
Hibernate: drop table PostalCodeSubscriberCountAudit if exists
15:21:13.672 [Thread-2] INFO  org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000030: Cleaning up connection pool [jdbc:hsqldb:mem:ptptest]
Hibernate: drop table Revision if exists
Hibernate: drop table PriceDate if exists
vertti
  • 7,539
  • 4
  • 51
  • 81

1 Answers1

-1

As you probably know, by default, SureFire executes your tests in a different thread ("fork"). See: Does Maven surefire plugin run tests using multiple threads?

It is likely that your tests, or some libraries used by your tests, execute asynchronously. You should inspect your tests to verify if this is the case.

Community
  • 1
  • 1
noahlz
  • 10,202
  • 7
  • 56
  • 75
  • I don't think this really answers the question. – eis Feb 20 '18 at 13:44
  • Well, without further details about the test configuration and application code, what else can anybody offer? @vertti needs to follow up either with logs that include thread names, or more details. Note that nobody else has contributed an answer. – noahlz Feb 20 '18 at 13:50
  • 1
    well, one could offer a description of how JPA persistancecontext-related tests work in spring: what is expected reuse policy of application contexts and what things contribute to it. Is it normal to have four different contexts? Or not? Why? – eis Feb 20 '18 at 14:15