1 8 9 package com.sleepycat.je.tree; 10 11 import java.io.File ; 12 13 import junit.framework.TestCase; 14 15 import com.sleepycat.je.Database; 16 import com.sleepycat.je.DatabaseConfig; 17 import com.sleepycat.je.DatabaseEntry; 18 import com.sleepycat.je.DatabaseException; 19 import com.sleepycat.je.DbInternal; 20 import com.sleepycat.je.Environment; 21 import com.sleepycat.je.EnvironmentConfig; 22 import com.sleepycat.je.LockMode; 23 import com.sleepycat.je.OperationStatus; 24 import com.sleepycat.je.Transaction; 25 import com.sleepycat.je.config.EnvironmentParams; 26 import com.sleepycat.je.util.TestUtils; 27 28 public class SplitTest extends TestCase { 29 private static final boolean DEBUG = false; 30 31 private File envHome; 32 private Environment env; 33 private Database db; 34 35 public SplitTest() { 36 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 37 } 38 39 public void setUp() 40 throws Exception { 41 TestUtils.removeLogFiles("Setup", envHome, false); 42 initEnv(); 43 } 44 45 public void tearDown() 46 throws Exception { 47 try { 48 db.close(); 49 env.close(); 50 } catch (DatabaseException E) { 51 } 52 53 TestUtils.removeLogFiles("TearDown", envHome, true); 54 } 55 56 private void initEnv() 57 throws DatabaseException { 58 59 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 60 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "4"); 61 envConfig.setTransactional(true); 62 envConfig.setAllowCreate(true); 63 env = new Environment(envHome, envConfig); 64 65 String databaseName = "testDb"; 66 Transaction txn = env.beginTransaction(null, null); 67 DatabaseConfig dbConfig = new DatabaseConfig(); 68 dbConfig.setTransactional(true); 69 dbConfig.setAllowCreate(true); 70 db = env.openDatabase(txn, databaseName, dbConfig); 71 txn.commit(); 72 } 73 74 77 public void test0Split() 78 throws Exception { 79 80 Key.DUMP_BINARY = true; 81 try { 82 83 for (int i = 160; i > 0; i-= 10) { 84 assertEquals(OperationStatus.SUCCESS, 85 db.put(null, new DatabaseEntry 86 (new byte[] {(byte)i }), 87 new DatabaseEntry(new byte[] {1}))); 88 } 89 if (DEBUG) { 90 System.out.println("<dump>"); 91 DbInternal.dbGetDatabaseImpl(db).getTree().dump(); 92 } 93 assertEquals(OperationStatus.SUCCESS, 94 db.put(null, new DatabaseEntry(new byte[]{(byte)151}), 95 new DatabaseEntry(new byte[] {1}))); 96 assertEquals(OperationStatus.SUCCESS, 97 db.put(null, new DatabaseEntry(new byte[]{(byte)152}), 98 new DatabaseEntry(new byte[] {1}))); 99 assertEquals(OperationStatus.SUCCESS, 100 db.put(null, new DatabaseEntry(new byte[]{(byte)153}), 101 new DatabaseEntry(new byte[] {1}))); 102 103 if (DEBUG) { 104 DbInternal.dbGetDatabaseImpl(db).getTree().dump(); 105 System.out.println("</dump>"); 106 } 107 108 134 assertEquals(OperationStatus.SUCCESS, 135 db.delete(null, 136 new DatabaseEntry(new byte[]{(byte) 130}))); 137 assertEquals(OperationStatus.SUCCESS, 138 db.delete(null, 139 new DatabaseEntry(new byte[]{(byte) 140}))); 140 env.compress(); 141 142 168 assertEquals(OperationStatus.SUCCESS, 169 db.put(null, new DatabaseEntry(new byte[]{(byte)140}), 170 new DatabaseEntry(new byte[] {1}))); 171 172 197 for (int i = 154; i < 159; i++) { 198 assertEquals(OperationStatus.SUCCESS, 199 db.put(null, 200 new DatabaseEntry(new byte[]{(byte)i}), 201 new DatabaseEntry(new byte[] {1}))); 202 } 203 204 228 DatabaseEntry data = new DatabaseEntry(); 229 assertEquals(OperationStatus.SUCCESS, 230 db.get(null, new DatabaseEntry(new byte[] 231 { (byte)140 }), 232 data, LockMode.DEFAULT)); 233 234 } catch (Throwable t) { 235 t.printStackTrace(); 236 throw new Exception (t); 237 } 238 } 239 } 240 | Popular Tags |