KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > recovery > MultiEnvTest


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

8
9 package com.sleepycat.je.recovery;
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.DatabaseException;
17 import com.sleepycat.je.Environment;
18 import com.sleepycat.je.EnvironmentConfig;
19 import com.sleepycat.je.tree.Node;
20 import com.sleepycat.je.util.TestUtils;
21
22 public class MultiEnvTest extends TestCase {
23
24     private File JavaDoc envHome1;
25     private File JavaDoc envHome2;
26     private Environment env1;
27     private Environment env2;
28
29     public MultiEnvTest() {
30         envHome1 = new File JavaDoc(System.getProperty(TestUtils.DEST_DIR));
31         envHome2 = new File JavaDoc(System.getProperty(TestUtils.DEST_DIR),
32                             "propTest");
33     }
34
35     public void setUp()
36         throws IOException JavaDoc {
37
38         TestUtils.removeLogFiles("Setup", envHome1, false);
39         TestUtils.removeLogFiles("Setup", envHome2, false);
40     }
41     
42     public void tearDown()
43         throws Exception JavaDoc {
44
45     TestUtils.removeLogFiles("TearDown", envHome1, false);
46     TestUtils.removeLogFiles("TearDown", envHome2, false);
47     }
48
49     public void testNodeIdsAfterRecovery()
50         throws Throwable JavaDoc {
51         try {
52             /*
53              * Env1 will be closed w/a certain notion of what the max node id
54              * is.
55              */

56             env1 = openEnv(envHome1);
57             long maxNodeId1 = Node.getLastId();
58             env1.close();
59
60             /*
61              * Env2 increments the node id further.
62              */

63             env2 = openEnv(envHome2);
64             long maxNodeId2 = Node.getLastId();
65
66             /* See what the highest node id is. */
67             assertTrue(maxNodeId2 > maxNodeId1);
68
69             /*
70              * Open env1 now. Even though this recovery finds a lower node id,
71              * must be sure not to overwrite the higher node id.
72              */

73             env1 = openEnv(envHome1);
74             long maxNodeId3 = Node.getLastId();
75             assertTrue(maxNodeId3 >= maxNodeId2);
76             env2.close();
77         } catch (Throwable JavaDoc t) {
78             /* Dump stack trace before trying to tear down. */
79             t.printStackTrace();
80             throw t;
81         }
82     }
83
84     private Environment openEnv(File JavaDoc envHome)
85         throws DatabaseException {
86
87         /* Create an environment. */
88         EnvironmentConfig envConfig = TestUtils.initEnvConfig();
89         envConfig.setAllowCreate(true);
90         Environment e = new Environment(envHome, envConfig);
91         return e;
92     }
93 }
94
Popular Tags