db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r566376 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang: Bug4356Test.java Bug5052rtsTest.java Bug5054Test.java LangHarnessJavaTest.java _Suite.java bug4356.java bug5052rts.java bug5054.java
Date Wed, 15 Aug 2007 22:48:14 GMT
Author: kmarsden
Date: Wed Aug 15 15:48:13 2007
New Revision: 566376

URL: http://svn.apache.org/viewvc?view=rev&rev=566376
Log:
DERBY-2900 convert lang\bug5054, lang\bug4356 and lang\bug5052rts to JUnit

Contributed by Ugo Matrangolo


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug4356Test.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5054Test.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/bug4356.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/bug5052rts.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/bug5054.java
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangHarnessJavaTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug4356Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug4356Test.java?view=auto&rev=566376
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug4356Test.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug4356Test.java
Wed Aug 15 15:48:13 2007
@@ -0,0 +1,113 @@
+/**
+ *  Derby - Class org.apache.derbyTesting.functionTests.tests.lang.Bug4356Test
+ *  
+ * 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.Connection;
+import java.sql.PreparedStatement;
+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.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Demonstrate subselect behavior with prepared statement.
+ */
+public class Bug4356Test extends BaseJDBCTestCase {
+
+    /**
+     * Basic constructor.
+     */
+    public Bug4356Test(String name) {
+        super(name);
+    }
+
+    /**
+     * Sets the auto commit to false.
+     */
+    protected void initializeConnection(Connection conn) throws SQLException {
+        conn.setAutoCommit(false);
+    }
+
+    /**
+     * Returns the implemented tests.
+     * 
+     * @return An instance of <code>Test</code> with the implemented tests to
+     *         run.
+     */
+    public static Test suite() {
+        return new CleanDatabaseTestSetup(TestConfiguration
+                .embeddedSuite(Bug4356Test.class)) {
+            protected void decorateSQL(Statement stmt) throws SQLException {
+                stmt.executeUpdate("CREATE TABLE T1 (a integer, b integer)");
+                stmt.executeUpdate("CREATE TABLE T2 (a integer)");
+                stmt.executeUpdate("INSERT INTO T2 VALUES(1)");
+            }
+        };
+    }
+
+    /**
+     * Bug only happens when autocommit is off.
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    /**
+     * Check fix for Bug4356 - Prepared statement parameter buffers are not cleared between
calls 
+     * to executeUpdate() in the same transaction.
+     * Using a prepared statement to insert data into a table using 
+     * a sub select to get the data from a second table. The
+     * prepared statement doesn't seem to clear it's buffers between 
+     * execute statements within the same transaction.
+     * @throws SQLException
+     */
+    public void testBug4356() throws SQLException {
+        Statement stmt = createStatement();
+        ResultSet rs;
+
+        PreparedStatement ps = prepareStatement("INSERT INTO T1 VALUES (?,(select count(*)
from t2 where a = ?)) ");
+
+        ps.setInt(1, 1);
+        ps.setInt(2, 1);
+        ps.executeUpdate();
+
+        ps.setInt(1, 2);
+        ps.setInt(2, 2);
+        ps.executeUpdate();
+
+        commit();
+     
+
+        rs = stmt.executeQuery("SELECT * FROM T1");
+        JDBC.assertFullResultSet(rs,new String[][] {{"1","1"},
+               {"2","0"}});
+ 
+
+        rs.close();
+        stmt.close();
+    }
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java?view=auto&rev=566376
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java
Wed Aug 15 15:48:13 2007
@@ -0,0 +1,145 @@
+/**
+ *  Derby - Class org.apache.derbyTesting.functionTests.tests.lang.Bug5052rtsTest
+ *  
+ * 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.Connection;
+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.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * testing gathering of runtime statistics for for the resultsets/statements not
+ * closed by the usee, but get closed when garbage collector collects such
+ * objects and closes them by calling the finalize.
+ * 
+ */
+public class Bug5052rtsTest extends BaseJDBCTestCase {
+
+    /**
+     * Basic constructor.
+     */
+    public Bug5052rtsTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Sets the auto commit to false.
+     */
+    protected void initializeConnection(Connection conn) throws SQLException {
+        conn.setAutoCommit(false);
+    }
+
+    /**
+     * Returns the implemented tests.
+     * 
+     * @return An instance of <code>Test</code> with the implemented tests to
+     *         run.
+     */
+    public static Test suite() {
+        return new CleanDatabaseTestSetup(TestConfiguration
+                .embeddedSuite(Bug5052rtsTest.class)) {
+            protected void decorateSQL(Statement stmt) throws SQLException {
+                stmt
+                        .execute("create table tab1 (COL1 int, COL2 smallint, COL3 real)");
+                stmt.executeUpdate("insert into tab1 values(1, 2, 3.1)");
+                stmt.executeUpdate("insert into tab1 values(2, 2, 3.1)");
+            }
+        };
+    }
+
+    /**
+     * Make sure NullPointerException does not occur if 
+     * RuntimeStatistics is used and ResultSet is not closed by the user
+     * 
+     * @throws SQLException
+     */
+    public void testBug5052() throws SQLException {
+        Statement stmt0 = createStatement();
+        Statement stmt1 = createStatement();
+        Statement stmt2 = createStatement();
+        CallableStatement cs;
+        ResultSet rs;
+        ResultSet rs1;
+
+        /* case1: Setting runtime statistics on just before result set close. */
+        rs = stmt0.executeQuery("select * from tab1"); // opens the result set
+
+        while (rs.next()) {
+            // System.out.println(rs.getString(1));
+        }
+
+        // set the runtime statistics on now.
+        cs = getConnection().prepareCall(
+                "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(?)");
+        cs.setInt(1, 1);
+        cs.execute();
+        cs.close();
+
+        rs.close();
+
+        cs = getConnection().prepareCall(
+                "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(?)");
+        cs.setInt(1, 0);
+        cs.execute();
+        cs.close();
+
+        /* case2: Statement/Resultset getting closed by the Garbage collector. */
+        rs = stmt1.executeQuery("select * from tab1"); // opens the result set
+
+        while (rs.next()) {
+            // System.out.println(rs.getString(1));
+        }
+        // set the runtime statistics on now.
+        cs = getConnection().prepareCall(
+                "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(?)");
+        cs.setInt(1, 1);
+        cs.execute();
+        cs.close();
+
+        rs1 = stmt2.executeQuery("select count(*) from tab1"); // opens the
+                                                                // result set
+
+        while (rs1.next()) {
+            // System.out.println(rs1.getString(1));
+        }
+
+        for (int i = 0; i < 3; i++) {
+            System.gc();
+            System.runFinalization();
+            // sleep for sometime to make sure garbage collector kicked in
+            // and collected the result set object.
+            try {
+                Thread.sleep(3000);
+            } catch (InterruptedException ie) {
+                fail("Unexpected interruption!");
+            }
+        }
+
+        commit(); // This should have failed before we fix 5052
+    }
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5054Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5054Test.java?view=auto&rev=566376
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5054Test.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5054Test.java
Wed Aug 15 15:48:13 2007
@@ -0,0 +1,107 @@
+/**
+ *  Derby - Class org.apache.derbyTesting.functionTests.tests.lang.Bug5054Test
+ *  
+ * 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.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.Utilities;
+
+/**
+ * Where current of cursorname and case sensitivity
+ */
+public class Bug5054Test extends BaseJDBCTestCase {
+
+    /**
+     * Basic constructor.
+     */
+    public Bug5054Test(String name) {
+        super(name);
+    }
+
+    /**
+     * Sets the auto commit to false.
+     */
+    protected void initializeConnection(Connection conn) throws SQLException {
+        conn.setAutoCommit(false);
+    }
+
+    /**
+     * Returns the implemented tests.
+     * 
+     * @return An instance of <code>Test</code> with the implemented tests to
+     *         run.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Bug5054Test");
+        Test test = new CleanDatabaseTestSetup(TestConfiguration
+                .embeddedSuite(Bug5054Test.class)) {
+            protected void decorateSQL(Statement stmt) throws SQLException {
+                stmt.executeUpdate("CREATE TABLE T1 (a integer, b integer)");
+                stmt.executeUpdate("INSERT INTO T1 VALUES(1, 1)");
+                stmt.executeUpdate("INSERT INTO T1 VALUES(2, 2)");
+            }
+        };
+        suite.addTest(test);
+        suite.addTest(TestConfiguration.clientServerDecorator(test));
+        return suite;
+    }
+
+    /**
+     * 
+     * Test fix of use of delimited cursor name in DRDA.
+     * @throws SQLException
+     */
+    public void testBugBug5054() throws SQLException {
+        Statement stmt1;
+        Statement stmt2;
+        Statement stmt3;
+        ResultSet rs;
+
+        stmt1 = createStatement();
+        stmt1.setCursorName("aBc");
+        rs = stmt1.executeQuery("select * from t1 for update");
+        rs.next();
+
+        stmt2 = createStatement();
+        stmt2.execute("update t1 set b=11 where current of \""
+                + rs.getCursorName() + "\"");
+
+        stmt3 = createStatement();
+        rs = stmt3.executeQuery("SELECT * FROM T1");
+
+        JDBC.assertFullResultSet(rs, 
+                    new String[][]{{"1","11"},
+                    {"2","2"}});
+
+        rs.close();
+    }
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangHarnessJavaTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangHarnessJavaTest.java?view=diff&rev=566376&r1=566375&r2=566376
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangHarnessJavaTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangHarnessJavaTest.java
Wed Aug 15 15:48:13 2007
@@ -53,9 +53,9 @@
     {
         // old derbylang.runall suite
         //"AIjdbc",
-        "bug4356",
-        "bug5052rts",
-        "bug5054",
+        //"bug4356",
+        //"bug5052rts",
+        //"bug5054",
         //"casting", TODO: investigate/convert, uses TestUtil.isNetFramework()
         //"closed", TODO: investigate/convert
         "concateTests",

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?view=diff&rev=566376&r1=566375&r2=566376
==============================================================================
--- 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
Wed Aug 15 15:48:13 2007
@@ -98,7 +98,7 @@
         suite.addTest(UpdateCursorTest.suite());
         suite.addTest(CoalesceTest.suite());
         suite.addTest(ProcedureInTriggerTest.suite());
-	suite.addTest(ForUpdateTest.suite());
+        suite.addTest(ForUpdateTest.suite());
         suite.addTest(CollationTest.suite());
         suite.addTest(CollationTest2.suite());
         suite.addTest(ScrollCursors1Test.suite());
@@ -116,6 +116,9 @@
         suite.addTest(PrimaryKeyTest.suite());
         suite.addTest(RenameTableTest.suite());
         suite.addTest(RenameIndexTest.suite());
+        suite.addTest(Bug5052rtsTest.suite());
+        suite.addTest(Bug5054Test.suite());
+        suite.addTest(Bug4356Test.suite());
 
         // Add the XML tests, which exist as a separate suite
         // so that users can "run all XML tests" easily.



Mime
View raw message