1 8 9 package com.sleepycat.je.test; 10 11 import java.util.Enumeration ; 12 import java.util.Set ; 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 27 public abstract class MultiKeyTxnTestCase extends TxnTestCase { 28 29 boolean useMultiKey = false; 30 31 static TestSuite multiKeyTxnTestSuite(Class testCaseClass, 32 EnvironmentConfig envConfig, 33 String [] 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 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 { 53 54 super.tearDown(); 55 if (useMultiKey) { 56 setName("multi-key:" + getName()); 57 } 58 } 59 60 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 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 |