1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2002,2010 Oracle. All rights reserved.
*
* $Id: ValidateSubtreeDeleteTest.java,v 1.34.2.2 2010/01/04 15:30:48 cwl Exp $
*/
package com.sleepycat.je.tree;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseConfig;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.DbInternal;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.Transaction;
import com.sleepycat.je.config.EnvironmentParams;
import com.sleepycat.je.log.FileManager;
import com.sleepycat.je.util.TestUtils;
public class ValidateSubtreeDeleteTest extends TestCase {
private File envHome;
private Environment env;
private Database testDb;
public ValidateSubtreeDeleteTest() {
envHome = new File(System.getProperty(TestUtils.DEST_DIR));
}
public void setUp()
throws IOException, DatabaseException {
TestUtils.removeFiles("Setup", envHome, FileManager.JE_SUFFIX);
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setTransactional(true);
envConfig.setConfigParam(EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(),
"false");
envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6");
envConfig.setAllowCreate(true);
env = new Environment(envHome, envConfig);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
dbConfig.setSortedDuplicates(true);
testDb = env.openDatabase(null, "Test", dbConfig);
}
public void tearDown() throws IOException, DatabaseException {
testDb.close();
if (env != null) {
try {
env.close();
} catch (DatabaseException E) {
}
}
TestUtils.removeFiles("TearDown", envHome, FileManager.JE_SUFFIX);
}
public void testBasic()
throws Exception {
try {
/* Make a 3 level tree full of data */
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
byte[] testData = new byte[1];
testData[0] = 1;
data.setData(testData);
Transaction txn = env.beginTransaction(null, null);
for (int i = 0; i < 15; i ++) {
key.setData(TestUtils.getTestArray(i));
testDb.put(txn, key, data);
}
/* Should not be able to delete any of it */
assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(0));
assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(1));
/*
* Should be able to delete both, the txn is aborted and the data
* isn't there.
*/
txn.abort();
assertTrue(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(0));
assertTrue(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(1));
/*
* Try explicit deletes.
*/
txn = env.beginTransaction(null, null);
for (int i = 0; i < 15; i ++) {
key.setData(TestUtils.getTestArray(i));
testDb.put(txn, key, data);
}
for (int i = 0; i < 15; i ++) {
key.setData(TestUtils.getTestArray(i));
testDb.delete(txn, key);
}
assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(0));
assertFalse(DbInternal.dbGetDatabaseImpl(testDb).getTree().validateDelete(1));
// XXX, now commit the delete and compress and test that the
// subtree is deletable. Not finished yet! Also must test deletes.
txn.abort();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
public void testDuplicates()
throws Exception {
try {
/* Make a 3 level tree full of data */
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
byte[] testData = new byte[1];
testData[0] = 1;
key.setData(testData);
Transaction txn = env.beginTransaction(null, null);
for (int i = 0; i < 4; i ++) {
data.setData(TestUtils.getTestArray(i));
testDb.put(txn, key, data);
}
/* Should not be able to delete any of it */
Tree tree = DbInternal.dbGetDatabaseImpl(testDb).getTree();
assertFalse(tree.validateDelete(0));
/*
* Should be able to delete, the txn is aborted and the data
* isn't there.
*/
txn.abort();
assertTrue(tree.validateDelete(0));
/*
* Try explicit deletes.
*/
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
|