KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > largedata > lobLengthTests


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.largedata.lobLengthTests
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.tests.largedata;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.PreparedStatement JavaDoc;
26 import java.sql.Statement JavaDoc;
27 import java.sql.SQLException JavaDoc;
28
29 import java.io.ByteArrayInputStream JavaDoc;
30
31 import org.apache.derby.tools.ij;
32 import org.apache.derby.tools.JDBCDisplayUtil;
33
34 /**
35  * This test is part of the "largedata" suite because the use of
36  * very large LOBs can require extra memory for the server JVM.
37  * If this test was run as part of the normal 'derbyall' suite,
38  * it would require that any developer running the derbyall suite
39  * have a machine with a good deal of memory. And since _every_
40  * developer is encouraged to run 'derbyall' before submitting
41  * any patches, that would mean that _every_ developer would
42  * need a machine with lots of memory--and that's something we
43  * do NOT want to require.
44  *
45  * The specific JVM memory requirements for this test are set in the
46  * properties file for this test (lobLengthTests_app.properties).
47  * It started out as -mx128M -ms128M, but that could change in the
48  * future as more test cases are added to this class. If it's not
49  * at least 128M, the result will be OutOfMemory exceptions when
50  * running against Network Server.
51  */

52
53 public class lobLengthTests {
54
55     /**
56      * Create an instance of this class and do the test.
57      */

58     public static void main(String JavaDoc [] args)
59     {
60         new lobLengthTests().go(args);
61     }
62
63     /**
64      * Create a JDBC connection using the arguments passed
65      * in from the harness, and then run the LOB length
66      * tests.
67      * @param args Arguments from the harness.
68      */

69     public void go(String JavaDoc [] args)
70     {
71         try {
72
73             // use the ij utility to read the property file and
74
// make the initial connection.
75
ij.getPropertyArg(args);
76             Connection JavaDoc conn = ij.startJBMS();
77
78             // Add additional tests here.
79
derby_121Test(conn);
80
81         } catch (Exception JavaDoc e) {
82
83             System.out.println("FAIL -- Unexpected exception:");
84             e.printStackTrace(System.out);
85
86         }
87     }
88
89     /**
90      * There was a defect (DERBY-121) where the server and client
91      * were processing lob lengths incorrectly. For lob lengths
92      * that are represented by 24 or more bits, the server and
93      * Derby client were doing incorrect bit-shifting. This
94      * test makes sure that problem no longer occurs.
95      */

96     private static void derby_121Test(Connection JavaDoc conn)
97         throws SQLException JavaDoc
98     {
99         System.out.println("Testing server read of lob length > 2^24 bytes.");
100
101         boolean autoc = conn.getAutoCommit();
102         conn.setAutoCommit(false);
103
104         // Create a test table.
105
Statement JavaDoc st = conn.createStatement();
106         st.execute("create table lobTable100M(bl blob(100M))");
107
108         PreparedStatement JavaDoc pSt = conn.prepareStatement(
109             "insert into lobTable100M(bl) values (?)");
110
111         // The error we're testing occurs when the server
112
// is shifting bits 24 and higher of the lob's
113
// length (in bytes). This means that, in order
114
// to check for the error, we have to specify a
115
// lob length (in bytes) that requires at least
116
// 24 bits to represent. Thus for a blob the
117
// length of the test data must be specified as
118
// at least 2^24 bytes (hence the '16800000' in
119
// the next line).
120
byte [] bA = new byte[16800000];
121         pSt.setBinaryStream(1,
122             new java.io.ByteArrayInputStream JavaDoc(bA), bA.length);
123
124         // Now try the insert; this is where the server processes
125
// the lob length.
126
try {
127             pSt.execute();
128             System.out.println("PASS.");
129         } catch (Exception JavaDoc e) {
130             System.out.println("FAIL -- unexpected exception:");
131             e.printStackTrace(System.out);
132         }
133
134         // Clean up.
135
try {
136             st.execute("drop table lobTable100M");
137         } catch (SQLException JavaDoc se) {}
138
139         conn.setAutoCommit(autoc);
140         return;
141
142     }
143 }
144
Popular Tags