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.bind.tuple.IntegerBinding; 17 import com.sleepycat.je.CheckpointConfig; 18 import com.sleepycat.je.Database; 19 import com.sleepycat.je.DatabaseConfig; 20 import com.sleepycat.je.DatabaseEntry; 21 import com.sleepycat.je.DatabaseException; 22 import com.sleepycat.je.DbInternal; 23 import com.sleepycat.je.Environment; 24 import com.sleepycat.je.EnvironmentConfig; 25 import com.sleepycat.je.OperationStatus; 26 import com.sleepycat.je.config.EnvironmentParams; 27 import com.sleepycat.je.log.FileManager; 28 import com.sleepycat.je.util.TestUtils; 29 30 52 public class SR12978Test extends TestCase { 53 54 private static final String DB_NAME = "foo"; 55 56 private static final CheckpointConfig forceConfig = new CheckpointConfig(); 57 static { 58 forceConfig.setForce(true); 59 } 60 61 private File envHome; 62 private Environment env; 63 private Database db; 64 65 public SR12978Test() { 66 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 67 } 68 69 public void setUp() 70 throws IOException , DatabaseException { 71 72 TestUtils.removeLogFiles("Setup", envHome, false); 73 TestUtils.removeFiles("Setup", envHome, FileManager.DEL_SUFFIX); 74 } 75 76 public void tearDown() 77 throws IOException , DatabaseException { 78 79 try { 80 if (env != null) { 81 env.close(); 82 } 83 } catch (Throwable e) { 84 System.out.println("tearDown: " + e); 85 } 86 87 try { 88 TestUtils.removeLogFiles("tearDown", envHome, true); 89 TestUtils.removeFiles("tearDown", envHome, FileManager.DEL_SUFFIX); 90 } catch (Throwable e) { 91 System.out.println("tearDown: " + e); 92 } 93 94 db = null; 95 env = null; 96 envHome = null; 97 } 98 99 102 private void open() 103 throws DatabaseException { 104 105 EnvironmentConfig config = TestUtils.initEnvConfig(); 106 DbInternal.disableParameterValidation(config); 107 config.setAllowCreate(true); 108 109 config.setConfigParam 110 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 111 config.setConfigParam 112 (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false"); 113 config.setConfigParam 114 (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 115 config.setConfigParam 116 (EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false"); 117 118 config.setConfigParam 119 (EnvironmentParams.LOG_FILE_MAX.getName(), "10240"); 120 config.setConfigParam 121 (EnvironmentParams.CLEANER_MIN_UTILIZATION.getName(), "90"); 122 123 env = new Environment(envHome, config); 124 125 DatabaseConfig dbConfig = new DatabaseConfig(); 126 dbConfig.setAllowCreate(true); 127 dbConfig.setSortedDuplicates(true); 128 db = env.openDatabase(null, DB_NAME, dbConfig); 129 } 130 131 134 private void close() 135 throws DatabaseException { 136 137 if (db != null) { 138 db.close(); 139 db = null; 140 } 141 if (env != null) { 142 env.close(); 143 env = null; 144 } 145 } 146 147 149 public void testSR12978() 150 throws DatabaseException { 151 152 open(); 153 154 final int COUNT = 500; 155 DatabaseEntry key = new DatabaseEntry(); 156 DatabaseEntry data = new DatabaseEntry(); 157 OperationStatus status; 158 159 164 IntegerBinding.intToEntry(0, data); 165 for (int i = 0; i < COUNT; i += 4) { 166 167 IntegerBinding.intToEntry(i + 0, key); 168 status = db.putNoOverwrite(null, key, data); 169 assertEquals(OperationStatus.SUCCESS, status); 170 171 IntegerBinding.intToEntry(i + 1, key); 172 status = db.putNoOverwrite(null, key, data); 173 assertEquals(OperationStatus.SUCCESS, status); 174 175 status = db.delete(null, key); 176 assertEquals(OperationStatus.SUCCESS, status); 177 } 178 179 180 env.checkpoint(forceConfig); 181 int nCleaned = env.cleanLog(); 182 assertTrue(nCleaned > 0); 183 184 185 IntegerBinding.intToEntry(1, data); 186 for (int i = 0; i < COUNT; i += 4) { 187 188 IntegerBinding.intToEntry(i + 0, key); 189 status = db.putNoDupData(null, key, data); 190 assertEquals(OperationStatus.SUCCESS, status); 191 } 192 193 197 IntegerBinding.intToEntry(0, data); 198 for (int i = 0; i < COUNT; i += 4) { 199 200 IntegerBinding.intToEntry(i + 2, key); 201 status = db.putNoOverwrite(null, key, data); 202 assertEquals(OperationStatus.SUCCESS, status); 203 204 IntegerBinding.intToEntry(i + 3, key); 205 status = db.putNoOverwrite(null, key, data); 206 assertEquals(OperationStatus.SUCCESS, status); 207 } 208 209 close(); 210 } 211 } 212 | Popular Tags |