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

📄 closeddbtest.java

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 JAVA
字号:
package com.sleepycat.db.test;import org.junit.After;import org.junit.AfterClass;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;import static org.junit.Assert.assertEquals;import static org.junit.Assert.fail;import com.sleepycat.db.*;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import com.sleepycat.db.test.TestUtils;public class ClosedDbTest {    public static final String CLOSEDDBTEST_DBNAME = "closeddbtest.db";    @BeforeClass public static void ClassInit() {        TestUtils.loadConfig(null);        TestUtils.check_file_removed(TestUtils.getDBFileName(CLOSEDDBTEST_DBNAME), true, true);        TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(CLOSEDDBTEST_DBNAME));    }    @AfterClass public static void ClassShutdown() {        TestUtils.check_file_removed(TestUtils.getDBFileName(CLOSEDDBTEST_DBNAME), true, true);        TestUtils.removeall(true, true, TestUtils.BASETEST_DBDIR, TestUtils.getDBFileName(CLOSEDDBTEST_DBNAME));    }    @Before public void PerTestInit()        throws Exception {    }    @After public void PerTestShutdown()        throws Exception {    }    /*     * Test case implementations.     * To disable a test mark it with @Ignore     * To set a timeout(ms) notate like: @Test(timeout=1000)     * To indicate an expected exception notate like: (expected=Exception)     */    @Test public void test1()        throws DatabaseException, FileNotFoundException    {        DatabaseConfig dbConf = new DatabaseConfig();        dbConf.setType(DatabaseType.BTREE);        dbConf.setAllowCreate(true);        Database db = new Database(TestUtils.getDBFileName(CLOSEDDBTEST_DBNAME), null, dbConf);         	DatabaseEntry key = new DatabaseEntry("key".getBytes());    	DatabaseEntry data = new DatabaseEntry("data".getBytes());    	db.putNoOverwrite(null, key, data);      	// Now, retrieve. It would be possible to reuse the    	// same key object, but that would be a-typical.    	DatabaseEntry getkey = new DatabaseEntry("key".getBytes());    	DatabaseEntry badgetkey = new DatabaseEntry("badkey".getBytes());    	DatabaseEntry getdata = new DatabaseEntry();    	getdata.setReuseBuffer(false); // TODO: is this enabling DB_DBT_MALLOC?        int ret;             // close the db - subsequent operations should fail by throwing        // an exception.    	db.close();      	try {    	    db.get(null, getkey, getdata, LockMode.DEFAULT);    	    fail("Database get on a closed Db should not have completed.");    	} catch (IllegalArgumentException e) {    	    TestUtils.DEBUGOUT(1, "Got expected exception from db.get on closed database.");    	}    }}

⌨️ 快捷键说明

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