1 8 9 package com.sleepycat.je.tree; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 14 import junit.framework.TestCase; 15 16 import com.sleepycat.je.Database; 17 import com.sleepycat.je.DatabaseConfig; 18 import com.sleepycat.je.DatabaseEntry; 19 import com.sleepycat.je.DatabaseException; 20 import com.sleepycat.je.DbInternal; 21 import com.sleepycat.je.Environment; 22 import com.sleepycat.je.EnvironmentConfig; 23 import com.sleepycat.je.Transaction; 24 import com.sleepycat.je.config.EnvironmentParams; 25 import com.sleepycat.je.log.FileManager; 26 import com.sleepycat.je.util.TestUtils; 27 28 public class ValidateSubtreeDeleteTest extends TestCase { 29 30 private File envHome; 31 private Environment env; 32 private Database testDb; 33 34 public ValidateSubtreeDeleteTest() { 35 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 36 } 37 38 public void setUp() 39 throws IOException , DatabaseException { 40 41 TestUtils.removeFiles("Setup", envHome, FileManager.JE_SUFFIX); 42 43 44 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 45 envConfig.setTransactional(true); 46 envConfig.setConfigParam(EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), 47 "false"); 48 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6"); 49 envConfig.setAllowCreate(true); 50 env = new Environment(envHome, envConfig); 51 52 DatabaseConfig dbConfig = new DatabaseConfig(); 53 dbConfig.setTransactional(true); 54 dbConfig.setAllowCreate(true); 55 dbConfig.setSortedDuplicates(true); 56 testDb = env.openDatabase(null, "Test", dbConfig); 57 } 58 59 public void tearDown() throws IOException , DatabaseException { 60 testDb.close(); 61 if (env != null) { 62 try { 63 env.close(); 64 } catch (DatabaseException E) { 65 } 66 } 67 TestUtils.removeFiles("TearDown", envHome, FileManager.JE_SUFFIX); 68 } 69 70 public void testBasic() 71 throws Exception { 72 try { 73 74 DatabaseEntry key = new DatabaseEntry(); 75 DatabaseEntry data = new DatabaseEntry(); 76 byte [] testData = new byte[1]; 77 testData[0] = 1; 78 data.setData(testData); 79 80 Transaction txn = env.beginTransaction(null, null); 81 for (int i = 0; i < 15; i ++) { 82 key.setData(TestUtils.getTestArray(i)); 83 testDb.put(txn, key, data); 84 } 85 86 87 assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(0)); 88 assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(1)); 89 90 94 txn.abort(); 95 assertTrue(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(0)); 96 assertTrue(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(1)); 97 98 99 102 txn = env.beginTransaction(null, null); 103 for (int i = 0; i < 15; i ++) { 104 key.setData(TestUtils.getTestArray(i)); 105 testDb.put(txn, key, data); 106 } 107 for (int i = 0; i < 15; i ++) { 108 key.setData(TestUtils.getTestArray(i)); 109 testDb.delete(txn, key); 110 } 111 assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(0)); 112 assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(1)); 113 114 txn.abort(); 117 } catch (Exception e) { 118 e.printStackTrace(); 119 throw e; 120 } 121 } 122 123 public void testDuplicates() 124 throws Exception { 125 try { 126 127 DatabaseEntry key = new DatabaseEntry(); 128 DatabaseEntry data = new DatabaseEntry(); 129 byte [] testData = new byte[1]; 130 testData[0] = 1; 131 key.setData(testData); 132 133 Transaction txn = env.beginTransaction(null, null); 134 for (int i = 0; i < 4; i ++) { 135 data.setData(TestUtils.getTestArray(i)); 136 testDb.put(txn, key, data); 137 } 138 139 140 Tree tree = DbInternal.dbGetDatabaseImpl(testDb).getTree(); 141 assertFalse(tree.validateDelete(0)); 142 143 147 txn.abort(); 148 assertTrue(tree.validateDelete(0)); 149 150 153 } catch (Exception e) { 154 e.printStackTrace(); 155 throw e; 156 } 157 } 158 159 } 160 | Popular Tags |