db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1579762 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ suites/ tests/lang/
Date Thu, 20 Mar 2014 21:36:20 GMT
Author: dag
Date: Thu Mar 20 21:36:20 2014
New Revision: 1579762

URL: http://svn.apache.org/r1579762
Log:
DERBY-6516 Convert lang/nestedCommit.sql to JUnit NestedCommitTest

Patch derby-6515 converts the test in question to JUnit and wires it
into the lang suite while removing it from the harness tests.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedCommitTest.java
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nestedCommit.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/nestedCommit_app.properties
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggBuiltinTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?rev=1579762&r1=1579761&r2=1579762&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
Thu Mar 20 21:36:20 2014
@@ -11,7 +11,6 @@ lang/isolationLevels.sql
 lang/joinDeadlock.sql
 lang/langUnitTests.sql
 lang/maxMemPerTab.java
-lang/nestedCommit.sql
 lang/openScans.sql
 lang/orderbyElimination.sql
 lang/outparams.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggBuiltinTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggBuiltinTest.java?rev=1579762&r1=1579761&r2=1579762&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggBuiltinTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AggBuiltinTest.java
Thu Mar 20 21:36:20 2014
@@ -43,7 +43,7 @@ public final class AggBuiltinTest extend
     private String [][] expRS;
     private final String NULLS_ELIMINATED = "01003";
     private SQLWarning sqlWarn = null;
