openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtyle...@apache.org
Subject svn commit: r814295 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence: common/utils/ kernel/
Date Sun, 13 Sep 2009 10:02:01 GMT
Author: mtylenda
Date: Sun Sep 13 10:02:01 2009
New Revision: 814295

URL: http://svn.apache.org/viewvc?rev=814295&view=rev
Log:
OPENJPA-1153: Speed tests up by using only needed entities rather than all entities from persistence.xml

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCheckConsistency.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestClassStringConstructor.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDateQueries.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java?rev=814295&r1=814294&r2=814295&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/common/utils/AbstractTestCase.java
Sun Sep 13 10:02:01 2009
@@ -67,6 +67,7 @@
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
+import java.util.Map.Entry;
 
 import javax.management.IntrospectionException;
 import javax.persistence.EntityManager;
@@ -93,6 +94,7 @@
     private Map<Map,OpenJPAEntityManagerFactory> emfs =
         new HashMap<Map,OpenJPAEntityManagerFactory>();
     private OpenJPAEntityManager currentEntityManager;
+    private Object[] props;
 
     protected enum Platform {
         EMPRESS,
@@ -118,6 +120,18 @@
         persistenceXmlResource = computePersistenceXmlResource(s);
     }
 
+    /**
+     * Use the given persistent types during the test.
+     * 
+     * @param props
+     *            list of persistent types used in testing and/or configuration values in
the form
+     *            key,value,key,value...
+     */
+    protected void setUp(Object... props) throws Exception {
+        super.setUp();
+        this.props = props;
+    }
+
     public void tearDown() throws Exception {
         try {
             super.tearDown();
@@ -194,11 +208,25 @@
         addProperties(map);
 
         OpenJPAEntityManagerFactory emf = emfs.get(map);
-        if (emf == null) {
-            emf = OpenJPAPersistence.createEntityManagerFactory(
-                "TestConv", persistenceXmlResource, map);
-            emfs.put(map, emf);
+        if (emf != null) {
+            return emf;
+        }
+
+        if (props != null) {
+            // Join properties passed in setUp (usually entities) with the given map and
use them to create EMF.
+            Object[] propsAndMap = new Object[props.length + map.size() * 2];
+            System.arraycopy(props, 0, propsAndMap, 0, props.length);
+            int i = props.length;
+            for (Object o : map.entrySet()) {
+                Entry mapEntry = (Entry) o;
+                propsAndMap[i++] = mapEntry.getKey();
+                propsAndMap[i++] = mapEntry.getValue();
+            }
+            emf = createEMF(propsAndMap);
+        } else {
+            emf = OpenJPAPersistence.createEntityManagerFactory("TestConv", persistenceXmlResource,
map);
         }
+        emfs.put(map, emf);
         return emf;
     }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java?rev=814295&r1=814294&r2=814295&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCalendarFields.java
Sun Sep 13 10:02:01 2009
@@ -48,8 +48,8 @@
         super(name);
     }
 
-    public void setUp() {
-        deleteAll(CalendarFields.class);
+    public void setUp() throws Exception {
+        super.setUp(CalendarFields.class);
     }
 
     public void testFieldDefaultTimeZone() {
@@ -67,7 +67,7 @@
         endEm(pm);
 
         pm = getPM();
-        cal = (CalendarFields) pm.find(CalendarFields.class, id);
+        cal = pm.find(CalendarFields.class, id);
         assertEquals(TimeZone.getTimeZone("Asia/Singapore"),
             cal.getSingapore().getTimeZone());
         endEm(pm);
@@ -90,9 +90,9 @@
         endEm(pm);
 
         pm = getPM();
-        c2 = (CalendarFields) pm.find(CalendarFields.class, id2);
+        c2 = pm.find(CalendarFields.class, id2);
         assertTimeZonesEquals(c1, c2);
-        assertTimeZonesEquals(c1, (CalendarFields) pm.detachCopy(c2));
+        assertTimeZonesEquals(c1, pm.detachCopy(c2));
         endEm(pm);
     }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCheckConsistency.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCheckConsistency.java?rev=814295&r1=814294&r2=814295&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCheckConsistency.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestCheckConsistency.java
Sun Sep 13 10:02:01 2009
@@ -45,8 +45,8 @@
         super(name);
     }
 
-    public void setUp() {
-        deleteAll(RuntimeTest1.class);
+    public void setUp() throws Exception {
+        super.setUp(RuntimeTest1.class);
 
         RuntimeTest1 pc = new RuntimeTest1();
         pc.setIntField(1);
@@ -61,7 +61,7 @@
         pm.validateChanges();        // no-op outside trans
         startTx(pm);
 
-        RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
+        RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
         pc.setIntField1(100);
 
         RuntimeTest1 npc = new RuntimeTest1();
@@ -89,7 +89,7 @@
         pm.validateChanges();        // no-op outside trans
         startTx(pm);
 
-        RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
+        RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
         pc.setIntField1(100);
 
         RuntimeTest1 npc = new RuntimeTest1();
@@ -112,7 +112,7 @@
         pm = getPM();
         try {
             RuntimeTest1 temp =
-                (RuntimeTest1) pm.find(RuntimeTest1.class, noid);
+                pm.find(RuntimeTest1.class, noid);
             fail("Object should not exist." + temp.getIntField() + "::" +
                 temp.getIntField1());
         } catch (Exception jonfe) {
@@ -176,7 +176,7 @@
         startTx(pm);
         boolean hasConn = hasConnection(pm);
 
-        RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
+        RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
         pc.setIntField1(100);
 
         RuntimeTest1 npc = new RuntimeTest1();
@@ -212,7 +212,7 @@
         startTx(pm);
         boolean hasConn = hasConnection(pm);
 
-        RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
+        RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
         pc.setIntField1(100);
 
         RuntimeTest1 npc = new RuntimeTest1();
@@ -238,7 +238,7 @@
         pm = getPM();
         try {
             RuntimeTest1 temp =
-                (RuntimeTest1) pm.find(RuntimeTest1.class, noid);
+                pm.find(RuntimeTest1.class, noid);
 
             fail("Object should not exist." + temp.getIntField() + "::" +
                 temp.getIntField1());

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestClassStringConstructor.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestClassStringConstructor.java?rev=814295&r1=814294&r2=814295&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestClassStringConstructor.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestClassStringConstructor.java
Sun Sep 13 10:02:01 2009
@@ -41,8 +41,8 @@
         super(name);
     }
 
-    public void setUp() {
-        deleteAll(AppIdClassString.class);
+    public void setUp() throws Exception {
+        super.setUp(AppIdClassString.class);
     }
 
     public void testConstructor() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDateQueries.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDateQueries.java?rev=814295&r1=814294&r2=814295&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDateQueries.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDateQueries.java
Sun Sep 13 10:02:01 2009
@@ -60,7 +60,7 @@
 
     public void setUp()
         throws Exception {
-        super.setUp();
+        super.setUp(AllFieldTypesTest.class);
 
         SimpleDateFormat sdf = new SimpleDateFormat("MMMMM dd, yyyy",
             Locale.US);
@@ -69,9 +69,6 @@
         _after = sdf.parse("April 27, 1978");
         _pm = getPM();
 
-        // delete all existing instances
-        deleteAll(AllFieldTypesTest.class);
-
         // create some instances to query on
         startTx(_pm);
         AllFieldTypesTest test = new AllFieldTypesTest();

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java?rev=814295&r1=814294&r2=814295&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java
Sun Sep 13 10:02:01 2009
@@ -52,8 +52,8 @@
         super(name);
     }
 
-    public void setUp() {
-        deleteAll(RuntimeTest1.class);
+    public void setUp() throws Exception {
+        super.setUp(RuntimeTest1.class, RuntimeTest2.class);
 
         OpenJPAEntityManager pm = getPM();
         startTx(pm);
@@ -101,7 +101,7 @@
 
     public void testExtent4() {
         OpenJPAEntityManager pm = getPM();
-        Extent ext = (Extent) pm.createExtent(RuntimeTest1.class, true);
+        Extent ext = pm.createExtent(RuntimeTest1.class, true);
 
         List all = new LinkedList();
         for (Iterator i = ext.iterator(); i.hasNext();)

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java?rev=814295&r1=814294&r2=814295&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java
Sun Sep 13 10:02:01 2009
@@ -54,8 +54,8 @@
     public TestExtents2() {
     }
 
-    public void setUp() {
-        deleteAll(RuntimeTest1.class);
+    public void setUp() throws Exception {
+        super.setUp(RuntimeTest1.class, RuntimeTest2.class, RuntimeTest3.class);
 
         RuntimeTest1 test1 = new RuntimeTest1();
         test1.setIntField(1);
@@ -170,7 +170,7 @@
         startTx(pm);
         try {
             RuntimeTest2 test2 =
-                (RuntimeTest2) pm.find(RuntimeTest2.class, _oid2);
+                pm.find(RuntimeTest2.class, _oid2);
             pm.remove(test2);
             RuntimeTest1 test1 = new RuntimeTest1();
             pm.persist(test1);



Mime
View raw message