⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexmanagertest.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// Copyright (C) 2004  Leo Mekenkamp. All rights reserved.//// $Id: IndexManagerTest.java,v 1.3 2004/03/28 16:14:40 per_nyfelt Exp $package test.ozoneDB.core.storage.gammaStore;import junit.framework.Test;import junit.framework.TestSuite;import junit.textui.TestRunner;import org.ozoneDB.ObjectNotFoundException;import org.ozoneDB.core.storage.FixedSizeCache;import org.ozoneDB.core.storage.gammaStore.ContainerLocation;import org.ozoneDB.core.storage.gammaStore.FileStreamStorageFactory;import org.ozoneDB.core.storage.gammaStore.GammaStore;import org.ozoneDB.core.storage.gammaStore.IndexManager;import test.OzoneTestCase;import java.io.File;import java.util.*;import java.util.logging.Level;import java.util.logging.Logger;/** * * @author  leo */public class IndexManagerTest extends OzoneTestCase {        private Random random;    private IndexManager indexManager;    private Map mirror;        private static final long DEFAULT_TESTSIZE = 10000;        public IndexManagerTest() {        super("testIndexManager");        Logger.getLogger(IndexManager.class.getName()).setLevel(Level.ALL);    }        public static Test suite() {        TestSuite suite = new TestSuite();        suite.addTest(new IndexManagerTest());        return suite;    }    public void testSmallNodes() throws Exception {        Properties properties = new Properties();        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey(), FileStreamStorageFactory.class.getName());        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.DIRECTORY.getKey(), "index");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYDEPTH.getKey(), "0");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYCOUNT.getKey(), "50");        properties.setProperty(IndexManager.GENERALINDEXNODECACHE.getKey(), FixedSizeCache.class.getName());        properties.setProperty(IndexManager.GENERALINDEXNODECACHE.getKey() + FixedSizeCache.MAXCAPACITY.getKey(), "2000");        properties.setProperty(IndexManager.MAXBRANCHNODESIZE.getKey(), "10"); // 93:2K; 226: 4K; 474:8K; 982:16K; 1998:32K        properties.setProperty(IndexManager.MAXLEAFNODESIZE.getKey(), "10"); // 72:2K; 179:4K; 376:8K; 784:16K; 1598:32K        // FIXME: Uncommentet so the test at least compiles        //properties.setProperty(IndexManager.FINALIZATIONTHRESHHOLD.getKey(), "0.001");                // in order to run this test with more items you need to increase stack space        actualTest(properties, 5000);    }        public void testBigNodes() throws Exception {        Properties properties = new Properties();        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey(), FileStreamStorageFactory.class.getName());        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.DIRECTORY.getKey(), "index");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYDEPTH.getKey(), "0");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYCOUNT.getKey(), "50");        properties.setProperty(IndexManager.GENERALINDEXNODECACHE.getKey(), FixedSizeCache.class.getName());        properties.setProperty(IndexManager.GENERALINDEXNODECACHE.getKey() + FixedSizeCache.MAXCAPACITY.getKey(), "20");        properties.setProperty(IndexManager.MAXBRANCHNODESIZE.getKey(), "1998"); // 93:2K; 226: 4K; 474:8K; 982:16K; 1998:32K        properties.setProperty(IndexManager.MAXLEAFNODESIZE.getKey(), "1598"); // 72:2K; 179:4K; 376:8K; 784:16K; 1598:32K        // FIXME: Uncommentet so the test at least compiles        //properties.setProperty(IndexManager.FINALIZATIONTHRESHHOLD.getKey(), "0.001");        actualTest(properties, DEFAULT_TESTSIZE);    }        public void testSmallCache() throws Exception {        Properties properties = new Properties();        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey(), FileStreamStorageFactory.class.getName());        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.DIRECTORY.getKey(), "index");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYDEPTH.getKey(), "2");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYCOUNT.getKey(), "10");        properties.setProperty(IndexManager.GENERALINDEXNODECACHE.getKey(), FixedSizeCache.class.getName());        properties.setProperty(IndexManager.GENERALINDEXNODECACHE.getKey() + FixedSizeCache.MAXCAPACITY.getKey(), "2");        properties.setProperty(IndexManager.MAXBRANCHNODESIZE.getKey(), "474"); // 93:2K; 226: 4K; 474:8K; 982:16K; 1998:32K        properties.setProperty(IndexManager.MAXLEAFNODESIZE.getKey(), "376"); // 72:2K; 179:4K; 376:8K; 784:16K; 1598:32K        // FIXME: Uncommentet so the test at least compiles        // properties.setProperty(IndexManager.FINALIZATIONTHRESHHOLD.getKey(), "0.001");        actualTest(properties, DEFAULT_TESTSIZE);    }        public void testGcListenerCache() throws Exception {        Properties properties = new Properties();        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey(), FileStreamStorageFactory.class.getName());        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.DIRECTORY.getKey(), "index");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYDEPTH.getKey(), "3");        properties.setProperty(IndexManager.INDEXNODESTORAGEFACTORY.getKey() + FileStreamStorageFactory.SUBDIRECTORYCOUNT.getKey(), "10");        // FIXME: just made up some replacements for the below line        //properties.setProperty(IndexManager.INDEXNODECACHE.getKey(), GcListenerCache.class.getName());        properties.setProperty(IndexManager.GENERALINDEXNODECACHE.getKey(), FixedSizeCache.class.getName());        properties.setProperty(IndexManager.MAXBRANCHNODESIZE.getKey(), "474"); // 93:2K; 226: 4K; 474:8K; 982:16K; 1998:32K        properties.setProperty(IndexManager.MAXLEAFNODESIZE.getKey(), "376"); // 72:2K; 179:4K; 376:8K; 784:16K; 1598:32K        // FIXME: Uncommentet so the test at least compiles        // properties.setProperty(IndexManager.FINALIZATIONTHRESHHOLD.getKey(), "0.001");        actualTest(properties, DEFAULT_TESTSIZE);    }    private void randomFill(long targetSize) {        while (mirror.size() < targetSize) {            assertEquals(indexManager.getSize(), mirror.size());            long val = Math.abs(random.nextInt());            ContainerLocation containerLocation = new ContainerLocation((int) val, (int)val);            Long key = new Long(val);            mirror.put(key, containerLocation);            indexManager.putContainerLocation(val, containerLocation);            assertEquals(indexManager.getSize(), mirror.size());        }    }    private void randomRemove(long targetSize) {        for (Iterator i = mirror.keySet().iterator(); i.hasNext() && indexManager.getSize() > targetSize; ) {            assertEquals("indexManager size: " + indexManager.getSize() + "; mirror size: " + mirror.size(), (int) indexManager.getSize(), mirror.size());            long val = Math.abs(random.nextInt());            boolean removed = mirror.remove(new Long(val)) != null;            try {                indexManager.removeContainerLocation(val);                assertTrue(removed);            } catch (ObjectNotFoundException e) {                assertFalse(removed);            }            if (!removed) {                Long key = (Long) i.next();                i.remove();                indexManager.removeContainerLocation(key.longValue());            }            assertEquals("indexManager size: " + indexManager.getSize() + "; mirror size: " + mirror.size(), (int) indexManager.getSize(), mirror.size());        }    }    private void checkEquality() {        for (int i = 0; i < mirror.size() * 2; i++) {            long val = Math.abs(random.nextInt());            try {                ContainerLocation fromIndex = indexManager.getContainerLocation(val);                ContainerLocation fromMirror = (ContainerLocation) mirror.get(new Long(val));                // uncommented to make it compile                //assertEquals(fromIndex.clusterId, fromMirror.clusterId);                //assertEquals(fromIndex.position, fromMirror.position);            } catch (ObjectNotFoundException e) {                assertNull(mirror.get(new Long(val)));            }        }    }        private void actualTest(Properties properties, long capacity) throws Exception {        File directory = new File("IndexManagerTest");//        if (directory.exists()) {//            throw new RuntimeException(directory.getAbsoluteFile() + " is needed for test. Please remove before proceeding.");//        }        directory.mkdirs();        properties.setProperty(GammaStore.DIRECTORY.getKey(), directory.getAbsolutePath());        random = new Random(0);        mirror = new HashMap();        // TODO not sure what the prefix should be        indexManager = new IndexManager(properties,"", true);                checkEquality();                randomFill(capacity);        checkEquality();        randomRemove(capacity / 2);                checkEquality();        randomFill(capacity);                indexManager.shutdown();        // TODO not sure what the prefix should be        indexManager = new IndexManager(properties,"", false);        checkEquality();        randomRemove(0);        checkEquality();        randomFill(capacity / 2 );        checkEquality();        indexManager.shutdown();        // TODO not sure what the prefix should be        indexManager = new IndexManager(properties, "",false);        checkEquality();        randomRemove(capacity / 4);                checkEquality();        indexManager.shutdown();        // TODO not sure what the prefix should be        indexManager = new IndexManager(properties, "", false);        checkEquality();        randomRemove(0);        checkEquality();        indexManager.shutdown();    }        private void deleteAll(File file) {        File[] children = file.listFiles();        for (int i = 0; i < children.length; i++) {            deleteAll(children[i]);        }        file.delete();    }        public static void main(String[] args) {        TestRunner testRunner = new TestRunner();        testRunner.run(IndexManagerTest.class);    }        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -