KickJava   Java API By Example, From Geeks To Geeks.

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


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

8
9 package com.sleepycat.je.recovery;
10
11 import java.util.Hashtable JavaDoc;
12
13 import com.sleepycat.je.EnvironmentConfig;
14 import com.sleepycat.je.Environment;
15 import com.sleepycat.je.Transaction;
16 import com.sleepycat.je.config.EnvironmentParams;
17 import com.sleepycat.je.util.TestUtils;
18
19 public class RecoveryDuplicatesTest extends RecoveryTestBase {
20
21     public void testDuplicates()
22         throws Throwable JavaDoc {
23
24         createEnvAndDbs(1 << 20, true, NUM_DBS);
25         int numRecs = 10;
26         int numDups = N_DUPLICATES_PER_KEY;
27
28         try {
29             /* Set up an repository of expected data. */
30             Hashtable JavaDoc expectedData = new Hashtable JavaDoc();
31
32             /* Insert all the data. */
33             Transaction txn = env.beginTransaction(null, null);
34             insertData(txn, 0, numRecs - 1, expectedData,
35                        numDups, true, NUM_DBS);
36             txn.commit();
37             closeEnv();
38             recoverAndVerify(expectedData, NUM_DBS);
39     } catch (Throwable JavaDoc t) {
40             t.printStackTrace();
41             throw t;
42         }
43     }
44
45     public void testDuplicatesWithDeletion()
46         throws Throwable JavaDoc {
47
48         createEnvAndDbs(1 << 20, true, NUM_DBS);
49         int numRecs = 10;
50         int nDups = N_DUPLICATES_PER_KEY;
51
52         try {
53             /* Set up an repository of expected data. */
54             Hashtable JavaDoc expectedData = new Hashtable JavaDoc();
55
56             /* Insert all the data. */
57             Transaction txn = env.beginTransaction(null, null);
58             insertData(txn, 0, numRecs -1, expectedData, nDups, true, NUM_DBS);
59
60             /* Delete all the even records. */
61             deleteData(txn, expectedData, false, true, NUM_DBS);
62             txn.commit();
63
64             /* Modify all the records. */
65             // modifyData(expectedData);
66

67             closeEnv();
68
69             recoverAndVerify(expectedData, NUM_DBS);
70         } catch (Throwable JavaDoc t) {
71             t.printStackTrace();
72             throw t;
73         }
74     }
75
76     /*
77      * See SR11455 for details.
78      *
79      * This test is checking that the maxTxnId gets recovered properly during
80      * recovery. The SR has to do with the INFileReader not including
81      * DupCountLN_TX and DelDupLN_TX's in its txnIdTrackingMap. When these
82      * were not included, it was possible for a transaction to consist solely
83      * of DupCountLN_TX/DelDupLN_TX pairs. The "deleteData" transaction below
84      * does just this. If no checkpoint occurred following such a transaction,
85      * then the correct current txnid would not be written to the log and
86      * determining this value during recovery would be left up to the
87      * INFileReader. However, without reading the DupCountLN_TX/DelDupLN_TX
88      * records, it would not recover the correct value.
89      *
90      * We take the poor man's way out of creating this situation by just
91      * manually asserting the txn id is correct post-recovery. The txnid of 12
92      * was determined by looking through logs before and after the fix.
93      */

94     public void testSR11455()
95         throws Throwable JavaDoc {
96
97         createEnvAndDbs(1 << 20, true, 1);
98         int numRecs = 1;
99         int nDups = 3;
100
101         try {
102             /* Set up an repository of expected data. */
103             Hashtable JavaDoc expectedData = new Hashtable JavaDoc();
104
105             /* Insert all the data. */
106             Transaction txn = env.beginTransaction(null, null);
107             insertData(txn, 0, numRecs -1, expectedData, nDups, true, 1);
108         txn.commit();
109
110         txn = env.beginTransaction(null, null);
111             /* Delete all the even records. */
112             deleteData(txn, expectedData, false, false, 1);
113             txn.abort();
114             closeEnv();
115
116         /* Open it again, which will run recovery. */
117         EnvironmentConfig recoveryConfig = TestUtils.initEnvConfig();
118         recoveryConfig.setTransactional(true);
119         recoveryConfig.setConfigParam
120         (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false");
121         recoveryConfig.setConfigParam
122         (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false");
123         env = new Environment(envHome, recoveryConfig);
124
125         txn = env.beginTransaction(null, null);
126         assertEquals(6, txn.getId());
127         txn.commit();
128         env.close();
129
130         } catch (Throwable JavaDoc t) {
131             t.printStackTrace();
132             throw t;
133         }
134     }
135
136     public void testDuplicatesWithAllDeleted()
137         throws Throwable JavaDoc {
138
139         createEnvAndDbs(1 << 20, true, NUM_DBS);
140         int numRecs = 10;
141         int nDups = N_DUPLICATES_PER_KEY;
142
143         try {
144             /* Set up an repository of expected data. */
145             Hashtable JavaDoc expectedData = new Hashtable JavaDoc();
146
147             /* Insert all the data. */
148             Transaction txn = env.beginTransaction(null, null);
149             insertData(txn, 0, numRecs - 1, expectedData, nDups,
150                true, NUM_DBS);
151
152             /* Delete all data. */
153             deleteData(txn, expectedData, true, true, NUM_DBS);
154             txn.commit();
155
156             /* Modify all the records. */
157         // modifyData(expectedData);
158
closeEnv();
159
160             recoverAndVerify(expectedData, NUM_DBS);
161         } catch (Throwable JavaDoc t) {
162             t.printStackTrace();
163             throw t;
164         }
165     }
166 }
167
Popular Tags