mirror of
https://github.com/apache/openjpa.git
synced 2025-03-06 16:39:11 +00:00
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:
parent
8556afe921
commit
ee682d82ab
@ -26,6 +26,7 @@ import javax.persistence.EntityManager;
|
|||||||
|
|
||||||
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
|
||||||
import org.apache.openjpa.kernel.FinderCache;
|
import org.apache.openjpa.kernel.FinderCache;
|
||||||
|
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
||||||
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,6 +57,7 @@ public class TestFinderCache extends SQLListenerTestCase {
|
|||||||
em.persist(cd);
|
em.persist(cd);
|
||||||
}
|
}
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@ -69,13 +71,14 @@ public class TestFinderCache extends SQLListenerTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testFinder() {
|
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
|
run(1, Book.class, BOOK_IDS); // for warmup
|
||||||
|
assertNull(getCache(emf1));
|
||||||
assertNull(getCache());
|
OpenJPAEntityManagerFactorySPI emf2 = createEMF("openjpa.jdbc.FinderCache", "true");
|
||||||
|
assertNotNull(getCache(emf2));
|
||||||
emf = createEMF("openjpa.jdbc.FinderCache", "true");
|
closeEMF(emf1);
|
||||||
assertNotNull(getCache());
|
closeEMF(emf2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSQLEventListener() {
|
public void testSQLEventListener() {
|
||||||
@ -90,6 +93,7 @@ public class TestFinderCache extends SQLListenerTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(BOOK_IDS.length*N, sql.size());
|
assertEquals(BOOK_IDS.length*N, sql.size());
|
||||||
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,8 +118,8 @@ public class TestFinderCache extends SQLListenerTestCase {
|
|||||||
return stats.get(N/2);
|
return stats.get(N/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
FinderCache getCache() {
|
FinderCache getCache(OpenJPAEntityManagerFactorySPI oemf) {
|
||||||
return ((JDBCConfiguration) emf.getConfiguration()).
|
return ((JDBCConfiguration) oemf.getConfiguration()).
|
||||||
getFinderCacheInstance();
|
getFinderCacheInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
|
|||||||
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
||||||
import org.apache.openjpa.persistence.OpenJPAQuery;
|
import org.apache.openjpa.persistence.OpenJPAQuery;
|
||||||
import org.apache.openjpa.persistence.jdbc.sqlcache.Employee.Category;
|
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.
|
* 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
|
* @author Pinaki Poddar
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TestPreparedQueryCache extends TestCase {
|
public class TestPreparedQueryCache extends AbstractPersistenceTestCase {
|
||||||
|
|
||||||
private static String RESOURCE = "META-INF/persistence.xml";
|
private static String RESOURCE = "META-INF/persistence.xml";
|
||||||
private static String UNIT_NAME = "PreparedQuery";
|
private static String UNIT_NAME = "PreparedQuery";
|
||||||
@ -97,13 +98,16 @@ public class TestPreparedQueryCache extends TestCase {
|
|||||||
|
|
||||||
protected static OpenJPAEntityManagerFactorySPI emf;
|
protected static OpenJPAEntityManagerFactorySPI emf;
|
||||||
protected static SQLAuditor auditor;
|
protected static SQLAuditor auditor;
|
||||||
|
protected static int TEST_COUNT = 0;
|
||||||
private OpenJPAEntityManagerSPI em;
|
private OpenJPAEntityManagerSPI em;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the test suite with a statically initialized EntityManagerFactory.
|
* Sets up the test suite with a statically initialized EntityManagerFactory.
|
||||||
* Creates data once for all other tests to use.
|
* Creates data once for all other tests to use.
|
||||||
*/
|
*/
|
||||||
public void setUp() {
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
if (emf == null) {
|
if (emf == null) {
|
||||||
Properties config = new Properties();
|
Properties config = new Properties();
|
||||||
config.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true,SchemaAction='drop,add')");
|
config.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true,SchemaAction='drop,add')");
|
||||||
@ -119,6 +123,7 @@ public class TestPreparedQueryCache extends TestCase {
|
|||||||
em = emf.createEntityManager();
|
em = emf.createEntityManager();
|
||||||
getPreparedQueryCache().clear();
|
getPreparedQueryCache().clear();
|
||||||
}
|
}
|
||||||
|
TEST_COUNT++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,9 +228,16 @@ public class TestPreparedQueryCache extends TestCase {
|
|||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
if (em.isOpen())
|
closeEM(em);
|
||||||
em.close();
|
em = null;
|
||||||
|
if (TEST_COUNT >= 50) {
|
||||||
|
auditor.clear();
|
||||||
|
auditor = null;
|
||||||
|
closeEMF(emf);
|
||||||
|
emf = null;
|
||||||
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user