Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 34681 invoked from network); 2 Nov 2006 00:56:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Nov 2006 00:56:59 -0000 Received: (qmail 54716 invoked by uid 500); 2 Nov 2006 00:57:10 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 54677 invoked by uid 500); 2 Nov 2006 00:57:10 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 54666 invoked by uid 99); 2 Nov 2006 00:57:10 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Nov 2006 16:57:10 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Nov 2006 16:56:58 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id EF12E1A984D; Wed, 1 Nov 2006 16:56:33 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r470152 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ suites/ tests/jdbcapi/ Date: Thu, 02 Nov 2006 00:56:33 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061102005633.EF12E1A984D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: djd Date: Wed Nov 1 16:56:32 2006 New Revision: 470152 URL: http://svn.apache.org/viewvc?view=rev&rev=470152 Log: DERBY-2005 converts the test jdbcapi/Stream.java to Junit. Contributed by Fernanda Pizzorno fernanda.pizzorno@sun.com Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StreamTest.java (with props) Removed: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/Stream.out db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Stream.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/embeddedUseprocess.exclude db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude?view=diff&rev=470152&r1=470151&r2=470152 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClientUseprocess.exclude Wed Nov 1 16:56:32 2006 @@ -9,7 +9,6 @@ # jdbcapi/checkDriver.java subtest createdbwithspaces fails, probably expecting different dir # jdbcapi/*sers* these tests log on to wombat with different permissions and users # test could possibly be rewritten to use another database -# jdbcapi/Stream.java fails ?? don't know why this fails # junitTests/derbyNet/CompatibilityTest.java - exits the suite # jdbcapi/xaSimplePositive.sql - needs more props, getting nullPointer accessing derby.log # jdbcapi/xaStateTran.sql - needs more props, getting nullPointer accessing derby.log @@ -44,7 +43,6 @@ jdbcapi/users2.sql jdbcapi/secureUsers.sql jdbcapi/secureUsers1.sql -jdbcapi/Stream.java junitTests/derbyNet/CompatibilityTest.java jdbcapi/xaSimplePositive.sql jdbcapi/xaStateTran.sql Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/embeddedUseprocess.exclude URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/embeddedUseprocess.exclude?view=diff&rev=470152&r1=470151&r2=470152 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/embeddedUseprocess.exclude (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/embeddedUseprocess.exclude Wed Nov 1 16:56:32 2006 @@ -14,7 +14,6 @@ # jdbcapi/SURTest.junit - fails with severe errors. # jdbcapi/UpdateXXXTest.junit - fails with NullPointerExceptions # jdbcapi/rsgetXXXcolumnNames.java - fails with an error indicating wombat already exists -# jdbcapi/Stream.java - fails with an error indicating wombat already exists # jdbcapi/HoldabilityTest.junit jdbcapi/bestrowidentifier.sql @@ -27,4 +26,3 @@ jdbcapi/SURTest.junit jdbcapi/UpdateXXXTest.junit jdbcapi/rsgetXXXcolumnNames.java -jdbcapi/Stream.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall?view=diff&rev=470152&r1=470151&r2=470152 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall Wed Nov 1 16:56:32 2006 @@ -17,5 +17,4 @@ jdbcapi/prepStmtNull.java jdbcapi/testRelative.java jdbcapi/rsgetXXXcolumnNames.java -jdbcapi/Stream.java jdbcapi/SURTest_ij.sql Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StreamTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StreamTest.java?view=auto&rev=470152 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StreamTest.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StreamTest.java Wed Nov 1 16:56:32 2006 @@ -0,0 +1,190 @@ +/* + +Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.StreamTest + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + */ + +package org.apache.derbyTesting.functionTests.tests.jdbcapi; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; + +import java.sql.*; +import junit.framework.*; +import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader; +import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream; + +import org.apache.derbyTesting.junit.BaseJDBCTestCase; +import org.apache.derbyTesting.junit.TestConfiguration; + +/** + * Tests of ResultSet streams + */ +public class StreamTest extends BaseJDBCTestCase { + + /** Creates a new instance of StreamTest */ + public StreamTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + getConnection().setAutoCommit(false); + } + + protected void tearDown() throws Exception { + rollback(); + super.tearDown(); + } + + public static Test suite() { + return TestConfiguration.defaultSuite(StreamTest.class); + } + + /** + * Tests calling ResultSet.getBinaryStream() twice in the same column + * using a 512 bytes blob + */ + public void testGetStreamTwiceSmallBlob() throws SQLException, IOException { + insertBlobData(512); + runGetStreamTwiceTest(); + } + + /** + * Tests calling ResultSet.getBinaryStream() twice in the same column + * using a 512K bytes blob + */ + public void testGetStreamTwiceLargeBlob() throws SQLException, IOException { + insertBlobData(512 * 1024); + runGetStreamTwiceTest(); + } + + /** + * Tests calling ResultSet.getCharacterStream() twice in the same column + * using a 512 characters clob + */ + public void testGetReaderTwiceSmallClob() throws SQLException, IOException { + insertClobData(512); + runGetReaderTwiceTest(); + } + + /** + * Tests calling ResultSet.getCharacterStream() twice in the same column + * using a 512K characters clob + */ + public void testGetReaderTwiceLargeClob() throws SQLException, IOException { + insertClobData(512 * 1024); + runGetReaderTwiceTest(); + } + + + private void insertBlobData(int blobSize) throws SQLException { + Statement stmt = createStatement(); + stmt.executeUpdate("CREATE TABLE testLob " + + " (b blob(" + blobSize + "))"); + stmt.close(); + PreparedStatement ps = + prepareStatement("insert into testLob values(?)"); + InputStream stream = new LoopingAlphabetStream(blobSize); + ps.setBinaryStream(1, stream, blobSize); + ps.executeUpdate(); + ps.close(); + } + + private void insertClobData(int clobSize) throws SQLException { + Statement stmt = createStatement(); + stmt.executeUpdate("CREATE TABLE testLob " + + " (c clob(" + clobSize + "))"); + stmt.close(); + PreparedStatement ps = + prepareStatement("insert into testLob values(?)"); + Reader reader = new LoopingAlphabetReader(clobSize); + ps.setCharacterStream(1, reader, clobSize); + ps.executeUpdate(); + ps.close(); + } + + private void runGetStreamTwiceTest() throws SQLException, IOException { + + InputStream is = null; + + Statement st = createStatement(); + ResultSet rs = st.executeQuery("select * from testLob"); + assertTrue("FAIL - row not found", rs.next()); + + println("get stream from testLob ..."); + is = rs.getBinaryStream(1); + is.close(); + + try{ + println("get stream from testLob again ..."); + is = rs.getBinaryStream(1); + fail("FAIL - Expected exception did not happen."); + + } catch(SQLException se) { + assertSQLState(LANG_STREAM_RETRIEVED_ALREADY, se); + } finally { + if (st != null) { + st.close(); + } + + if (rs != null) { + rs.close(); + } + + if (is != null) { + is.close(); + } + } + } + + public void runGetReaderTwiceTest() throws SQLException, IOException { + Reader reader = null; + + Statement st = createStatement(); + ResultSet rs = st.executeQuery( "select * from testLob"); + assertTrue("FAIL - row not found", rs.next()); + + println("get reader from testLob ..."); + reader = rs.getCharacterStream(1); + reader.close(); + try { + println("get reader from testLob again ..."); + reader = rs.getCharacterStream(1); + fail("FAIL - Expected exception did not happen."); + + } catch(SQLException se) { + assertSQLState(LANG_STREAM_RETRIEVED_ALREADY, se); + } finally { + if (st != null) { + st.close(); + } + + if (rs != null) { + rs.close(); + } + + if (reader != null) { + reader.close(); + } + } + } + + private static final String LANG_STREAM_RETRIEVED_ALREADY = "XCL18"; + +} \ No newline at end of file Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StreamTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?view=diff&rev=470152&r1=470151&r2=470152 ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java Wed Nov 1 16:56:32 2006 @@ -59,6 +59,7 @@ suite.addTest(ResultSetCloseTest.suite()); suite.addTest(BlobClob4BlobTest.suite()); suite.addTest(CharacterStreamsTest.suite()); + suite.addTest(StreamTest.suite()); if (JDBC.vmSupportsJDBC3()) {