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 da...@apache.org on 2010/01/29 17:10:57 UTC
svn commit: r904538 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests:
tests/jdbcapi/BLOBTest.java tests/memory/BlobMemTest.java
tests/memory/ClobMemTest.java util/streams/LoopingAlphabetReader.java
Author: dag
Date: Fri Jan 29 16:10:56 2010
New Revision: 904538
URL: http://svn.apache.org/viewvc?rev=904538&view=rev
Log:
DERBY-4477 Selecting / projecting a column whose value is represented by a stream more than once fails
Patch derby-4477-lowmem-2, which adds test cases to check that lobs
are not materialized when large, for the use cases covered by this
issue. The test cases are added to the lowmem suite, which is not not
part of the regular suites.All. This commit is preparatory in that the
lobs are still small, so these changes should be revisited to change
their sizes when the cloning handles materialization properly, cf
DERBY-3650 and DERBY-4520.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/ClobMemTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/streams/LoopingAlphabetReader.java
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=904538&r1=904537&r2=904538&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 Fri Jan 29 16:10:56 2010
@@ -390,6 +390,9 @@
* Tests that a lob can be safely occur multiple times in a SQL select.
* <p/>
* See DERBY-4477.
+ * <p/>
+ * @see org.apache.derbyTesting.functionTests.tests.memory.BlobMemTest#testDerby4477_3645_3646_Repro_lowmem
+ * @see org.apache.derbyTesting.functionTests.tests.memory.ClobMemTest#testDerby4477_3645_3646_Repro_lowmem_clob
*/
public void testDerby4477_3645_3646_Repro() throws SQLException, IOException {
setAutoCommit(false);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java?rev=904538&r1=904537&r2=904538&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/BlobMemTest.java Fri Jan 29 16:10:56 2010
@@ -27,7 +27,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-
import java.sql.PreparedStatement;
import java.util.Arrays;
import java.util.Properties;
@@ -38,6 +37,7 @@
import org.apache.derbyTesting.functionTests.harness.JavaVersionHolder;
import org.apache.derbyTesting.functionTests.tests.lang.SimpleTest;
import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream;
+import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
import org.apache.derbyTesting.junit.JDBC;
@@ -212,6 +212,78 @@
return new SystemPropertyTestSetup(suite,p);
}
-
+ /**
+ * Tests that a blob can be safely occur multiple times in a SQL select and
+ * test that large objects streams are not being materialized when cloned.
+ * <p/>
+ * See DERBY-4477.
+ * @see org.apache.derbyTesting.functionTests.tests.jdbcapi.BLOBTest#testDerby4477_3645_3646_Repro
+ * @see ClobMemTest#testDerby4477_3645_3646_Repro_lowmem_clob
+ */
+ public void testDerby4477_3645_3646_Repro_lowmem()
+ throws SQLException, IOException {
+
+ setAutoCommit(false);
+
+ Statement s = createStatement();
+ // int blobsize = LONG_BLOB_LENGTH;
+ int blobsize = 35000;
+
+ s.executeUpdate(
+ "CREATE TABLE T_MAIN(" +
+ "ID INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
+ "V BLOB(" + blobsize + ") )");
+
+ PreparedStatement ps = prepareStatement(
+ "INSERT INTO T_MAIN(V) VALUES (?)");
+
+ int blobLen = blobsize;
+ LoopingAlphabetStream stream = new LoopingAlphabetStream(blobLen);
+ ps.setBinaryStream(1, stream, blobLen);
+
+ ps.executeUpdate();
+ ps.close();
+
+ s.executeUpdate("CREATE TABLE T_COPY ( V1 BLOB(" + blobsize +
+ "), V2 BLOB(" + blobsize + "))");
+
+ // This failed in the repro for DERBY-3645 solved as part of
+ // DERBY-4477:
+ s.executeUpdate("INSERT INTO T_COPY SELECT V, V FROM T_MAIN");
+
+ // Check that the two results are identical:
+ ResultSet rs = s.executeQuery("SELECT * FROM T_COPY");
+ rs.next();
+ InputStream is = rs.getBinaryStream(1);
+
+ stream.reset();
+ assertEquals(stream, is);
+
+ is = rs.getBinaryStream(2);
+
+ stream.reset();
+ assertEquals(stream, is);
+ rs.close();
+ // This failed in the repro for DERBY-3646 solved as part of
+ // DERBY-4477 (repro slightly rewoked here):
+ rs = s.executeQuery("SELECT 'I', V, ID, V from T_MAIN");
+ rs.next();
+
+ is = rs.getBinaryStream(2);
+ stream.reset();
+ assertEquals(stream, is);
+
+ is = rs.getBinaryStream(4);
+ stream.reset();
+ assertEquals(stream, is);
+
+ // clean up
+ stream.close();
+ is.close();
+ s.close();
+ rs.close();
+
+ rollback();
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/ClobMemTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/ClobMemTest.java?rev=904538&r1=904537&r2=904538&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/ClobMemTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/ClobMemTest.java Fri Jan 29 16:10:56 2010
@@ -190,5 +190,78 @@
}
+ /**
+ * Tests that a clob can be safely occur multiple times in a SQL
+ * select and test that large objects streams are not being
+ * materialized when cloned. Same as
+ * testDerby4477_3645_3646_Repro_lowmem, but now using clob rather
+ * than blob.
+ * @see BlobMemTest#testDerby4477_3645_3646_Repro_lowmem
+ */
+ public void testDerby4477_3645_3646_Repro_lowmem_clob()
+ throws SQLException, IOException {
+ setAutoCommit(false);
+
+ Statement s = createStatement();
+ // int clobsize = LONG_BLOB_LENGTH;
+ int clobsize = 35000;
+
+ s.executeUpdate(
+ "CREATE TABLE T_MAIN(" +
+ "ID INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
+ "V CLOB(" + clobsize + ") )");
+
+ PreparedStatement ps = prepareStatement(
+ "INSERT INTO T_MAIN(V) VALUES (?)");
+
+ int blobLen = clobsize;
+ LoopingAlphabetReader stream = new LoopingAlphabetReader(blobLen);
+ ps.setCharacterStream(1, stream, blobLen);
+
+ ps.executeUpdate();
+ ps.close();
+
+ s.executeUpdate("CREATE TABLE T_COPY ( V1 CLOB(" + clobsize +
+ "), V2 CLOB(" + clobsize + "))");
+
+ // This failed in the repro for DERBY-3645 solved as part of
+ // DERBY-4477:
+ s.executeUpdate("INSERT INTO T_COPY SELECT V, V FROM T_MAIN");
+
+ // Check that the two results are identical:
+ ResultSet rs = s.executeQuery("SELECT * FROM T_COPY");
+ rs.next();
+ Reader is = rs.getCharacterStream(1);
+
+ stream.reopen();
+ assertEquals(stream, is);
+
+ is = rs.getCharacterStream(2);
+
+ stream.reopen();
+ assertEquals(stream, is);
+ rs.close();
+
+ // This failed in the repro for DERBY-3646 solved as part of
+ // DERBY-4477 (repro slightly rewoked here):
+ rs = s.executeQuery("SELECT 'I', V, ID, V from T_MAIN");
+ rs.next();
+
+ is = rs.getCharacterStream(2);
+ stream.reopen();
+ assertEquals(stream, is);
+
+ is = rs.getCharacterStream(4);
+ stream.reopen();
+ assertEquals(stream, is);
+
+ // clean up
+ stream.close();
+ is.close();
+ s.close();
+ rs.close();
+
+ rollback();
+ }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/streams/LoopingAlphabetReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/streams/LoopingAlphabetReader.java?rev=904538&r1=904537&r2=904538&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/streams/LoopingAlphabetReader.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/streams/LoopingAlphabetReader.java Fri Jan 29 16:10:56 2010
@@ -177,6 +177,15 @@
}
/**
+ * Reopen the stream.
+ */
+ public void reopen()
+ throws IOException {
+ this.closed = false;
+ reset();
+ }
+
+ /**
* Return remaining characters in the stream.
*/
public int available() {