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

📄 collectiontest.java

📁 嵌入式数据库Berkeley DB-4.5.20源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2002-2006 *	Oracle Corporation.  All rights reserved. * * $Id: CollectionTest.java,v 12.6 2006/08/24 14:46:46 bostic Exp $ */package com.sleepycat.collections.test;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Enumeration;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.ListIterator;import java.util.Map;import java.util.NoSuchElementException;import java.util.Set;import java.util.SortedMap;import java.util.SortedSet;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import com.sleepycat.bind.EntityBinding;import com.sleepycat.bind.EntryBinding;import com.sleepycat.collections.MapEntryParameter;import com.sleepycat.collections.StoredCollection;import com.sleepycat.collections.StoredCollections;import com.sleepycat.collections.StoredContainer;import com.sleepycat.collections.StoredEntrySet;import com.sleepycat.collections.StoredIterator;import com.sleepycat.collections.StoredKeySet;import com.sleepycat.collections.StoredList;import com.sleepycat.collections.StoredMap;import com.sleepycat.collections.StoredSortedEntrySet;import com.sleepycat.collections.StoredSortedKeySet;import com.sleepycat.collections.StoredSortedMap;import com.sleepycat.collections.StoredSortedValueSet;import com.sleepycat.collections.StoredValueSet;import com.sleepycat.collections.TransactionRunner;import com.sleepycat.collections.TransactionWorker;import com.sleepycat.compat.DbCompat;import com.sleepycat.db.Database;import com.sleepycat.db.DatabaseException;import com.sleepycat.db.Environment;import com.sleepycat.util.ExceptionUnwrapper;/** * @author Mark Hayes */public class CollectionTest extends TestCase {    private static final int NONE = 0;    private static final int SUB = 1;    private static final int HEAD = 2;    private static final int TAIL = 3;    /*     * For long tests we permute testStoredIterator to test both StoredIterator     * and BlockIterator.  When testing BlockIterator, we permute the maxKey     * over the array values below.  BlockIterator's block size is 10.  So we     * test below the block size (6), at the block size (10), and above it (14     * and 22).     */    private static final int DEFAULT_MAX_KEY = 6;    private static final int[] MAX_KEYS = {6, 10, 14, 22};    private boolean testStoredIterator;    private int maxKey; /* Must be a multiple of 2. */    private int beginKey = 1;    private int endKey;    private Environment env;    private Database store;    private Database index;    private boolean isEntityBinding;    private boolean isAutoCommit;    private TestStore testStore;    private String testName;    private EntryBinding keyBinding;    private EntryBinding valueBinding;    private EntityBinding entityBinding;    private TransactionRunner readRunner;    private TransactionRunner writeRunner;    private TransactionRunner writeIterRunner;    private TestEnv testEnv;    private StoredMap map;    private StoredMap imap; // insertable map (primary store for indexed map)    private StoredSortedMap smap; // sorted map (null or equal to map)    private StoredMap saveMap;    private StoredSortedMap saveSMap;    private int rangeType;    private StoredList list;    private StoredList ilist; // insertable list (primary store for index list)    private StoredList saveList;    private StoredKeySet keySet;    private StoredValueSet valueSet;    /**     * Runs a command line collection test.     * @see #usage     */    public static void main(String[] args)        throws Exception {        if (args.length == 1 &&            (args[0].equals("-h") || args[0].equals("-help"))) {            usage();        } else {            junit.framework.TestResult tr =		junit.textui.TestRunner.run(suite(args));	    if (tr.errorCount() > 0 ||		tr.failureCount() > 0) {		System.exit(1);	    } else {		System.exit(0);	    }        }    }    private static void usage() {        System.out.println(            "Usage: java com.sleepycat.collections.test.CollectionTest\n" +            "              -h | -help\n" +            "              [testName]...\n" +            "  where testName has the format:\n" +            "    <env>-<store>-{entity|value}\n" +            "  <env> is:\n" +            "    bdb | cdb | txn\n" +            "  <store> is:\n" +            "    btree-uniq | btree-dup | btree-dupsort | btree-recnum |\n" +            "    hash-uniq | hash-dup | hash-dupsort |\n" +            "    queue | recno | recno-renum\n" +            "  For example:  bdb-btree-uniq-entity\n" +            "  If no arguments are given then all tests are run.");        System.exit(2);    }    public static Test suite()        throws Exception {        return suite(null);    }    static Test suite(String[] args)        throws Exception {        if ("true".equals(System.getProperty("longtest"))) {            TestSuite suite = new TestSuite();            /* StoredIterator tests. */            permuteTests(args, suite, true, DEFAULT_MAX_KEY);            /* BlockIterator tests with different maxKey values. */            for (int i = 0; i < MAX_KEYS.length; i += 1) {                permuteTests(args, suite, false, MAX_KEYS[i]);            }            return suite;        } else {            return baseSuite(args);        }    }    private static void permuteTests(String[] args,                                     TestSuite suite,                                     boolean storedIter,                                     int maxKey)        throws Exception {        TestSuite baseTests = baseSuite(args);        Enumeration e = baseTests.tests();        while (e.hasMoreElements()) {            CollectionTest t = (CollectionTest) e.nextElement();            t.setParams(storedIter, maxKey);            suite.addTest(t);        }    }    private static TestSuite baseSuite(String[] args)        throws Exception {        TestSuite suite = new TestSuite();        for (int i = 0; i < TestEnv.ALL.length; i += 1) {            for (int j = 0; j < TestStore.ALL.length; j += 1) {                for (int k = 0; k < 2; k += 1) {                    boolean entityBinding = (k != 0);                    addTest(args, suite, new CollectionTest(                            TestEnv.ALL[i], TestStore.ALL[j],                            entityBinding, false));                    if (TestEnv.ALL[i].isTxnMode()) {                        addTest(args, suite, new CollectionTest(                                TestEnv.ALL[i], TestStore.ALL[j],                                entityBinding, true));                    }                }            }        }        return suite;    }    private static void addTest(String[] args, TestSuite suite,                                CollectionTest test) {        if (args == null || args.length == 0) {            suite.addTest(test);        } else {            for (int t = 0; t < args.length; t += 1) {                if (args[t].equals(test.testName)) {                    suite.addTest(test);                    break;                }            }        }    }    public CollectionTest(TestEnv testEnv, TestStore testStore,                          boolean isEntityBinding, boolean isAutoCommit) {        super(null);        this.testEnv = testEnv;        this.testStore = testStore;        this.isEntityBinding = isEntityBinding;        this.isAutoCommit = isAutoCommit;        keyBinding = testStore.getKeyBinding();        valueBinding = testStore.getValueBinding();        entityBinding = testStore.getEntityBinding();        setParams(false, DEFAULT_MAX_KEY);    }    private void setParams(boolean storedIter, int maxKey) {        this.testStoredIterator = storedIter;        this.maxKey = maxKey;        this.endKey = maxKey;        testName = testEnv.getName() + '-' + testStore.getName() +                    (isEntityBinding ? "-entity" : "-value") +                    (isAutoCommit ? "-autoCommit" : "") +                    (testStoredIterator ? "-storedIter" : "") +                    ((maxKey != DEFAULT_MAX_KEY) ? ("-maxKey-" + maxKey) : "");    }    public void tearDown()        throws Exception {        setName(testName);    }    public void runTest()        throws Exception {        DbTestUtil.printTestName(DbTestUtil.qualifiedTestName(this));        try {            env = testEnv.open(testName);            // For testing auto-commit, use a normal (transactional) runner for            // all reading and for writing via an iterator, and a do-nothing            // runner for writing via collections; if auto-commit is tested,            // the per-collection auto-commit property will be set elsewhere.            //            TransactionRunner normalRunner = newTransactionRunner(env);            normalRunner.setAllowNestedTransactions(                    DbCompat.NESTED_TRANSACTIONS);            TransactionRunner nullRunner = new NullTransactionRunner(env);            readRunner = nullRunner;            writeIterRunner = normalRunner;            if (isAutoCommit) {                writeRunner = nullRunner;            } else {                writeRunner = normalRunner;            }            store = testStore.open(env, "unindexed.db");            testUnindexed();            store.close();            store = null;            TestStore indexOf = testStore.getIndexOf();            if (indexOf != null) {                store = indexOf.open(env, "indexed.db");                index = testStore.openIndex(store, "index.db");                testIndexed();                index.close();                index = null;                store.close();                store = null;            }            env.close();            env = null;        } catch (Exception e) {            throw ExceptionUnwrapper.unwrap(e);        } finally {            if (index != null) {                try {		    index.close();		} catch (Exception e) {		}            }            if (store != null) {                try {		    store.close();		} catch (Exception e) {		}            }            if (env != null) {                try {		    env.close();		} catch (Exception e) {		}            }            /* Ensure that GC can cleanup. */            index = null;            store = null;            env = null;            readRunner = null;            writeRunner = null;            writeIterRunner = null;            map = null;            imap = null;            smap = null;            saveMap = null;            saveSMap = null;            list = null;            ilist = null;            saveList = null;            keySet = null;            valueSet = null;	    testEnv = null;

⌨️ 快捷键说明

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