openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtyle...@apache.org
Subject svn commit: r1081067 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
Date Sun, 13 Mar 2011 09:54:15 GMT
Author: mtylenda
Date: Sun Mar 13 09:54:15 2011
New Revision: 1081067

URL: http://svn.apache.org/viewvc?rev=1081067&view=rev
Log:
OPENJPA-1376: Add a test for new allocationSize behavior, make test take advantage of setTestsDisabled
method.

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java?rev=1081067&r1=1081066&r2=1081067&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestNativeSeqGenerator.java
Sun Mar 13 09:54:15 2011
@@ -27,7 +27,6 @@ public class TestNativeSeqGenerator exte
     OpenJPAEntityManager em;
     JDBCConfiguration conf;
     DBDictionary dict;
-    boolean supportsNativeSequence = false;
     
     EntityE2 entityE2;
     
@@ -37,10 +36,14 @@ public class TestNativeSeqGenerator exte
         assertNotNull(emf);
         conf = (JDBCConfiguration) emf.getConfiguration();
         dict = conf.getDBDictionaryInstance();
-        supportsNativeSequence = dict.nextSequenceQuery != null;       
+        boolean supportsNativeSequence = dict.nextSequenceQuery != null;       
+        setTestsDisabled(!supportsNativeSequence);
         if (supportsNativeSequence) {
             em = emf.createEntityManager();
             assertNotNull(em);
+        } else {
+            getLog().trace(this + " is disabled because " + dict.getClass().getSimpleName()
+
+                " does not support native sequences.");
         }
     }
     
@@ -49,10 +52,6 @@ public class TestNativeSeqGenerator exte
     }
     
     public void testGetIdGeneratorSeqGen() {
-        if (!supportsNativeSequence) {
-            System.out.println("Does not support native sequence");
-            return;
-        }
         createEntityE2();
         em.getTransaction().begin();
         em.persist(entityE2);
@@ -62,4 +61,32 @@ public class TestNativeSeqGenerator exte
         assertTrue("Next value should depend on previous genid", nextId >= genId + 1);
         em.close();
     }
+
+    /**
+     * Asserts native sequence generator allocates values in memory
+     * and requests sequence values from database only when necessary.
+     * @since 2.2.0
+     */
+    public void testAllocationSize() {
+        // Turn off statement batching for easier INSERT counting.
+        dict.setBatchLimit(0);
+        em.getTransaction().begin();
+        resetSQL();
+        for (int i = 0; i < 51; i++) {
+            createEntityE2();
+            em.persist(entityE2);
+        }
+        em.getTransaction().commit();
+
+        // Since allocationSize has a default of 50, we expect 2 sequence fetches and 51
INSERTs.
+        assertEquals("53 statements should be executed.", 53, getSQLCount());
+        String[] statements = new String[53];
+        statements[0] = ".*";
+        statements[1] = ".*";
+        for (int i = 2; i < 53; i++) {
+            statements[i] = "INSERT .*";
+        }
+        assertAllExactSQLInOrder(statements);
+        em.close();
+    }
 }



Mime
View raw message