db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r476316 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi: ConcurrencyTest.java HoldabilityTest.java UpdatableResultSetTest.java UpdateXXXTest.java
Date Fri, 17 Nov 2006 21:12:01 GMT
Author: djd
Date: Fri Nov 17 13:11:59 2006
New Revision: 476316

URL: http://svn.apache.org/viewvc?view=rev&rev=476316
Log:
Various changes to ensure JDBC objects are closed when running the JUnit tests in the jdbcapi
package.
Change UpdateableResultSetTest to become standard and use the connection provided by
the super class.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java?view=diff&rev=476316&r1=476315&r2=476316
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
Fri Nov 17 13:11:59 2006
@@ -677,26 +677,28 @@
         
         // Compressing the table in another transaction:
         Connection con2 = openDefaultConnection();
+        
+        con2.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        PreparedStatement ps2 = con2.prepareStatement
+            ("call SYSCS_UTIL.SYSCS_COMPRESS_TABLE(?, ?, ?)");
+        ps2.setString(1, "APP");
+        ps2.setString(2, "T1");
+        ps2.setInt(3, 0);
+        println("T2: call SYSCS_UTIL.SYSCS_COMPRESS_TABLE(APP, T1, 0)");
         try {
-            con2.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-            PreparedStatement ps2 = con2.prepareStatement
-                ("call SYSCS_UTIL.SYSCS_COMPRESS_TABLE(?, ?, ?)");
-            ps2.setString(1, "APP");
-            ps2.setString(2, "T1");
-            ps2.setInt(3, 0);
-            println("T2: call SYSCS_UTIL.SYSCS_COMPRESS_TABLE(APP, T1, 0)");
             ps2.executeUpdate(); // This will hang
-            assertTrue("Expected T2 to hang", false);
+            fail("Expected T2 to hang");
         } catch (SQLException e) {
             println("T2: Got exception:" + e.getMessage());
             
-            assertEquals("Unexpected SQL state", 
-                         LOCK_TIMEOUT_EXPRESSION_SQL_STATE,
-                         e.getSQLState());
-        } finally {
-            con2.rollback();
+            assertSQLState(LOCK_TIMEOUT_EXPRESSION_SQL_STATE, e);
+
         }
+        ps2.close();
+        con2.rollback();
         con2.close();
+        
+        s.close();
     }
     
     /**
@@ -717,19 +719,20 @@
                 rs.getInt(3) + ")");
         Connection con2 = openDefaultConnection();
         con2.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        try {
-            PreparedStatement ps2 = con2.prepareStatement
+
+        PreparedStatement ps2 = con2.prepareStatement
                 ("delete from t1 where id=?");
-            ps2.setInt(1, firstKey);
+        ps2.setInt(1, firstKey);
+        try {
             ps2.executeUpdate();
-            assertTrue("expected record with id=" + firstKey + 
-                       " to be locked", false);
+            fail("expected record with id=" + firstKey + 
+                       " to be locked");
         } catch (SQLException e) {
-            assertEquals("Unexpected SQL state",  LOCK_TIMEOUT_SQL_STATE,
-                         e.getSQLState());
-        } finally {
-            con2.rollback();
+            assertSQLState(LOCK_TIMEOUT_SQL_STATE, e);
         }
+        
+        ps2.close();
+        con2.rollback();
         con2.close();
         s.close();
     }
@@ -770,6 +773,7 @@
         println("T1: delete records");
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
+        delStatement.close();
         commit();
         println("T1: commit");
         
@@ -807,11 +811,12 @@
             ps2.executeUpdate();
             con2.commit();
             println("T3: commit");
-            assertTrue("Expected T3 to hang waiting for Table lock", false);
+            fail("Expected T3 to hang waiting for Table lock");
         } catch (SQLException e) {            
             println("T3: got expected exception");
             con2.rollback();            
         }
+        ps2.close();
         rs.first(); // Go to first tuple
         println("T1: Read first Tuple:(" + rs.getInt(1) + "," +
                 rs.getInt(2) + "," +
@@ -838,6 +843,7 @@
                     rs.getInt(3) + ")");
         }
         con2.close();
+        s.close();
     }
     
     // By providing a static suite(), you can customize which tests to run.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java?view=diff&rev=476316&r1=476315&r2=476316
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
Fri Nov 17 13:11:59 2006
@@ -465,7 +465,8 @@
                 // Delete all records except the first:
         Statement delStatement = createStatement();
         int deleted = delStatement.executeUpdate("delete from T1 where id>0");
-        int expectedDeleted = recordCount-1;    
+        int expectedDeleted = recordCount-1;
+        delStatement.close();
         
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
@@ -609,13 +610,10 @@
         ps2.setBoolean(4, defragment);
         ps2.setBoolean(5, truncate);
         
-        try { 
-            ps2.executeUpdate();
-            ps2.close();
-            con2.commit();
-        } finally {
-            con2.close();
-        }
+        ps2.executeUpdate();
+        ps2.close();
+        con2.commit();
+        con2.close();
     }
 
     private final static String selectStatement = "select * from t1";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java?view=diff&rev=476316&r1=476315&r2=476316
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdatableResultSetTest.java
Fri Nov 17 13:11:59 2006
@@ -39,11 +39,15 @@
     public UpdatableResultSetTest(String name) {
         super(name);
     }
-
-    private Connection conn = null;
     
+    /**
+     * Create require objects and data. No tearDown
+     * is needed because these are created in non-auto-commit
+     * mode and no commit is ever issued. Thus on the super's
+     * tearDown the rollback will revert everything.
+     */
     protected void setUp() throws SQLException {
-        conn = getConnection();
+        Connection conn = getConnection();
         conn.setAutoCommit(false);
         Statement stmt = conn.createStatement();
         
@@ -68,17 +72,8 @@
         stmt.executeUpdate("create table \"my table\" (x int)");
         stmt.executeUpdate("insert into \"my table\" values (1), (2), (3) ");
         
-        
-        
         stmt.close();
     }
