1 8 9 package com.sleepycat.je.cleaner; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 14 import junit.framework.TestCase; 15 16 import com.sleepycat.je.CheckpointConfig; 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.log.FileManager; 28 import com.sleepycat.je.util.TestUtils; 29 30 78 public class SR12885Test extends TestCase { 79 80 private static final String DB_NAME = "foo"; 81 82 private static final CheckpointConfig forceConfig = new CheckpointConfig(); 83 static { 84 forceConfig.setForce(true); 85 } 86 87 private File envHome; 88 private Environment env; 89 private Database db; 90 91 public SR12885Test() { 92 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 93 } 94 95 public void setUp() 96 throws IOException , DatabaseException { 97 98 TestUtils.removeLogFiles("Setup", envHome, false); 99 TestUtils.removeFiles("Setup", envHome, FileManager.DEL_SUFFIX); 100 } 101 102 public void tearDown() 103 throws IOException , DatabaseException { 104 105 try { 106 if (env != null) { 107 env.close(); 108 } 109 } catch (Throwable e) { 110 System.out.println("tearDown: " + e); 111 } 112 113 try { 114 TestUtils.removeLogFiles("tearDown", envHome, true); 115 TestUtils.removeFiles("tearDown", envHome, FileManager.DEL_SUFFIX); 116 } catch (Throwable e) { 117 System.out.println("tearDown: " + e); 118 } 119 120 db = null; 121 env = null; 122 envHome = null; 123 } 124 125 128 private void openEnv() 129 throws DatabaseException { 130 131 EnvironmentConfig config = TestUtils.initEnvConfig(); 132 DbInternal.disableParameterValidation(config); 133 config.setTransactional(true); 134 config.setAllowCreate(true); 135 136 config.setConfigParam 137 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 138 config.setConfigParam 139 (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false"); 140 config.setConfigParam 141 (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 142 config.setConfigParam 143 (EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false"); 144 145 config.setConfigParam(EnvironmentParams.LOG_FILE_MAX.getName(), 146 Integer.toString(1024)); 147 env = new Environment(envHome, config); 148 149 openDb(); 150 } 151 152 155 private void openDb() 156 throws DatabaseException { 157 158 DatabaseConfig dbConfig = new DatabaseConfig(); 159 dbConfig.setTransactional(true); 160 dbConfig.setAllowCreate(true); 161 db = env.openDatabase(null, DB_NAME, dbConfig); 162 } 163 164 167 private void closeEnv() 168 throws DatabaseException { 169 170 if (db != null) { 171 db.close(); 172 db = null; 173 } 174 if (env != null) { 175 env.close(); 176 env = null; 177 } 178 } 179 180 public void testSR12885() 181 throws DatabaseException { 182 183 openEnv(); 184 185 final int COUNT = 10; 186 DatabaseEntry key = new DatabaseEntry(); 187 DatabaseEntry data = new DatabaseEntry(TestUtils.getTestArray(0)); 188 OperationStatus status; 189 190 191 for (int i = 0; i < COUNT; i += 1) { 192 key.setData(TestUtils.getTestArray(i)); 193 status = db.putNoOverwrite(null, key, data); 194 assertEquals(OperationStatus.SUCCESS, status); 195 } 196 197 201 for (int i = 1; i < COUNT; i += 1) { 202 key.setData(TestUtils.getTestArray(i)); 203 status = db.delete(null, key); 204 assertEquals(OperationStatus.SUCCESS, status); 205 } 206 207 213 env.checkpoint(forceConfig); 214 int cleaned = env.cleanLog(); 215 assertTrue("cleaned=" + cleaned, cleaned > 0); 216 217 222 Transaction txn = env.beginTransaction(null, null); 223 key.setData(TestUtils.getTestArray(0)); 224 status = db.delete(txn, key); 225 assertEquals(OperationStatus.SUCCESS, status); 226 status = db.putNoOverwrite(txn, key, data); 227 assertEquals(OperationStatus.SUCCESS, status); 228 229 236 env.checkpoint(forceConfig); 237 238 243 txn.abort(); 244 txn = env.beginTransaction(null, null); 245 key.setData(TestUtils.getTestArray(0)); 246 status = db.delete(txn, key); 247 assertEquals(OperationStatus.SUCCESS, status); 248 249 265 env.checkpoint(forceConfig); 266 txn.abort(); 267 status = db.get(null, key, data, null); 268 assertEquals(OperationStatus.SUCCESS, status); 269 270 271 272 closeEnv(); 273 } 274 } 275 | Popular Tags |