001: /**
002:
003: * JDBM LICENSE v1.00
004:
005: *
006:
007: * Redistribution and use of this software and associated documentation
008:
009: * ("Software"), with or without modification, are permitted provided
010:
011: * that the following conditions are met:
012:
013: *
014:
015: * 1. Redistributions of source code must retain copyright
016:
017: * statements and notices. Redistributions must also contain a
018:
019: * copy of this document.
020:
021: *
022:
023: * 2. Redistributions in binary form must reproduce the
024:
025: * above copyright notice, this list of conditions and the
026:
027: * following disclaimer in the documentation and/or other
028:
029: * materials provided with the distribution.
030:
031: *
032:
033: * 3. The name "JDBM" must not be used to endorse or promote
034:
035: * products derived from this Software without prior written
036:
037: * permission of Cees de Groot. For written permission,
038:
039: * please contact cg@cdegroot.com.
040:
041: *
042:
043: * 4. Products derived from this Software may not be called "JDBM"
044:
045: * nor may "JDBM" appear in their names without prior written
046:
047: * permission of Cees de Groot.
048:
049: *
050:
051: * 5. Due credit should be given to the JDBM Project
052:
053: * (http://jdbm.sourceforge.net/).
054:
055: *
056:
057: * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
058:
059: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
060:
061: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
062:
063: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
064:
065: * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
066:
067: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
068:
069: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
070:
071: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
072:
073: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
074:
075: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
076:
077: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
078:
079: * OF THE POSSIBILITY OF SUCH DAMAGE.
080:
081: *
082:
083: * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
084:
085: * Contributions are Copyright (C) 2000 by their associated contributors.
086:
087: *
088:
089: */package jdbm.btree;
090:
091: import jdbm.RecordManager;
092:
093: import jdbm.RecordManagerFactory;
094:
095: import jdbm.helper.StringComparator;
096:
097: import jdbm.recman.TestRecordFile;
098:
099: import jdbm.btree.BTree;
100:
101: import java.io.IOException;
102:
103: import junit.framework.*;
104:
105: /**
106:
107: * Contributed test case for BTree by Christof Dallermassl (cdaller@iicm.edu):
108:
109: *
110:
111: * -= quote from original message posted on jdbm-general =-
112:
113: * <pre>
114:
115: *
116:
117: * I tried to insert a couple of elements into a BTree and then remove
118:
119: * them one by one. After a number or removals, there is always (if more
120:
121: * than 20 elements in btree) a java.io.StreamCorruptedException thrown.
122:
123: *
124:
125: * The strange thing is, that on 50 elements, the exception is thrown
126:
127: * after removing 22, on 200 it is thrown after 36, on 1000 it is thrown
128:
129: * after 104, on 10000 it is thrown after 1003....
130:
131: *
132:
133: * The full stackTrace is here:
134:
135: * ---------------------- snip ------- snap -------------------------
136:
137: * java.io.StreamCorruptedException: Caught EOFException while reading the
138:
139: * stream header
140:
141: * at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:845)
142:
143: * at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
144:
145: * at jdbm.recman.RecordManager.byteArrayToObject(RecordManager.java:296)
146:
147: * at jdbm.recman.RecordManager.fetchObject(RecordManager.java:239)
148:
149: * at jdbm.helper.ObjectCache.fetchObject(ObjectCache.java:104)
150:
151: * at jdbm.btree.BPage.loadBPage(BPage.java:670)
152:
153: * at jdbm.btree.BPage.remove(BPage.java:492)
154:
155: * at jdbm.btree.BPage.remove(BPage.java:437)
156:
157: * at jdbm.btree.BTree.remove(BTree.java:313)
158:
159: * at JDBMTest.main(JDBMTest.java:41)
160:
161: *
162:
163: * </pre>
164:
165: *
166:
167: * @author <a href="mailto:cdaller@iicm.edu">Christof Dallermassl</a>
168:
169: * @version $Id: StreamCorrupted.java,v 1.4 2003/09/21 15:49:02 boisvert Exp $
170:
171: */
172:
173: public class StreamCorrupted
174:
175: extends TestCase
176:
177: {
178:
179: public StreamCorrupted(String name) {
180:
181: super (name);
182:
183: }
184:
185: public void setUp() {
186:
187: TestRecordFile.deleteTestFile();
188:
189: }
190:
191: public void tearDown() {
192:
193: TestRecordFile.deleteTestFile();
194:
195: }
196:
197: /**
198:
199: * Basic tests
200:
201: */
202:
203: public void testStreamCorrupted()
204:
205: throws IOException
206:
207: {
208:
209: RecordManager recman;
210:
211: BTree btree;
212:
213: int iterations;
214:
215: iterations = 100; // 23 works :-(((((
216:
217: // open database
218:
219: recman = RecordManagerFactory
220: .createRecordManager(TestRecordFile.testFileName);
221:
222: // create a new B+Tree data structure
223:
224: btree = BTree.createInstance(recman, new StringComparator());
225:
226: recman.setNamedObject("testbtree", btree.getRecid());
227:
228: // action:
229:
230: // insert data
231:
232: for (int count = 0; count < iterations; count++) {
233:
234: btree.insert("num" + count, new Integer(count), true);
235:
236: }
237:
238: // delete data
239:
240: for (int count = 0; count < iterations; count++) {
241:
242: btree.remove("num" + count);
243:
244: }
245:
246: // close database
247:
248: recman.close();
249:
250: recman = null;
251:
252: }
253:
254: /**
255:
256: * Runs all tests in this class
257:
258: */
259:
260: public static void main(String[] args) {
261:
262: junit.textui.TestRunner
263: .run(new TestSuite(StreamCorrupted.class));
264:
265: }
266:
267: }
|