-    private String[][] SINGLE_NULL_ROW = new String[][]{{null}};
+    private final String[][] SINGLE_NULL_ROW = new String[][]{{null}};
     /**
      * Public constructor required for running test as standalone JUnit.
      * @param name test name

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedCommitTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedCommitTest.java?rev=1579762&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedCommitTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedCommitTest.java
Thu Mar 20 21:36:20 2014
@@ -0,0 +1,200 @@
+/**
+ *  Derby - Class org.apache.derbyTesting.functionTests.tests.lang.NestedCommitTest
+ *
+ * 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.lang;
+
+import java.sql.CallableStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import junit.framework.Test;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Test nested commit
+ */
+
+public final class NestedCommitTest extends BaseJDBCTestCase {
+
+    /**
+     * Public constructor required for running test as standalone JUnit.
+     * @param name test name
+     */
+    public NestedCommitTest(String name)
+    {
+        super(name);
+    }
+
+    public static Test suite()
+    {
+        return TestConfiguration.defaultSuite(NestedCommitTest.class);
+    }
+
+    public void testNestedCommit() throws Exception
+    {
+        ResultSet rs;
+        CallableStatement cSt;
+        Statement st = createStatement();
+
+        String [][] expRS;
+        String [] expColNames;
+
+        st.getConnection().setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
+
+        try {
+            // Make sure that we cannot do a commit/rollback on a nested
+            // connection when we are in the middle of something that has to be
+            // atomic (e.g. DML). commit/rollback on a nested connection is
+            // only permitted when we are doing something simple like CALL
+            // myMethod() or VALUES myMethod().
+
+            st.executeUpdate("CREATE PROCEDURE doConnCommit() "
+                    + "       DYNAMIC RESULT SETS 0 LANGUAGE JAVA "
+                    + "       EXTERNAL NAME "
+                    + "'org.apache.derbyTesting.functionTests.util.Triggers"
+                    + ".doConnCommit' "
+                    + "    CONTAINS SQL"
+                    + "       PARAMETER STYLE JAVA");
+
+            st.executeUpdate("CREATE PROCEDURE doConnRollback() "
+                    + "       DYNAMIC RESULT SETS 0 LANGUAGE JAVA "
+                    + "       EXTERNAL NAME "
+                    + "'org.apache.derbyTesting.functionTests.util.Triggers"
+                    + ".doConnRollback' "
+                    + "    CONTAINS SQL"
+                    + "       PARAMETER STYLE JAVA");
+
+            st.executeUpdate("CREATE PROCEDURE doConnStmt(IN TEXT CHAR(50)) "
+                    + "       DYNAMIC RESULT SETS 0 LANGUAGE JAVA "
+                    + "       EXTERNAL NAME "
+                    + "'org.apache.derbyTesting.functionTests.util.Triggers"
+                    + ".doConnStmtNoRS' "
+                    + "    CONTAINS SQL"
+                    + "       PARAMETER STYLE JAVA");
+
+            st.executeUpdate("CREATE FUNCTION doConnCommitInt() "
+                    + "       RETURNS INT EXTERNAL NAME "
+                    + "'org.apache.derbyTesting.functionTests.util.Triggers"
+                    + ".doConnCommitInt' "
+                    + "       LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+            st.executeUpdate("CREATE FUNCTION doConnStmtInt(TEXT CHAR(50)) "
+                    + "       RETURNS INT EXTERNAL NAME "
+                    + "'org.apache.derbyTesting.functionTests.util.Triggers"
+                    + ".doConnStmtIntNoRS' "
+                    + "       LANGUAGE JAVA PARAMETER STYLE JAVA");
+
+            st.executeUpdate("create table x (x int)");
+            st.executeUpdate("insert into x values 1,2,3,4");
+
+            setAutoCommit(false);
+
+            // All the following calls should succeed
+            //
+            cSt = prepareCall("call doConnCommit()");
+            assertUpdateCount(cSt, 0);
+
+            cSt = prepareCall("call doConnRollback()");
+            assertUpdateCount(cSt, 0);
+
+            // No longer supported as language statements.
+            // call doConnStmt('commit'); call doConnStmt('rollback');
+
+            cSt = prepareCall("call doConnStmt('call doConnCommit()')");
+            assertUpdateCount(cSt, 0);
+
+            cSt = prepareCall("call doConnStmt('call doConnRollback()')");
+            assertUpdateCount(cSt, 0);
+
+            // call doConnStmt('call doConnStmt(''call
+            // doConnStmt(''''commit'''')'')');
+
+            rs = st.executeQuery("values doConnCommitInt()");
+            assertTrue(rs.next());
+            try {
+                rs.getString(1);
+            } catch (SQLException e) {
+                assertSQLState("XCL16", e);
+            }
+
+            // values doConnStmtInt('commit');
+            // values doConnStmtInt('rollback');
+            // values doConnStmtInt('call doConnStmt(
+            //                     ''call doConnStmt(''''commit'''')'')');
+
+            rs = st.executeQuery(
+                    "values doConnStmtInt('values doConnCommitInt()')");
+            JDBC.assertFullResultSet(rs, new String [][]{{"1"}}, true);
+
+            // fail
+
+            assertStatementError(
+                    "38000", st,
+                    "insert into x select x+doConnCommitInt() from x");
+
+            assertStatementError(
+                    "38000", st,
+                    "delete from x where x in (select x+doConnCommitInt() from x)");
+
+            assertStatementError(
+                    "38000", st,
+                    "delete from x where x = doConnCommitInt()");
+
+            assertStatementError(
+                    "38000", st,
+                    "update x set x = doConnCommitInt()");
+
+            // insert into x values doConnStmtInt(
+            //          'call doConnStmt(''call doConnStmt(''''commit'''')'')');
+            // select doConnStmtInt('call doConnStmt(
+            //          ''call doConnStmt(''''rollback'''')'')') from x;
+
+            assertStatementError(
+                    "38000", st,
+                    "select doConnStmtInt('call doConnStmt(" +
+                            "''call doConnCommit()'')') from x");
+
+            cSt = prepareCall(
+                "call doConnStmt('set isolation serializable')");
+            assertUpdateCount(cSt, 0);
+
+        } finally {
+            // clean up
+            dontThrow(st, "drop table x");
+            dontThrow(st, "drop procedure doConnCommit");
+            dontThrow(st, "drop procedure doConnRollback");
+            dontThrow(st, "drop function doConnCommitInt");
+            dontThrow(st, "drop procedure doConnStmt");
+            dontThrow(st, "drop function doConnStmtInt");
+            commit();
+        }
+    }
+
+    private void dontThrow(Statement st, String stm) {
+        try {
+            st.executeUpdate(stm);
+        } catch (SQLException e) {
+            // ignore, best effort here
+        }
+    }
+}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=1579762&r1=1579761&r2=1579762&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Thu Mar 20 21:36:20 2014
@@ -244,6 +244,7 @@ public class _Suite extends BaseTestCase
         suite.addTest(NewOptimizerOverridesTest.suite());
         suite.addTest(XMLOptimizerTraceTest.suite());
         suite.addTest(MergeStatementTest.suite());
+        suite.addTest(NestedCommitTest.suite());
         suite.addTest(ForeignKeysNonSpsTest.suite());
         suite.addTest(LOBDB2compatibilityTest.suite());
         suite.addTest(CurrentSchemaTest.suite());



Mime
View raw message