make sure tests cleanup EMs and EMFs

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1027588 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-10-26 15:09:32 +00:00
parent 8556afe921
commit ee682d82ab
2 changed files with 28 additions and 12 deletions

View File

@ -26,6 +26,7 @@ import javax.persistence.EntityManager;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.kernel.FinderCache;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
/**
@ -56,6 +57,7 @@ public class TestFinderCache extends SQLListenerTestCase {
em.persist(cd);
}
em.getTransaction().commit();
em.close();
}
public void setUp() {
@ -69,13 +71,14 @@ public class TestFinderCache extends SQLListenerTestCase {
}
public void testFinder() {
emf = createEMF("openjpa.jdbc.FinderCache", "false");
//closeEMF(emf); // close EMF provided by SingleEMFTestCase
OpenJPAEntityManagerFactorySPI emf1 = createEMF("openjpa.jdbc.FinderCache", "false");
run(1, Book.class, BOOK_IDS); // for warmup
assertNull(getCache());
emf = createEMF("openjpa.jdbc.FinderCache", "true");
assertNotNull(getCache());
assertNull(getCache(emf1));
OpenJPAEntityManagerFactorySPI emf2 = createEMF("openjpa.jdbc.FinderCache", "true");
assertNotNull(getCache(emf2));
closeEMF(emf1);
closeEMF(emf2);
}
public void testSQLEventListener() {
@ -90,6 +93,7 @@ public class TestFinderCache extends SQLListenerTestCase {
}
}
assertEquals(BOOK_IDS.length*N, sql.size());
em.close();
}
/**
@ -114,8 +118,8 @@ public class TestFinderCache extends SQLListenerTestCase {
return stats.get(N/2);
}
FinderCache getCache() {
return ((JDBCConfiguration) emf.getConfiguration()).
FinderCache getCache(OpenJPAEntityManagerFactorySPI oemf) {
return ((JDBCConfiguration) oemf.getConfiguration()).
getFinderCacheInstance();
}

View File

@ -47,6 +47,7 @@ import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
import org.apache.openjpa.persistence.OpenJPAPersistence;
import org.apache.openjpa.persistence.OpenJPAQuery;
import org.apache.openjpa.persistence.jdbc.sqlcache.Employee.Category;
import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
/**
* Tests correctness and performance of queries with and without Prepared Query Cacheing.
@ -66,7 +67,7 @@ import org.apache.openjpa.persistence.jdbc.sqlcache.Employee.Category;
* @author Pinaki Poddar
*
*/
public class TestPreparedQueryCache extends TestCase {
public class TestPreparedQueryCache extends AbstractPersistenceTestCase {
private static String RESOURCE = "META-INF/persistence.xml";
private static String UNIT_NAME = "PreparedQuery";
@ -97,13 +98,16 @@ public class TestPreparedQueryCache extends TestCase {
protected static OpenJPAEntityManagerFactorySPI emf;
protected static SQLAuditor auditor;
protected static int TEST_COUNT = 0;
private OpenJPAEntityManagerSPI em;
/**
* Sets up the test suite with a statically initialized EntityManagerFactory.
* Creates data once for all other tests to use.
*/
public void setUp() {
@Override
public void setUp() throws Exception {
super.setUp();
if (emf == null) {
Properties config = new Properties();
config.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true,SchemaAction='drop,add')");
@ -119,6 +123,7 @@ public class TestPreparedQueryCache extends TestCase {
em = emf.createEntityManager();
getPreparedQueryCache().clear();
}
TEST_COUNT++;
}
/**
@ -223,9 +228,16 @@ public class TestPreparedQueryCache extends TestCase {
em.getTransaction().commit();
}
@Override
public void tearDown() throws Exception {
if (em.isOpen())
em.close();
closeEM(em);
em = null;
if (TEST_COUNT >= 50) {
auditor.clear();
auditor = null;
closeEMF(emf);
emf = null;
}
super.tearDown();
}