db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r760489 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/master/ functionTests/suites/ functionTests/tests/store/ junit/
Date Tue, 31 Mar 2009 15:43:00 GMT
Author: kmarsden
Date: Tue Mar 31 15:42:59 2009
New Revision: 760489

URL: http://svn.apache.org/viewvc?rev=760489&view=rev
Log:
DERBY-3842 Convert "org.apache.derbyTesting.functionTests.tests.store.holdCursorExternalSortJDBC30.sql"
to junit.

Contributed by Tiago R. Espinha and Junjie Peng


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/HoldCursorExternalSortJDBC30Test.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/holdCursorExternalSortJDBC30.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30_derby.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall?rev=760489&r1=760488&r2=760489&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbynetmats.runall
Tue Mar 31 15:42:59 2009
@@ -6,5 +6,4 @@
 lang/holdCursorIJ.sql
 lang/wisconsin.java
 lang/ShutdownDatabase.java
-store/holdCursorExternalSortJDBC30.sql
 store/holdCursorJDBC30.sql

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall?rev=760489&r1=760488&r2=760489&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/j9derbynetmats.runall
Tue Mar 31 15:42:59 2009
@@ -2,5 +2,4 @@
 derbynet/dblook_test_net_territory.java
 derbynet/runtimeinfo.java
 lang/holdCursorIJ.sql
-store/holdCursorExternalSortJDBC30.sql
 store/holdCursorJDBC30.sql

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall?rev=760489&r1=760488&r2=760489&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/storemore.runall
Tue Mar 31 15:42:59 2009
@@ -26,7 +26,6 @@
 store/bug3498.sql
 store/Beetle6038.java
 store/holdCursorJDBC30.sql
-store/holdCursorExternalSortJDBC30.sql
 store/TestDurabilityProperty.java
 store/OnlineCompressTest.java
 store/OnlineBackupTest1.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/HoldCursorExternalSortJDBC30Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/HoldCursorExternalSortJDBC30Test.java?rev=760489&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/HoldCursorExternalSortJDBC30Test.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/HoldCursorExternalSortJDBC30Test.java
