001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.largedata.lobLengthTests
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.functionTests.tests.largedata;
023:
024: import java.sql.Connection;
025: import java.sql.PreparedStatement;
026: import java.sql.Statement;
027: import java.sql.SQLException;
028:
029: import java.io.ByteArrayInputStream;
030:
031: import org.apache.derby.tools.ij;
032: import org.apache.derby.tools.JDBCDisplayUtil;
033:
034: /**
035: * This test is part of the "largedata" suite because the use of
036: * very large LOBs can require extra memory for the server JVM.
037: * If this test was run as part of the normal 'derbyall' suite,
038: * it would require that any developer running the derbyall suite
039: * have a machine with a good deal of memory. And since _every_
040: * developer is encouraged to run 'derbyall' before submitting
041: * any patches, that would mean that _every_ developer would
042: * need a machine with lots of memory--and that's something we
043: * do NOT want to require.
044: *
045: * The specific JVM memory requirements for this test are set in the
046: * properties file for this test (lobLengthTests_app.properties).
047: * It started out as -mx128M -ms128M, but that could change in the
048: * future as more test cases are added to this class. If it's not
049: * at least 128M, the result will be OutOfMemory exceptions when
050: * running against Network Server.
051: */
052:
053: public class lobLengthTests {
054:
055: /**
056: * Create an instance of this class and do the test.
057: */
058: public static void main(String[] args) {
059: new lobLengthTests().go(args);
060: }
061:
062: /**
063: * Create a JDBC connection using the arguments passed
064: * in from the harness, and then run the LOB length
065: * tests.
066: * @param args Arguments from the harness.
067: */
068: public void go(String[] args) {
069: try {
070:
071: // use the ij utility to read the property file and
072: // make the initial connection.
073: ij.getPropertyArg(args);
074: Connection conn = ij.startJBMS();
075:
076: // Add additional tests here.
077: derby_121Test(conn);
078:
079: } catch (Exception e) {
080:
081: System.out.println("FAIL -- Unexpected exception:");
082: e.printStackTrace(System.out);
083:
084: }
085: }
086:
087: /**
088: * There was a defect (DERBY-121) where the server and client
089: * were processing lob lengths incorrectly. For lob lengths
090: * that are represented by 24 or more bits, the server and
091: * Derby client were doing incorrect bit-shifting. This
092: * test makes sure that problem no longer occurs.
093: */
094: private static void derby_121Test(Connection conn)
095: throws SQLException {
096: System.out
097: .println("Testing server read of lob length > 2^24 bytes.");
098:
099: boolean autoc = conn.getAutoCommit();
100: conn.setAutoCommit(false);
101:
102: // Create a test table.
103: Statement st = conn.createStatement();
104: st.execute("create table lobTable100M(bl blob(100M))");
105:
106: PreparedStatement pSt = conn
107: .prepareStatement("insert into lobTable100M(bl) values (?)");
108:
109: // The error we're testing occurs when the server
110: // is shifting bits 24 and higher of the lob's
111: // length (in bytes). This means that, in order
112: // to check for the error, we have to specify a
113: // lob length (in bytes) that requires at least
114: // 24 bits to represent. Thus for a blob the
115: // length of the test data must be specified as
116: // at least 2^24 bytes (hence the '16800000' in
117: // the next line).
118: byte[] bA = new byte[16800000];
119: pSt.setBinaryStream(1, new java.io.ByteArrayInputStream(bA),
120: bA.length);
121:
122: // Now try the insert; this is where the server processes
123: // the lob length.
124: try {
125: pSt.execute();
126: System.out.println("PASS.");
127: } catch (Exception e) {
128: System.out.println("FAIL -- unexpected exception:");
129: e.printStackTrace(System.out);
130: }
131:
132: // Clean up.
133: try {
134: st.execute("drop table lobTable100M");
135: } catch (SQLException se) {
136: }
137:
138: conn.setAutoCommit(autoc);
139: return;
140:
141: }
142: }
|