You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by an...@apache.org on 2006/07/18 11:58:16 UTC

svn commit: r423033 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi: BLOBDataModelSetup.java BLOBTest.java

Author: andreask
Date: Tue Jul 18 02:58:14 2006
New Revision: 423033

URL: http://svn.apache.org/viewvc?rev=423033&view=rev
Log:
extended tests created in DERBY-1477 with four new testcases which uses projection in the select statements. The tests are for verifying that we do not get OutOfMemory issues when reading and updating BLOBS

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java?rev=423033&r1=423032&r2=423033&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java Tue Jul 18 02:58:14 2006
@@ -73,8 +73,7 @@
             ("INSERT INTO " + tableName + "(val, length, data) VALUES (?,?, ?)");
         
         // Insert 10 records with size of 1MB
-        final int size = 1024*1024;
-        for (int i = 0; i < 10; i++) {
+        for (int i = 0; i < regularBlobs; i++) {
             final int val = i;
             final InputStream stream = new TestInputStream(size, val);
             preparedStatement.setInt(1, val);
@@ -84,14 +83,11 @@
         }
         
         // Insert 1 record with size of 64 MB
-        final int bigsize = 1024 * 1024 * 64;
-        final int val = 11;
-        
-        BaseJDBCTestCase.println("Insert BLOB with size = " + bigsize);
-        preparedStatement.setInt(1, val);
-        preparedStatement.setInt(2, bigsize);
-        final InputStream stream = new TestInputStream(bigsize, val);
-        preparedStatement.setBinaryStream(3, stream, bigsize);
+        BaseJDBCTestCase.println("Insert BLOB with size = " + bigSize);
+        preparedStatement.setInt(1, bigVal);
+        preparedStatement.setInt(2, bigSize);
+        final InputStream stream = new TestInputStream(bigSize, bigVal);
+        preparedStatement.setBinaryStream(3, stream, bigSize);
         
         BaseJDBCTestCase.println("Execute update");
         preparedStatement.executeUpdate();
@@ -128,6 +124,18 @@
     {
         return tableName;
     }
+    
+    /** Size of regular Blobs (currently 1MB) */
+    final static int size = 1024 * 1024;
+    
+    /** Number of regular Blobs */
+    final static int regularBlobs = 10;
+
+    /** Size of big record (currently 64 MB) */
+    final static int bigSize = 64 * 1024 * 1024;
+    
+    /** Val for big  record */
+    final static int bigVal = regularBlobs + 1;
     
     /** JDBC Connection */        
     private Connection con;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java?rev=423033&r1=423032&r2=423033&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java Tue Jul 18 02:58:14 2006
@@ -94,8 +94,8 @@
         
         while (rs.next()) {
             println("Next");
-            final int size = rs.getInt(2);
-            if (size>1024*1024) break;
+            final int val = rs.getInt(1);
+            if (val == BLOBDataModelSetup.bigVal) break;
         }
         
         final int newVal = rs.getInt(1) + 11;
@@ -107,7 +107,7 @@
 
     /**
      * Tests updating a Blob from a scollable resultset, using
-     * result set update methods.
+     * positioned updates.
      * @exception SQLException causes test to fail with error
      * @exception IOException causes test to fail with error
      */
@@ -137,7 +137,7 @@
 
     /**
      * Tests updating a Blob from a forward only resultset, using
-     * result set update methods.
+     * methods.
      * @exception SQLException causes test to fail with error
      * @exception IOException causes test to fail with error
      */
@@ -150,20 +150,136 @@
         final ResultSet rs = 
             stmt.executeQuery("SELECT * from " + 
                               BLOBDataModelSetup.getBlobTableName());
-        
         while (rs.next()) {
             println("Next");
-            final int size = rs.getInt(2);
-            if (size>1024*1024) break;
+            final int val = rs.getInt(1);
+            if (val == BLOBDataModelSetup.bigVal) break;
         }
         
         final int newVal = rs.getInt(1) + 11;
         final int newSize = rs.getInt(2) / 2;
         testUpdateBlobWithPositionedUpdate(rs, newVal, newSize);
         
+        rs.close();
+    }
+
+    /**
+     * Tests updating a Blob from a scollable resultset produced by a
+     * select query with projection. Updates are made using
+     * result set update methods.
+     * @exception SQLException causes test to fail with error
+     * @exception IOException causes test to fail with error
+     */
+    public void testUpdateBlobFromScrollableResultSetWithProjectUsingResultSetMethods()
+        throws SQLException, IOException
+    {
+        final Statement stmt = 
+            con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                                ResultSet.CONCUR_UPDATABLE);
+        final ResultSet rs = 
+            stmt.executeQuery("SELECT data,val,length from " + 
+                              BLOBDataModelSetup.getBlobTableName());
+        println("Last");
+        rs.last();
+        
+        final int newVal = rs.getInt(2) + 11;
+        final int newSize = rs.getInt(3) / 2;
+        testUpdateBlobWithResultSetMethods(rs, newVal, newSize);
+        
+        println("Verify updated blob using result set");
+        verifyBlob(newVal, newSize, rs.getBlob(1));
         
         rs.close();
     }
