Package jdbm.btree

Source Code of jdbm.btree.StreamCorrupted

/*******************************************************************************
* Copyright 2010 Cees De Groot, Alex Boisvert, Jan Kotek
*
* Licensed 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 jdbm.btree;

import java.io.IOException;

import jdbm.RecordManager;
import jdbm.recman.TestCaseWithTestFile;

/**
* Contributed test case for BTree by Christof Dallermassl (cdaller iicm.edu):
*
* -= quote from original message posted on jdbm-general =-
* <pre>
*
* I tried to insert a couple of elements into a BTree and then remove
* them one by one. After a number or removals, there is always (if more
* than 20 elements in btree) a java.io.StreamCorruptedException thrown.
*
* The strange thing is, that on 50 elements, the exception is thrown
* after removing 22, on 200 it is thrown after 36, on 1000 it is thrown
* after 104, on 10000 it is thrown after 1003....
*
* The full stackTrace is here:
* ---------------------- snip ------- snap -------------------------
* java.io.StreamCorruptedException: Caught EOFException while reading the
* stream header
*   at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:845)
*   at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
*   at jdbm.recman.RecordManager.byteArrayToObject(RecordManager.java:296)
*   at jdbm.recman.RecordManager.fetchObject(RecordManager.java:239)
*   at jdbm.helper.ObjectCache.fetchObject(ObjectCache.java:104)
*   at jdbm.btree.BPage.loadBPage(BPage.java:670)
*   at jdbm.btree.BPage.remove(BPage.java:492)
*   at jdbm.btree.BPage.remove(BPage.java:437)
*   at jdbm.btree.BTree.remove(BTree.java:313)
*   at JDBMTest.main(JDBMTest.java:41)
*
* </pre>
*
@author <a href="mailto:cdaller iicm.edu">Christof Dallermassl</a>
@version $Id: StreamCorrupted.java,v 1.4 2003/09/21 15:49:02 boisvert Exp $
*/
public class StreamCorrupted
    extends TestCaseWithTestFile
{



    /**
     *  Basic tests
     */
    public void testStreamCorrupted()
        throws IOException
    {
        RecordManager  recman;
        BTree          btree;
        int            iterations;

        iterations = 100; // 23 works :-(((((

        // open database
        recman = newRecordManager();

        // create a new B+Tree data structure
        btree = BTree.createInstance( recman);
        recman.setNamedObject( "testbtree", btree.getRecid() );

        // action:

        // insert data
        for( int count = 0; count < iterations; count++ ) {
            btree.insert( "num" + count, new Integer( count ), true );
        }

        // delete data
        for( int count = 0; count < iterations; count++ ) {
            btree.remove( "num" + count );
        }

        // close database
        recman.close();
        recman = null;
    }


}
TOP

Related Classes of jdbm.btree.StreamCorrupted

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.