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.Cursor; 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 public class SR10553Test extends TestCase { 31 32 private static final String DB_NAME = "foo"; 33 34 private static final CheckpointConfig forceConfig = new CheckpointConfig(); 35 static { 36 forceConfig.setForce(true); 37 } 38 39 private File envHome; 40 private Environment env; 41 private Database db; 42 43 public SR10553Test() { 44 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 45 } 46 47 public void setUp() 48 throws IOException , DatabaseException { 49 50 TestUtils.removeLogFiles("Setup", envHome, false); 51 TestUtils.removeFiles("Setup", envHome, FileManager.DEL_SUFFIX); 52 } 53 54 public void tearDown() 55 throws IOException , DatabaseException { 56 57 try { 58 if (env != null) { 59 env.close(); 60 } 61 } catch (Throwable e) { 62 System.out.println("tearDown: " + e); 63 } 64 65 try { 66 TestUtils.removeLogFiles("tearDown", envHome, true); 67 TestUtils.removeFiles("tearDown", envHome, FileManager.DEL_SUFFIX); 68 } catch (Throwable e) { 69 System.out.println("tearDown: " + e); 70 } 71 72 db = null; 73 env = null; 74 envHome = null; 75 } 76 77 80 private void openEnv() 81 throws DatabaseException { 82 83 EnvironmentConfig config = TestUtils.initEnvConfig(); 84 DbInternal.disableParameterValidation(config); 85 config.setAllowCreate(true); 86 87 config.setConfigParam 88 (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false"); 89 config.setConfigParam 90 (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false"); 91 config.setConfigParam 92 (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 93 config.setConfigParam 94 (EnvironmentParams.ENV_RUN_INCOMPRESSOR.getName(), "false"); 95 96 config.setConfigParam(EnvironmentParams.LOG_FILE_MAX.getName(), 97 Integer.toString(1024)); 98 99 config.setConfigParam(EnvironmentParams.MAX_MEMORY.getName(), 100 Integer.toString(1024 * 96)); 101 102 config.setConfigParam 103 (EnvironmentParams.CLEANER_TRACK_DETAIL.getName(), "false"); 104 config.setConfigParam(EnvironmentParams.NUM_LOG_BUFFERS.getName(), 105 Integer.toString(2)); 106 107 config.setConfigParam(EnvironmentParams.LOG_MEM_SIZE.getName(), 108 Integer.toString(7000)); 109 110 env = new Environment(envHome, config); 111 112 openDb(); 113 } 114 115 118 private void openDb() 119 throws DatabaseException { 120 121 DatabaseConfig dbConfig = new DatabaseConfig(); 122 dbConfig.setAllowCreate(true); 123 dbConfig.setSortedDuplicates(true); 124 db = env.openDatabase(null, DB_NAME, dbConfig); 125 } 126 127 130 private void closeEnv() 131 throws DatabaseException { 132 133 if (db != null) { 134 db.close(); 135 db = null; 136 } 137 if (env != null) { 138 env.close(); 139 env = null; 140 } 141 } 142 143 145 public void testSR10553() 146 throws DatabaseException { 147 148 openEnv(); 149 150 151 final int COUNT = 10; 152 DatabaseEntry key = new DatabaseEntry(TestUtils.getTestArray(0)); 153 DatabaseEntry data = new DatabaseEntry(); 154 for (int i = 0; i < COUNT; i += 1) { 155 data.setData(TestUtils.getTestArray(i)); 156 db.put(null, key, data); 157 } 158 Cursor cursor = db.openCursor(null, null); 159 assertEquals(OperationStatus.SUCCESS, 160 cursor.getSearchKey(key, data, null)); 161 assertEquals(COUNT, cursor.count()); 162 cursor.close(); 163 164 165 db.delete(null, key); 166 167 168 env.checkpoint(forceConfig); 169 int cleaned = env.cleanLog(); 170 assertTrue("cleaned=" + cleaned, cleaned > 0); 171 172 173 env.evictMemory(); 174 175 176 cursor = db.openCursor(null, null); 177 for (OperationStatus status = cursor.getFirst(key, data, null); 178 status == OperationStatus.SUCCESS; 179 status = cursor.getNext(key, data, null)) { 180 } 181 cursor.close(); 182 183 189 closeEnv(); 190 } 191 } 192 | Popular Tags |