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.bind.tuple.StringBinding; 17 import com.sleepycat.je.Database; 18 import com.sleepycat.je.DatabaseConfig; 19 import com.sleepycat.je.DatabaseEntry; 20 import com.sleepycat.je.DatabaseException; 21 import com.sleepycat.je.DbInternal; 22 import com.sleepycat.je.Environment; 23 import com.sleepycat.je.EnvironmentConfig; 24 import com.sleepycat.je.OperationStatus; 25 import com.sleepycat.je.Transaction; 26 import com.sleepycat.je.config.EnvironmentParams; 27 import com.sleepycat.je.util.TestUtils; 28 29 59 public class SR13034Test extends TestCase { 60 61 private File envHome; 62 private Environment env; 63 private Database db; 64 65 public SR13034Test() { 66 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 67 } 68 69 public void setUp() 70 throws IOException { 71 72 TestUtils.removeLogFiles("Setup", envHome, false); 73 } 74 75 public void tearDown() 76 throws Exception { 77 78 try { 79 if (env != null) { 80 env.close(); 81 } 82 } catch (Exception e) { 83 System.out.println("During tearDown: " + e); 84 } 85 86 env = null; 87 db = null; 88 89 TestUtils.removeLogFiles("TearDown", envHome, false); 90 } 91 92 private void open() 93 throws DatabaseException { 94 95 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 96 envConfig.setAllowCreate(true); 97 envConfig.setTransactional(true); 98 99 envConfig.setConfigParam 100 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 101 envConfig.setConfigParam 102 (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false"); 103 envConfig.setConfigParam 104 (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 105 envConfig.setConfigParam 106 (EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false"); 107 env = new Environment(envHome, envConfig); 108 109 DatabaseConfig dbConfig = new DatabaseConfig(); 110 dbConfig.setAllowCreate(true); 111 dbConfig.setTransactional(true); 112 dbConfig.setSortedDuplicates(true); 113 db = env.openDatabase(null, "foo", dbConfig); 114 } 115 116 private void close() 117 throws DatabaseException { 118 119 db.close(); 120 db = null; 121 122 env.close(); 123 env = null; 124 } 125 126 public void testSR13034() 127 throws DatabaseException { 128 129 open(); 130 131 DatabaseEntry key = new DatabaseEntry(); 132 DatabaseEntry data = new DatabaseEntry(); 133 OperationStatus status; 134 Transaction txn; 135 136 140 txn = env.beginTransaction(null, null); 141 StringBinding.stringToEntry("A", key); 142 StringBinding.stringToEntry("C", data); 143 status = db.putNoOverwrite(txn, key, data); 144 assertEquals(OperationStatus.SUCCESS, status); 145 status = db.delete(txn, key); 146 assertEquals(OperationStatus.SUCCESS, status); 147 txn.commit(); 148 149 153 txn = env.beginTransaction(null, null); 154 StringBinding.stringToEntry("A", key); 155 StringBinding.stringToEntry("A", data); 156 status = db.putNoDupData(txn, key, data); 157 StringBinding.stringToEntry("A", key); 158 StringBinding.stringToEntry("B", data); 159 status = db.putNoDupData(txn, key, data); 160 assertEquals(OperationStatus.SUCCESS, status); 161 txn.abort(); 162 163 168 db.close(); 169 DbInternal.envGetEnvironmentImpl(env).close(false); 170 open(); 171 172 close(); 173 } 174 } 175 | Popular Tags |