-
-    protected void tearDown() throws Exception {
-        conn.rollback();
-        conn.close();
-        super.tearDown();
-        conn = null;
-    }
     
     /** Create a test suite with all tests in this class. */
     public static Test suite() {
@@ -97,7 +92,7 @@
      */
     public void testInsertRowOnQuotedTable() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my \"\"quoted\"\" table\"");
         rs.next();
@@ -122,7 +117,7 @@
      */
     public void testUpdateRowOnQuotedTable() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my \"\"quoted\"\" table\"");
         rs.next();
@@ -145,7 +140,7 @@
      */
     public void testDeleteRowOnQuotedTable() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my \"\"quoted\"\" table\"");
         rs.next();
@@ -167,7 +162,7 @@
      */    
     public void testInsertRowOnQuotedColumn() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my quoted columns\"");
         rs.next();
@@ -192,7 +187,7 @@
      */    
     public void testUpdateRowOnQuotedColumn() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my quoted columns\"");
         rs.next();
@@ -215,7 +210,7 @@
      */    
     public void testDeleteRowOnQuotedColumn() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my quoted columns\"");
         rs.next();
@@ -237,7 +232,7 @@
      */    
     public void testInsertRowOnQuotedSchema() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my \"\"quoted\"\" schema\"." +
                 "\"my quoted schema\"");
@@ -263,7 +258,7 @@
      */    
     public void testUpdateRowOnQuotedSchema() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my \"\"quoted\"\" schema\"." +
                 "\"my quoted schema\"");
@@ -287,7 +282,7 @@
      */    
     public void testDeleteRowOnQuotedSchema() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         rs = stmt.executeQuery("select * from \"my \"\"quoted\"\" schema\"." +
                 "\"my quoted schema\"");
@@ -310,7 +305,7 @@
      */    
     public void testInsertRowOnQuotedCursor() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         stmt.setCursorName("my \"\"\"\"quoted\"\"\"\" cursor\"\"");
         rs = stmt.executeQuery("select * from \"my table\"");
@@ -335,7 +330,7 @@
      */    
     public void testUpdateRowOnQuotedCursor() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         stmt.setCursorName("\"\"my quoted cursor");
         rs = stmt.executeQuery("select * from \"my table\"");
@@ -358,7 +353,7 @@
      */    
     public void testDeleteRowOnQuotedCursor() throws SQLException {
         ResultSet rs = null;
-        Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement stmt = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                 ResultSet.CONCUR_UPDATABLE);
         stmt.setCursorName("\"\"my quoted cursor\"\"");
         rs = stmt.executeQuery("select * from \"my table\"");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java?view=diff&rev=476316&r1=476315&r2=476316
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java
Fri Nov 17 13:11:59 2006
@@ -132,10 +132,8 @@
             ps.setString(10, "1");
             ps.executeUpdate();
             
