db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1081293 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/EmbedBlob.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
Date Mon, 14 Mar 2011 09:19:07 GMT
Author: kahatlen
Date: Mon Mar 14 09:19:06 2011
New Revision: 1081293

URL: http://svn.apache.org/viewvc?rev=1081293&view=rev
Log:
DERBY-5113: Intermittent failure in BlobSetMethodsTest on Java 7: Unable to set stream: 'Reached
EOF prematurely; expected 1,024, got 0.'

Blob.truncate() should copy bytes from the beginning of the stream.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=1081293&r1=1081292&r2=1081293&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Mon Mar 14 09:19:06
2011
@@ -1023,6 +1023,7 @@ final class EmbedBlob extends Connection
                     control.truncate (len);
                 }
                 else {
+                    setBlobPosition(0); // copy from the beginning
                     control = new LOBStreamControl (getEmbedConnection());
                     control.copyData (myStream, len);
                     myStream.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java?rev=1081293&r1=1081292&r2=1081293&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
Mon Mar 14 09:19:06 2011
@@ -3513,9 +3513,48 @@ public class BlobClob4BlobTest extends B
         
     }
 
+    /**
+     * Test that Blob.truncate() resets the position before copying the first
+     * N bytes into a new holder object. The bug is only triggered if the
+     * BLOB returned as a stream from store. That is, it must be larger than
+     * one page so that it's not materialized. Regression test for DERBY-5113.
+     */
+    public void testDerby5113() throws Exception {
+        setAutoCommit(false);
 
+        // Insert a BLOB larger than one page. Normally, this means larger
+        // than 32K, but the test tables use smaller pages, see comment in
+        // setUp().
+        PreparedStatement insert = prepareStatement(
+                "insert into testblob(a) values ?");
+        insert.setBinaryStream(1, new LoopingAlphabetStream(5000), 5000);
+        insert.executeUpdate();
 
+        // Retrieve the BLOB.
+        Statement s = createStatement();
+        ResultSet rs = s.executeQuery("select a from testblob");
+        rs.next();
+        Blob blob = rs.getBlob(1);
 
+        // Now call getBytes() so that the position in the underlying stream
+        // is changed.
+        byte[] bytes = blob.getBytes(1, 3000);
+        assertEquals(new LoopingAlphabetStream(3000),
+                     new ByteArrayInputStream(bytes));
+
+        // Truncate the BLOB. This used to fail with "Reached EOF prematurely"
+        // because truncate() didn't move the position in the underlying stream
+        // back to the beginning.
+        blob.truncate(4000);
+
+        // Verify that the BLOB was truncated correctly.
+        assertEquals(4000, blob.length());
+        bytes = blob.getBytes(1, 4000);
+        assertEquals(new LoopingAlphabetStream(4000),
+                     new ByteArrayInputStream(bytes));
+
+        rs.close();
+    }
         
     
     private static final String BLOB_BAD_POSITION = "XJ070";



Mime
View raw message