KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > test > MultiKeyTxnTestCase


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

8
9 package com.sleepycat.je.test;
10
11 import java.util.Enumeration JavaDoc;
12 import java.util.Set JavaDoc;
13
14 import junit.framework.TestSuite;
15
16 import com.sleepycat.je.DatabaseEntry;
17 import com.sleepycat.je.DatabaseException;
18 import com.sleepycat.je.EnvironmentConfig;
19 import com.sleepycat.je.SecondaryDatabase;
20 import com.sleepycat.je.SecondaryKeyCreator;
21 import com.sleepycat.je.SecondaryMultiKeyCreator;
22
23 /**
24  * Permutes a TxnTestCase over a boolean property for using multiple secondary
25  * keys.
26  */

27 public abstract class MultiKeyTxnTestCase extends TxnTestCase {
28
29     boolean useMultiKey = false;
30
31     static TestSuite multiKeyTxnTestSuite(Class JavaDoc testCaseClass,
32                                           EnvironmentConfig envConfig,
33                                           String JavaDoc[] txnTypes) {
34
35         TestSuite suite = new TestSuite();
36         for (int i = 0; i < 2; i += 1) {
37             boolean multiKey = (i == 1);
38             TestSuite txnSuite = txnTestSuite(testCaseClass, envConfig,
39                                               txnTypes);
40             Enumeration JavaDoc e = txnSuite.tests();
41             while (e.hasMoreElements()) {
42                 MultiKeyTxnTestCase test =
43                     (MultiKeyTxnTestCase) e.nextElement();
44                 test.useMultiKey = multiKey;
45                 suite.addTest(test);
46             }
47         }
48         return suite;
49     }
50     
51     public void tearDown()
52         throws Exception JavaDoc {
53
54         super.tearDown();
55         if (useMultiKey) {
56             setName("multi-key:" + getName());
57         }
58     }
59
60     /**
61      * Wraps a single key creator to exercise the multi-key code for tests that
62      * only create a single secondary key.
63      */

64     static class SimpleMultiKeyCreator
65         implements SecondaryMultiKeyCreator {
66
67         private SecondaryKeyCreator keyCreator;
68
69         SimpleMultiKeyCreator(SecondaryKeyCreator keyCreator) {
70             this.keyCreator = keyCreator;
71         }
72
73         public void createSecondaryKeys(SecondaryDatabase secondary,
74                                         DatabaseEntry key,
75                                         DatabaseEntry data,
76                                         Set JavaDoc results)
77             throws DatabaseException {
78
79             DatabaseEntry result = new DatabaseEntry();
80             if (keyCreator.createSecondaryKey(secondary, key, data, result)) {
81                 results.add(result);
82             }
83         }
84     }
85 }
86
Popular Tags