Tue Mar 31 15:42:59 2009
@@ -0,0 +1,288 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.functionTests.tests.store.HoldCursorExternalSortJDBC30Test
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * 
+ */
+package org.apache.derbyTesting.functionTests.tests.store;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import java.util.Properties;
+import junit.framework.Test;
+
+import org.apache.derbyTesting.functionTests.util.Formatters;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.RuntimeStatisticsParser;
+import org.apache.derbyTesting.junit.SQLUtilities;
+import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * TEST CASES SPECIFIC TO STORE IMPLEMENTATION OF HOLD CURSOR (external sort).
+ */
+public class HoldCursorExternalSortJDBC30Test extends BaseJDBCTestCase {
+
+    /**
+     * Public constructor required for running test as standalone JUnit.
+     */
+    public HoldCursorExternalSortJDBC30Test(String name) {
+        super(name);
+    }
+    
+    public static Test suite() {
+        Properties sysProps = new Properties();
+        sysProps.put("derby.storage.sortBufferMax", "5");
+        sysProps.put("derby.debug.true", "testSort");
+
+        Test suite = TestConfiguration.embeddedSuite(HoldCursorExternalSortJDBC30Test.class);
+        return new CleanDatabaseTestSetup(new SystemPropertyTestSetup(suite, sysProps, true))
{
+            /**
+             * Creates the table used in the test cases.
+             *
+             */
+            protected void decorateSQL(Statement s) throws SQLException {
+                Connection conn = s.getConnection();
+                conn.setAutoCommit(false);
+
+                /* This table is used by testOrder_Hold and testOrder_NoHold */
+                s.executeUpdate("create table foo (a int, data varchar(2000))");
+
+                /* This one is specific for testOrderWithMultipleLevel since
+                 * it requires some more records to be inserted */
+                s.executeUpdate("create table bar (a int, data varchar(2000))");
+
+                PreparedStatement ps = conn.prepareStatement(
+                                    "insert into foo values(?,?), (?,?), (?,?), (?,?), (?,?),
" +
+                                    "(?,?), (?,?), (?,?), (?,?), (?,?)"
+                                    );
+
+                for(int i = 0; i <= 9; i++){
+                    ps.setInt(i*2+1, i+1);
+                    ps.setString(i*2+2, Formatters.padString("" + (i+1), 2000));
+                }
+                ps.executeUpdate();
+                ps.close();
+                
+                s.execute("INSERT INTO bar SELECT * FROM foo");
+            }
+
+        };
+    }
+    
+    /**
+     * test hold cursor with external sort (order by).
+     * Cutover to external sort has been set to 4 rows by the test property 
+     * file so with 10 rows we get a 1 level external sort.  This tests that
+     * temp files will be held open across the commit if the cursor is held
+     * open.
+     */
+    public void testOrder_Hold() throws SQLException{
+         setAutoCommit(false);
+
+        Statement stUtil = createStatement();
+        stUtil.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+                        "'derby.language.bulkFetchDefault', '1')");
+        
+        Statement st = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                                       ResultSet.CONCUR_READ_ONLY,
+                                       ResultSet.HOLD_CURSORS_OVER_COMMIT);
+
+        /* Enable statistics */
+        st.execute("CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
+
+        ResultSet test1 = st.executeQuery("select * from foo order by a");
+        stUtil.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+                "'derby.language.bulkFetchDefault', '16')");
+
+        /* Commit pattern for the cursor navigation */
+        boolean[] doCommitAfter = {true, false, false, false, true, false, false, false,
true, false};
+
+        for(int i=0; i<10; i++) {
+            assertTrue(test1.next());
+
+            /* Match both key and the padded value */
+            assertEquals(i+1, test1.getInt("a"));
+            assertEquals(Formatters.padString(""+(i+1), 2000),
+                        test1.getString("data"));
+
+            if (doCommitAfter[i]) {
+                commit();
+            }
+        }
+
+        /* No more records */
+        assertFalse(test1.next());
+
+        test1.close();
+        commit();
+
+        /* Confirm that an external sort occured */
+        RuntimeStatisticsParser parser = SQLUtilities.getRuntimeStatisticsParser(st);
+        assertTrue(parser.usedExternalSort());
+
+        st.close();
+        stUtil.close();
+    }
+    
+    /**
+     * test hold cursor with external sort (order by).
+     * Cutover to external sort has been set to 4 rows by the test property 
+     * file so with 10 rows we get a 1 level external sort.  This tests that
+     * temp files will be held open across the commit if the cursor is held
+     * open.
+     */
+    public void testOrder_NoHold() throws SQLException{        
+        setAutoCommit(false);
+
+        Statement stUtil = createStatement();
+
+        stUtil.execute("CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
+
+        //exercise the non-held cursor path also.
+        stUtil.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+                "'derby.language.bulkFetchDefault', '1')");
+
+        Statement st = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                                       ResultSet.CONCUR_READ_ONLY,
+                                       ResultSet.CLOSE_CURSORS_AT_COMMIT);
+
+        /* Enable statistics */
+        st.execute("CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
+
+        ResultSet test1 = st.executeQuery("select * from foo order by a");
+
+        stUtil.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+                "'derby.language.bulkFetchDefault', '16')");        
+        
+        for(int i=0; i<10; i++) {
+            assertTrue(test1.next());
+
+            /* Match both key and the padded value */
+            assertEquals(i+1, test1.getInt("a"));
+            assertEquals(Formatters.padString(""+(i+1), 2000),
+                        test1.getString("data"));
+        }
+        
+        /* No more records */
+        assertFalse(test1.next());
+
+        test1.close();
+        commit();
+
+        /* Confirm that an external sort occured */
+        RuntimeStatisticsParser parser = SQLUtilities.getRuntimeStatisticsParser(st);
+        assertTrue(parser.usedExternalSort());
+
+        st.close();
+        stUtil.close();
+    }
+    
+    /**
+     * test hold cursor with multi-level external sort (order by).
+     * Cutover to external sort has been set to 4 rows by the test property 
+     * file so with 10 rows we get a 1 level external sort.  This tests that
+     * temp files will be held open across the commit if the cursor is held
+     * open.
+     */
+    public void testOrderWthMultipleLevel() throws SQLException{
+        setAutoCommit(false);
+        
+        Statement stUtil = createStatement();
+        
+        stUtil.addBatch("insert into bar select a + 100, data from bar");
+        stUtil.addBatch("insert into bar select a + 10,  data from bar");
+        stUtil.addBatch("insert into bar select a + 200, data from bar");
+        stUtil.addBatch("insert into bar select a + 200, data from bar");
+        stUtil.executeBatch();
+
+        stUtil.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+        "'derby.language.bulkFetchDefault', '1')");
+
+        Statement st = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                                       ResultSet.CONCUR_READ_ONLY,
+                                       ResultSet.HOLD_CURSORS_OVER_COMMIT);
+
+        /* Enable statistics */
+        st.execute("CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)");
+        
+        ResultSet test1 = st.executeQuery("select * from bar order by a");
+        stUtil.executeUpdate("call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+                "'derby.language.bulkFetchDefault', '16')");
+
+        /* This pattern is repeated twice below */
+        boolean[] doCommitAfter = {true, false, false, false, true, false, false, false,
true, false,
+                                   true, false, false, false, true, false, false, false,
true, false};
+
+        /* Do asserts where a=[1,20] */
+        for(int i=0; i<20; i++) {
+            assertTrue(test1.next());
+
+            /* The actual data ranges from 1 to 10. This enforces it based on "i" */
+            String data = ((i+1) % 10 == 0 ? 10 : (i+1) % 10)+"";
+
+            /* Match both key and the padded value */
+            assertEquals(i+1, test1.getInt("a"));
+            assertEquals(Formatters.padString(data, 2000),
+                        test1.getString("data"));
+
+            /* Check whether we want a commit */
+            if (doCommitAfter[i%20]) {
+                commit();
+            }
+        }
+
+        /* Do asserts where a=[101,120] */
+        for(int i=100; i<120; i++) {
+            assertTrue(test1.next());
+
+            /* The actual data ranges from 1 to 10. This enforces it based on "i" */
+            String data = ((i+1) % 10 == 0 ? 10 : (i+1) % 10)+"";
+
+            /* Match both key and the padded value */
+            assertEquals(i+1, test1.getInt("a"));
+            assertEquals(Formatters.padString(data, 2000),
+                        test1.getString("data"));
+
+            /* Check whether we want a commit */
+            if (doCommitAfter[i%20]) {
+                commit();
+            }
+        }
+
+        /* Do the last assert and commit */
+        assertTrue(test1.next());
+            
+        assertEquals(201, test1.getInt("a"));
+        assertEquals(Formatters.padString("1", 2000),
+                    test1.getString("data"));
+
+        commit();
+        test1.close();
+        
+        /* Confirm that an external sort occured */
+        RuntimeStatisticsParser parser = SQLUtilities.getRuntimeStatisticsParser(st);
+        assertTrue(parser.usedExternalSort());
+
+        stUtil.close();
+        st.close();
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/HoldCursorExternalSortJDBC30Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java?rev=760489&r1=760488&r2=760489&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/_Suite.java
Tue Mar 31 15:42:59 2009
@@ -26,6 +26,7 @@
 
 import junit.framework.Test; 
 import junit.framework.TestSuite;
+import org.apache.derby.iapi.services.sanity.SanityManager;
 
 /**
  * Suite to run all JUnit tests in this package:
@@ -61,6 +62,11 @@
         suite.addTest(LiveLockTest.suite());
         suite.addTest(ClobReclamationTest.suite());
         suite.addTest(IndexSplitDeadlockTest.suite());
+        
+        /* Tests that only run in sane builds */
+        if (SanityManager.DEBUG) {
+            suite.addTest(HoldCursorExternalSortJDBC30Test.suite());
+        }
 
         // Encryption only supported for Derby in J2SE/J2EE environments.
         // J2ME (JSR169) does not support encryption.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java?rev=760489&r1=760488&r2=760489&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/RuntimeStatisticsParser.java
Tue Mar 31 15:42:59 2009
@@ -321,5 +321,13 @@
             return (foundCount >=instances);
                 
         }
+
+    public boolean usedExternalSort() {
+        return (statistics.indexOf("Sort type=external") != -1 );
+    }
+
+    public String toString() {
+        return statistics;
+    }
 }
     



Mime
View raw message