+
+    /**
+     * Tests updating a Blob from a forward only resultset, produced by 
+     * a select query with projection. Updates are made using
+     * result set update methods.
+     * @exception SQLException causes test to fail with error
+     * @exception IOException causes test to fail with error
+     */
+    public void testUpdateBlobFromForwardOnlyResultSetWithProjectUsingResultSetMethods()
+        throws SQLException, IOException
+    {
+        final Statement stmt = 
+            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                                ResultSet.CONCUR_UPDATABLE);
+        final ResultSet rs = 
+            stmt.executeQuery("SELECT data,val,length from " + 
+                              BLOBDataModelSetup.getBlobTableName());
+        
+        while (rs.next()) {
+            println("Next");
+            final int val = rs.getInt("VAL");
+            if (val == BLOBDataModelSetup.bigVal) break;
+        }
+        
+        final int newVal = rs.getInt("VAL") + 11;
+        final int newSize = BLOBDataModelSetup.bigSize / 2;
+        testUpdateBlobWithResultSetMethods(rs, newVal, newSize);
+        
+        rs.close();
+    }
+
+    /**
+     * Tests updating a Blob from a scollable resultset, produced by 
+     * a select query with projection. Updates are made using
+     * positioned updates
+     * @exception SQLException causes test to fail with error
+     * @exception IOException causes test to fail with error
+     */
+    public void testUpdateBlobFromScrollableResultSetWithProjectUsingPositionedUpdates()
+        throws SQLException, IOException
+    {
+        final Statement stmt = 
+            con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                                ResultSet.CONCUR_UPDATABLE);
+        final ResultSet rs = 
+            stmt.executeQuery("SELECT data from " + 
+                              BLOBDataModelSetup.getBlobTableName() + 
+                              " WHERE val= " + BLOBDataModelSetup.bigVal);
+        println("Last");
+        rs.last();
+        
+        final int newVal = BLOBDataModelSetup.bigVal * 2;
+        final int newSize = BLOBDataModelSetup.bigSize / 2;
+        testUpdateBlobWithPositionedUpdate(rs, newVal, newSize);
+
+        rs.relative(0); // Necessary after a positioned update
+        
+        println("Verify updated blob using result set");
+        verifyBlob(newVal, newSize, rs.getBlob("DATA"));
+        
+        rs.close();
+    }
+
+    /**
+     * Tests updating a Blob from a forward only resultset, produced by 
+     * a select query with projection. Updates are made using
+     * positioned updates.
+     * @exception SQLException causes test to fail with error
+     * @exception IOException causes test to fail with error
+     */
+    public void testUpdateBlobFromForwardOnlyResultSetWithProjectUsingPositionedUpdates()
+        throws SQLException, IOException
+    {
+        final Statement stmt = 
+            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                                ResultSet.CONCUR_UPDATABLE);
+        final ResultSet rs = 
+            stmt.executeQuery("SELECT data from " + 
+                              BLOBDataModelSetup.getBlobTableName() + 
+                              " WHERE val = " + BLOBDataModelSetup.bigVal);
+        rs.next();
+        
+        final int newVal =  BLOBDataModelSetup.bigVal * 2;
+        final int newSize = BLOBDataModelSetup.bigSize / 2;
+        testUpdateBlobWithPositionedUpdate(rs, newVal, newSize);
+        
+        rs.close();
+    }
+    
     
     /**
      * Tests updating the Blob using result set update methods.
@@ -178,17 +294,17 @@
                                                     final int newSize) 
         throws SQLException, IOException
     {
-        int val = rs.getInt(1);
-        int size = rs.getInt(2);
+        int val = rs.getInt("VAL");
+        int size = rs.getInt("LENGTH");
         println("VerifyBlob");
-        verifyBlob(val, size, rs.getBlob(3));
+        verifyBlob(val, size, rs.getBlob("DATA"));
         
         println("UpdateBlob");
         final TestInputStream newStream = new TestInputStream(newSize, newVal);
         
-        rs.updateInt(1, newVal);
-        rs.updateInt(2, newSize);
-        rs.updateBinaryStream(3, newStream, newSize);
+        rs.updateInt("VAL", newVal);
+        rs.updateInt("LENGTH", newSize);
+        rs.updateBinaryStream("DATA", newStream, newSize);
         rs.updateRow();
         
         println("Verify updated blob with another query");