db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r596847 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/ functionTests/tests/lang/ junit/
Date Tue, 20 Nov 2007 22:12:03 GMT
Author: djd
Date: Tue Nov 20 14:12:02 2007
New Revision: 596847

URL: http://svn.apache.org/viewvc?rev=596847&view=rev
Log:
Fix tearDown method for jdbcapi.ConcurrencyTest to ensure it commits the DROP TABLE it executes.
Add a utility method for junit tests that want to drop a table regardless of if it exists
or not

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/SURDataModelSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.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?rev=596847&r1=596846&r2=596847&view=diff
==============================================================================
--- 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
Tue Nov 20 14:12:02 2007
@@ -58,14 +58,10 @@
     
     public void tearDown() throws Exception 
     {
-        try {
-            rollback();
-            Statement dropStatement = createStatement();
-            dropStatement.execute("drop table t1");
-            dropStatement.close();
-        } catch (SQLException e) {
-            printStackTrace(e); // Want to propagate the real exception.
-        }
+        rollback();
+        dropTable("T1");
+        commit();
+
         super.tearDown();
     }
     

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java?rev=596847&r1=596846&r2=596847&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
Tue Nov 20 14:12:02 2007
@@ -62,27 +62,10 @@
                                        int records) 
         throws SQLException
     {
-        Statement statement = con.createStatement();
-        
-        try { 
-            statement.execute("drop table t1"); 
-        } catch (SQLException e) {
-            assertEquals("'drop table t1' failed with unexpected SQL State",
-                         TABLE_EXISTS_SQL_STATE, e.getSQLState());
-            
-            // The net framework does not give any valuable error code
-            if (!TestConfiguration.getCurrent().getJDBCClient().isEmbedded()) {
-                
-                assertEquals("'drop table t1' failed with unexpected error code",
-                             NET_ERROR, e.getErrorCode());
-            } else {
-                assertEquals("'drop table t1' failed with unexpected error code",
-                             TABLE_EXISTS_ERRORCODE, e.getErrorCode());
-            }
-            
-        };
         
+        BaseJDBCTestCase.dropTable(con, "T1");
         
+        Statement statement = con.createStatement();     
         
         /** Create the table */
         statement.execute(model.getCreateTableStatement());
@@ -253,11 +236,4 @@
     static void printStackTrace(Throwable t) {
         BaseJDBCTestCase.printStackTrace(t);
     }
-    
-    /**
-     * Error codes and SQL state
-     */
-    private final static String TABLE_EXISTS_SQL_STATE = "42Y55";
-    private final static int TABLE_EXISTS_ERRORCODE = 20000;
-    private final static int NET_ERROR = -1; 
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java?rev=596847&r1=596846&r2=596847&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TableFunctionTest.java
Tue Nov 20 14:12:02 2007
@@ -1764,21 +1764,6 @@
         catch( SQLException se) {}
     }
 
-    /**
-     * Drop a table so that we can recreate it.
-     */
-    private void    dropTable( String tableName )
-        throws Exception
-    {
-        // swallow the "object doesn't exist" diagnostic
-        try {
-            PreparedStatement   ps = prepareStatement( "drop table " + tableName );
-
-            ps.execute();
-            ps.close();
-        }
-        catch( SQLException se) {}
-    }
 
     /**
      * Assert that the ResultSet returns the desired rows.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=596847&r1=596846&r2=596847&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Tue
Nov 20 14:12:02 2007
@@ -818,6 +818,42 @@
     }
 
     /**
+     * Execute a DROP TABLE command using the passed in tableName as-is
+     * and the default connection.
+     * If the DROP TABLE fails because the table does not exist then
+     * the exception is ignored.
+     * @param tableName Table to be dropped.
+     * @throws SQLException
+     */
+    public final void dropTable(String tableName) throws SQLException
+    {
+       dropTable(getConnection(), tableName);
+    }
+    
+    /**
+     * Execute a DROP TABLE command using the passed in tableName as-is.
+     * If the DROP TABLE fails because the table does not exist then
+     * the exception is ignored.
+     * @param conn Connection to execute the DROP TABLE
+     * @param tableName Table to be dropped.
+     * @throws SQLException
+     */
+    public static void dropTable(Connection conn, String tableName) throws SQLException
+    {
+        Statement statement = conn.createStatement();
+        String dropSQL = "DROP TABLE " + tableName;
+        try { 
+            
+            statement.executeUpdate(dropSQL); 
+        } catch (SQLException e) {
+            assertSQLState("42Y55", e);
+        }
+        finally {
+            statement.close();
+        }
+    }
+
+    /**
      * Assert that the query fails (either in compilation,
      * execution, or retrieval of results--doesn't matter)
      * and throws a SQLException with the expected state.



Mime
View raw message