From 58d1f4966a188ba44232edf5ff5bb27c5d361a3f Mon Sep 17 00:00:00 2001 From: Donald Woods Date: Tue, 12 Oct 2010 15:38:20 +0000 Subject: [PATCH] make sure tests cleanup EMs and EMFs git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1021802 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/AbstractCachedEMFTestCase.java | 16 ++++++++++++---- .../persistence/test/SingleEMFTestCase.java | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractCachedEMFTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractCachedEMFTestCase.java index 01fac6a9b..ef291006e 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractCachedEMFTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractCachedEMFTestCase.java @@ -76,10 +76,18 @@ public abstract class AbstractCachedEMFTestCase extends AbstractPersistenceTestC @Override protected boolean removeEldestEntry(Map.Entry entry) { OpenJPAEntityManagerFactorySPI oemf = (OpenJPAEntityManagerFactorySPI)entry.getValue(); - // if (oemf != null && oemf.isOpen()) { - // oemf.close(); - // } - return this.size() > 2; + if (this.size() > 2) { + // if the eldest should be removed, then try to close it first + if (oemf != null && oemf.isOpen()) { + try { + oemf.close(); + } catch (Exception e) { + // no-op - eat it + } + } + return true; + } + return false; } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java index bb176e08e..c0994de0c 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java @@ -85,6 +85,7 @@ public abstract class SingleEMFTestCase throw e; } finally { closeEMF(emf); + emf = null; } }