KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > dbi > DbTreeTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: DbTreeTest.java,v 1.26 2006/10/30 21:14:43 bostic Exp $
7  */

8
9 package com.sleepycat.je.dbi;
10
11 import java.io.File JavaDoc;
12 import java.io.IOException JavaDoc;
13
14 import junit.framework.TestCase;
15
16 import com.sleepycat.je.Database;
17 import com.sleepycat.je.DatabaseConfig;
18 import com.sleepycat.je.DatabaseException;
19 import com.sleepycat.je.Environment;
20 import com.sleepycat.je.EnvironmentConfig;
21 import com.sleepycat.je.config.EnvironmentParams;
22 import com.sleepycat.je.log.FileManager;
23 import com.sleepycat.je.util.TestUtils;
24
25 public class DbTreeTest extends TestCase {
26     private File JavaDoc envHome;
27     
28     public DbTreeTest() {
29         envHome = new File JavaDoc(System.getProperty(TestUtils.DEST_DIR));
30     }
31
32     public void setUp() throws IOException JavaDoc, DatabaseException {
33         TestUtils.removeFiles("Setup", envHome, FileManager.JE_SUFFIX);
34     }
35
36     public void tearDown() throws IOException JavaDoc, DatabaseException {
37         TestUtils.removeFiles("TearDown", envHome, FileManager.JE_SUFFIX);
38     }
39
40     public void testDbLookup() throws Throwable JavaDoc {
41         try {
42             EnvironmentConfig envConfig = TestUtils.initEnvConfig();
43             envConfig.setTransactional(true);
44             envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6");
45             envConfig.setAllowCreate(true);
46             Environment env = new Environment(envHome, envConfig);
47
48             // Make two databases
49
DatabaseConfig dbConfig = new DatabaseConfig();
50             dbConfig.setTransactional(true);
51             dbConfig.setAllowCreate(true);
52             Database dbHandleAbcd = env.openDatabase(null, "abcd", dbConfig);
53             Database dbHandleXyz = env.openDatabase(null, "xyz", dbConfig);
54
55             // Can we get them back?
56
dbConfig.setAllowCreate(false);
57             Database newAbcdHandle = env.openDatabase(null, "abcd", dbConfig);
58             Database newXyzHandle = env.openDatabase(null, "xyz", dbConfig);
59
60             dbHandleAbcd.close();
61             dbHandleXyz.close();
62             newAbcdHandle.close();
63             newXyzHandle.close();
64             env.close();
65         } catch (Throwable JavaDoc t) {
66             t.printStackTrace();
67             throw t;
68         }
69     }
70 }
71
Popular Tags