diff --git a/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java b/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java new file mode 100644 index 0000000000..625796714f --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/tree/TreeTest.java @@ -0,0 +1,133 @@ +/** + * + * 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.activemq.kaha.impl.index.tree; + +import java.io.File; +import java.io.IOException; +import org.apache.activemq.kaha.Store; +import org.apache.activemq.kaha.StoreEntry; +import org.apache.activemq.kaha.impl.index.IndexItem; +import org.apache.activemq.kaha.impl.index.IndexManager; +import junit.framework.TestCase; + +/** + * Test a TreeIndex + * + */ +public class TreeTest extends TestCase{ + + private static int COUNT=55; + private TreeIndex tree; + private File directory; + private IndexManager indexManager; + private boolean dumpTree=false; + + /** + * @throws java.lang.Exception + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception{ + super.setUp(); + directory=new File("activemq-data"); + directory.mkdirs(); + indexManager=new IndexManager(directory,"im-test","rw",null); + this.tree=new TreeIndex(directory,"testTree",indexManager); + this.tree.setKeyMarshaller(Store.StringMarshaller); + } + + public void testTreeWithCaching() throws Exception{ + this.tree.setEnablePageCaching(true); + //doTest(); + } + + public void testTreeWithoutCaching() throws Exception{ + this.tree.setEnablePageCaching(false); + //doTest(); + } + + public void doTest() throws Exception{ + // doTest(300); + // tree.clear(); + // tree.unload(); + doTest(600);// count = 55 - this fails + // tree.clear(); + // tree.unload(); + //doTest(1024*16); + } + + public void doTest(int pageSize) throws Exception{ + String keyRoot="key:"; + tree.setPageSize(pageSize); + this.tree.load(); + // doInsert(keyRoot); + // checkRetrieve(keyRoot); + // doRemove(keyRoot); + doInsert(keyRoot); + doRemoveBackwards(keyRoot); + } + + void doInsert(String keyRoot) throws Exception{ + for(int i=0;i=0;i--){ + tree.remove(keyRoot+i); + System.out.println("BACK Removed " + keyRoot+i); + tree.getRoot().dump(); + System.out.println(""); + } + for(int i=0;i