Author: dwoods
Date: Fri Oct 8 21:46:25 2010
New Revision: 1006038
URL: http://svn.apache.org/viewvc?rev=1006038&view=rev
Log:
make sure tests cleanup EMs and EMFs
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestContainerSpecCompatibilityOptions.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestQuerySQLCache.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestContainerSpecCompatibilityOptions.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestContainerSpecCompatibilityOptions.java?rev=1006038&r1=1006037&r2=1006038&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestContainerSpecCompatibilityOptions.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestContainerSpecCompatibilityOptions.java
Fri Oct 8 21:46:25 2010
@@ -81,7 +81,7 @@ public class TestContainerSpecCompatibil
assertEquals("JPA", spec.getName().toUpperCase());
assertEquals(spec.getVersion(), 1);
- emf1.close();
+ closeEMF(emf1);
}
@@ -136,7 +136,7 @@ public class TestContainerSpecCompatibil
em.close();
}
} finally {
- oemf.close();
+ closeEMF(oemf);
}
}
@@ -205,7 +205,7 @@ public class TestContainerSpecCompatibil
fail("OneToMany mapping failed with exception message: " +
e.getMessage());
} finally {
em.close();
- oemf.close();
+ closeEMF(oemf);
}
}
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestQuerySQLCache.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestQuerySQLCache.java?rev=1006038&r1=1006037&r2=1006038&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestQuerySQLCache.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestQuerySQLCache.java
Fri Oct 8 21:46:25 2010
@@ -60,16 +60,19 @@ public class TestQuerySQLCache extends S
props.put("openjpa.jdbc.QuerySQLCache",
"org.apache.openjpa.persistence.compatible.TestQuerySQLCache.BadCacheMap");
+ OpenJPAEntityManagerFactorySPI emf1 = null;
try {
- OpenJPAEntityManagerFactorySPI emf =
(OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+ emf1 = (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
cast(Persistence.createEntityManagerFactory("test", props));
//
// EMF creation must throw an exception because the cache
implementation class will not be found
//
- assertFalse(false);
+ fail("EMF creation must throw an exception because the cache
implementation class will not be found");
}
catch (Exception e) {
assertTrue(true);
+ } finally {
+ closeEMF(emf1);
}
}
@@ -108,117 +111,124 @@ public class TestQuerySQLCache extends S
+
TblParent.class.getName() + ")");
props.put("openjpa.jdbc.QuerySQLCache", "true");
- OpenJPAEntityManagerFactorySPI emf = (OpenJPAEntityManagerFactorySPI)
OpenJPAPersistence.
+ OpenJPAEntityManagerFactorySPI emf1 = (OpenJPAEntityManagerFactorySPI)
OpenJPAPersistence.
cast(Persistence.createEntityManagerFactory("test", props));
- EntityManagerImpl em = (EntityManagerImpl)emf.createEntityManager();
-
- em.getTransaction().begin();
-
- for (int i = 1; i < 3; i++) {
- TblParent p = new TblParent();
- p.setParentId(i);
- TblChild c = new TblChild();
- c.setChildId(i);
- c.setTblParent(p);
- p.addTblChild(c);
- em.persist(p);
- em.persist(c);
-
- TblGrandChild gc = new TblGrandChild();
- gc.setGrandChildId(i);
- gc.setTblChild(c);
- c.addTblGrandChild(gc);
-
- em.persist(p);
- em.persist(c);
- em.persist(gc);
- }
- em.flush();
- em.getTransaction().commit();
- em.clear();
-
- for (int i = 1; i < 3; i++) {
- TblParent p = em.find(TblParent.class, i);
- int pid = p.getParentId();
- assertEquals(pid, i);
- Collection<TblChild> children = p.getTblChildren();
- boolean hasChild = false;
- for (TblChild c : children) {
- hasChild = true;
- Collection<TblGrandChild> gchildren = c.getTblGrandChildren();
- int cid = c.getChildId();
- assertEquals(cid, i);
- boolean hasGrandChild = false;
- for (TblGrandChild gc : gchildren) {
- hasGrandChild = true;
- int gcId = gc.getGrandChildId();
- assertEquals(gcId, i);
+ try {
+ EntityManagerImpl em =
(EntityManagerImpl)emf1.createEntityManager();
+
+ em.getTransaction().begin();
+
+ for (int i = 1; i < 3; i++) {
+ TblParent p = new TblParent();
+ p.setParentId(i);
+ TblChild c = new TblChild();
+ c.setChildId(i);
+ c.setTblParent(p);
+ p.addTblChild(c);
+ em.persist(p);
+ em.persist(c);
+
+ TblGrandChild gc = new TblGrandChild();
+ gc.setGrandChildId(i);
+ gc.setTblChild(c);
+ c.addTblGrandChild(gc);
+
+ em.persist(p);
+ em.persist(c);
+ em.persist(gc);
+ }
+ em.flush();
+ em.getTransaction().commit();
+ em.clear();
+
+ for (int i = 1; i < 3; i++) {
+ TblParent p = em.find(TblParent.class, i);
+ int pid = p.getParentId();
+ assertEquals(pid, i);
+ Collection<TblChild> children = p.getTblChildren();
+ boolean hasChild = false;
+ for (TblChild c : children) {
+ hasChild = true;
+ Collection<TblGrandChild> gchildren =
c.getTblGrandChildren();
+ int cid = c.getChildId();
+ assertEquals(cid, i);
+ boolean hasGrandChild = false;
+ for (TblGrandChild gc : gchildren) {
+ hasGrandChild = true;
+ int gcId = gc.getGrandChildId();
+ assertEquals(gcId, i);
+ }
+ assertTrue(hasGrandChild);
}
- assertTrue(hasGrandChild);
+ assertTrue(hasChild);
+ em.close();
}
- assertTrue(hasChild);
+ } finally {
+ closeEMF(emf1);
}
- em.close();
- emf.close();
}
private void runMultiEMCaching(Map props) {
EntityManagerFactory emfac =
Persistence.createEntityManagerFactory("test", props);
- EntityManager em = emfac.createEntityManager();
+ try {
+ EntityManager em = emfac.createEntityManager();
- //
- // Create some entities
- //
- em.getTransaction().begin();
- for (int i = 0; i < nPeople; i++) {
- Person p = new Person();
- p.setId(i);
- em.persist(p);
- }
- em.flush();
- em.getTransaction().commit();
- em.close();
-
- Thread[] newThreads = new Thread[nThreads];
- FindPeople[] customer = new FindPeople[nThreads];
- for (int i=0; i < nThreads; i++) {
- customer[i] = new FindPeople(emfac, 0, nPeople, nIterations, i);
- newThreads[i] = new Thread(customer[i]);
- newThreads[i].start();
- }
-
- //
- // Wait for the worker threads to complete
- //
- for (int i = 0; i < nThreads; i++) {
- try {
- newThreads[i].join();
+ //
+ // Create some entities
+ //
+ em.getTransaction().begin();
+ for (int i = 0; i < nPeople; i++) {
+ Person p = new Person();
+ p.setId(i);
+ em.persist(p);
}
- catch (InterruptedException e) {
- this.fail("Caught Interrupted Exception: " + e);
+ em.flush();
+ em.getTransaction().commit();
+ em.close();
+
+ Thread[] newThreads = new Thread[nThreads];
+ FindPeople[] customer = new FindPeople[nThreads];
+ for (int i=0; i < nThreads; i++) {
+ customer[i] = new FindPeople(emfac, 0, nPeople, nIterations,
i);
+ newThreads[i] = new Thread(customer[i]);
+ newThreads[i].start();
}
- }
- //
- // Run through the state of all runnables to assert if any of them
failed.
- //
- for (int i = 0; i < nThreads; i++) {
- assertFalse(customer[i].hadFailures());
- }
-
- //
- // Clean up the entities used in this test
- //
- em = emfac.createEntityManager();
- em.getTransaction().begin();
- for (int i = 0; i < nPeople; i++) {
- Person p = em.find(Person.class, i);
- em.remove(p);
- }
- em.flush();
- em.getTransaction().commit();
- em.close();
+ //
+ // Wait for the worker threads to complete
+ //
+ for (int i = 0; i < nThreads; i++) {
+ try {
+ newThreads[i].join();
+ }
+ catch (InterruptedException e) {
+ this.fail("Caught Interrupted Exception: " + e);
+ }
+ }
+
+ //
+ // Run through the state of all runnables to assert if any of them
failed.
+ //
+ for (int i = 0; i < nThreads; i++) {
+ assertFalse(customer[i].hadFailures());
+ }
+
+ //
+ // Clean up the entities used in this test
+ //
+ em = emfac.createEntityManager();
+ em.getTransaction().begin();
+ for (int i = 0; i < nPeople; i++) {
+ Person p = em.find(Person.class, i);
+ em.remove(p);
+ }
+ em.flush();
+ em.getTransaction().commit();
+ em.close();
+ } finally {
+ closeEMF(emfac);
+ }
}
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java?rev=1006038&r1=1006037&r2=1006038&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/compat/TestSpecCompatibilityOptions.java
Fri Oct 8 21:46:25 2010
@@ -54,18 +54,20 @@ extends AbstractCachedEMFTestCase {
"org/apache/openjpa/persistence/compat/" +
"persistence_1_0.xml");
- Compatibility compat =
emf.getConfiguration().getCompatibilityInstance();
- assertTrue(compat.getFlushBeforeDetach());
- assertTrue(compat.getCopyOnDetach());
- assertTrue(compat.getIgnoreDetachedStateFieldForProxySerialization());
- assertTrue(compat.getPrivatePersistentProperties());
- String vMode = emf.getConfiguration().getValidationMode();
- assertEquals("NONE", vMode);
- Specification spec = emf.getConfiguration().getSpecificationInstance();
- assertEquals("JPA", spec.getName().toUpperCase());
- assertEquals(spec.getVersion(), 1);
-
- emf.close();
+ try {
+ Compatibility compat =
emf.getConfiguration().getCompatibilityInstance();
+ assertTrue(compat.getFlushBeforeDetach());
+ assertTrue(compat.getCopyOnDetach());
+
assertTrue(compat.getIgnoreDetachedStateFieldForProxySerialization());
+ assertTrue(compat.getPrivatePersistentProperties());
+ String vMode = emf.getConfiguration().getValidationMode();
+ assertEquals("NONE", vMode);
+ Specification spec =
emf.getConfiguration().getSpecificationInstance();
+ assertEquals("JPA", spec.getName().toUpperCase());
+ assertEquals(spec.getVersion(), 1);
+ } finally {
+ closeEMF(emf);
+ }
}
/*
@@ -79,18 +81,20 @@ extends AbstractCachedEMFTestCase {
"org/apache/openjpa/persistence/compat/" +
"persistence_2_0.xml");
- Compatibility compat =
emf.getConfiguration().getCompatibilityInstance();
- assertFalse(compat.getFlushBeforeDetach());
- assertFalse(compat.getCopyOnDetach());
- assertFalse(compat.getIgnoreDetachedStateFieldForProxySerialization());
- assertFalse(compat.getPrivatePersistentProperties());
- String vMode = emf.getConfiguration().getValidationMode();
- assertEquals("AUTO", vMode);
- Specification spec = emf.getConfiguration().getSpecificationInstance();
- assertEquals("JPA", spec.getName().toUpperCase());
- assertEquals(spec.getVersion(), 2);
-
- emf.close();
+ try {
+ Compatibility compat =
emf.getConfiguration().getCompatibilityInstance();
+ assertFalse(compat.getFlushBeforeDetach());
+ assertFalse(compat.getCopyOnDetach());
+
assertFalse(compat.getIgnoreDetachedStateFieldForProxySerialization());
+ assertFalse(compat.getPrivatePersistentProperties());
+ String vMode = emf.getConfiguration().getValidationMode();
+ assertEquals("AUTO", vMode);
+ Specification spec =
emf.getConfiguration().getSpecificationInstance();
+ assertEquals("JPA", spec.getName().toUpperCase());
+ assertEquals(spec.getVersion(), 2);
+ } finally {
+ closeEMF(emf);
+ }
}
/*
@@ -125,7 +129,7 @@ extends AbstractCachedEMFTestCase {
em.close();
}
} finally {
- emf.close();
+ closeEMF(emf);
}
}
@@ -194,7 +198,7 @@ extends AbstractCachedEMFTestCase {
fail("OneToMany mapping failed with exception message: " +
e.getMessage());
} finally {
em.close();
- emf.close();
+ closeEMF(emf);
}
}