-            rs = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
-                                     ResultSet.CONCUR_UPDATABLE).
-                executeQuery(SELECT_STMT);
-            rs.next();
+            ps.close();
+            stmt.close();
         } catch (SQLException e) {
             con.rollback();
             throw e;
@@ -150,14 +148,21 @@
     public void testUpdateString() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateString(i, "2");
             assertEquals("Expected rs.getDouble(" + i + 
                          ") to match updated value", 2, (int) rs.getDouble(i));
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreUpdated();
         
+        s.close();
     }
 
     /**
@@ -168,13 +173,21 @@
     public void testUpdateInt() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateInt(i, 2);
             assertEquals("Expected rs.getInt(" + i + 
                          ") to match updated value", 2, rs.getInt(i));
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreUpdated();
+        
+        s.close();
     }
 
     /**
@@ -185,13 +198,21 @@
     public void testUpdateLong() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateLong(i, 2L);
             assertEquals("Expected rs.getLong(" + i + 
                          ") to match updated value", 2L, rs.getLong(i));
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreUpdated();
+        
+        s.close();
     }
 
     /**
@@ -202,13 +223,21 @@
     public void testUpdateShort() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateShort(i, (short) 2);
             assertEquals("Expected rs.getShort(" + i + 
                          ") to match updated value", 2, (int) rs.getShort(i));
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreUpdated();
+        
+        s.close();
     }
     
     /**
@@ -219,13 +248,21 @@
     public void testUpdateFloat() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateFloat(i, 2.0f);
             assertEquals("Expected rs.getFloat(" + i + 
                          ") to match updated value", 2, (int) rs.getFloat(i));
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreUpdated();
+        
+        s.close();
     }
     
     /**
@@ -236,13 +273,22 @@
     public void testUpdateDouble() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        
+        rs.next();
+    	
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateDouble(i, 2.0);
             assertEquals("Expected rs.getDouble(" + i + 
                          ") to match updated value", 2, (int) rs.getDouble(i));
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreUpdated();
+        
+        s.close();
     }
 
     /**
@@ -253,6 +299,11 @@
     public void jdbc2testUpdateBigDecimal() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateBigDecimal(i, BigDecimal.valueOf(2L));
             assertEquals("Expected rs.getBigDecimal(" + i + 
@@ -260,7 +311,10 @@
                          rs.getBigDecimal(i).intValue());
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreUpdated();
+        
+        s.close();
     }
     
     /**
@@ -271,6 +325,11 @@
     public void testUpdateObjectWithNull() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         Object value = null;
         
         for (int i = 1; i <= COLUMNS; i++) {
@@ -281,7 +340,10 @@
                        rs.wasNull());
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreNull();
+        
+        s.close();
     }
 
     /**
@@ -292,6 +354,11 @@
     public void testUpdateNull() 
         throws SQLException
     {
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
+        rs.next();
+
         for (int i = 1; i <= COLUMNS; i++) {
             rs.updateNull(i);
             assertNull("Expected rs.getObject(" + i + ") to be null", 
@@ -300,7 +367,10 @@
                        rs.wasNull());
         }
         rs.updateRow();
+        rs.close();
         checkColumnsAreNull();
+        
+        s.close();
     }
 
     /**
@@ -311,11 +381,12 @@
     private void checkColumnsAreNull() 
         throws SQLException
     {
-        rs.close();
+
+        
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                                 ResultSet.CONCUR_READ_ONLY);
         
-        rs = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
-                                 ResultSet.CONCUR_READ_ONLY).
-            executeQuery(SELECT_STMT);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
         
         rs.next();
         
@@ -326,6 +397,7 @@
                        " to be true when data is SQL Null on column", 
                        rs.wasNull());
         }
+        s.close();
     }
 
     /**
@@ -337,11 +409,10 @@
     private void checkColumnsAreUpdated() 
         throws SQLException
     {
-        rs.close();
+         Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+                                 ResultSet.CONCUR_READ_ONLY);
         
-        rs = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
-                                 ResultSet.CONCUR_READ_ONLY).
-            executeQuery(SELECT_STMT);
+        ResultSet rs = s.executeQuery(SELECT_STMT);
         
         rs.next();
         for (int i = 1; i <= COLUMNS; i++) {
@@ -355,10 +426,8 @@
             assertEquals("Unexpected value from rs.getDouble( + " + i + ")",
                          expectedVal, actualVal);
         }
+        s.close();
     }
-    
-    /* Updatable ResultSet */
-    private ResultSet rs = null;
     
     /* Table name */
     private static final String TABLE_NAME = "MultiTypeTable";



Mime
View raw message