Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Ensure that EntityManagers are closed in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Apr 11, 2014
1 parent c6a6d65 commit 543f3dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Expand Up @@ -6,7 +6,8 @@

import org.hibernate.Session;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
Expand Down Expand Up @@ -104,17 +105,20 @@ public void deleteExceptEssentialData() {
}

private void purgeLuceneIndexes() {
FullTextSession fullTextSession =
Search.getFullTextSession((Session) entityManagerFactory
.createEntityManager().getDelegate());

fullTextSession.purgeAll(HAccount.class);
fullTextSession.purgeAll(HGlossaryEntry.class);
fullTextSession.purgeAll(HGlossaryTerm.class);
fullTextSession.purgeAll(HProject.class);
fullTextSession.purgeAll(HProjectIteration.class);
fullTextSession.purgeAll(TransMemoryUnit.class);
fullTextSession.purgeAll(HTextFlowTarget.class);
FullTextEntityManager em =
Search.getFullTextEntityManager(
entityManagerFactory.createEntityManager());
try {
em.purgeAll(HAccount.class);
em.purgeAll(HGlossaryEntry.class);
em.purgeAll(HGlossaryTerm.class);
em.purgeAll(HProject.class);
em.purgeAll(HProjectIteration.class);
em.purgeAll(TransMemoryUnit.class);
em.purgeAll(HTextFlowTarget.class);
} finally {
em.close();
}
}

public void makeSampleLanguages() {
Expand Down
Expand Up @@ -76,6 +76,9 @@ abstract class ZanataGroovyJpaTest {
public void shutdownEM() {
log.debug("Shutting down EM");
em.getTransaction().rollback();
if (em.isOpen()) {
em.close();
}
em = null;
}

Expand Down
3 changes: 3 additions & 0 deletions zanata-war/src/test/java/org/zanata/provider/JPAProvider.java
Expand Up @@ -52,6 +52,9 @@ public void shutdownEM() {
log.debug("Shutting down EM");
clearHibernateSecondLevelCache();
em.getTransaction().rollback();
if (em.isOpen()) {
em.close();
}
em = null;
}

Expand Down

0 comments on commit 543f3dd

Please sign in to comment.