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 SR10597Test 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 SR10597Test() { 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 env = new Environment(envHome, config); 99 100 openDb(); 101 } 102 103 106 private void openDb() 107 throws DatabaseException { 108 109 DatabaseConfig dbConfig = new DatabaseConfig(); 110 dbConfig.setAllowCreate(true); 111 dbConfig.setSortedDuplicates(true); 112 db = env.openDatabase(null, DB_NAME, dbConfig); 113 } 114 115 118 private void closeEnv() 119 throws DatabaseException { 120 121 if (db != null) { 122 db.close(); 123 db = null; 124 } 125 if (env != null) { 126 env.close(); 127 env = null; 128 } 129 } 130 131 133 public void testSR10597() 134 throws DatabaseException { 135 136 openEnv(); 137 138 139 final int COUNT = 10; 140 DatabaseEntry key = new DatabaseEntry(TestUtils.getTestArray(0)); 141 DatabaseEntry data = new DatabaseEntry(); 142 for (int i = 0; i < COUNT; i += 1) { 143 data.setData(TestUtils.getTestArray(i)); 144 db.put(null, key, data); 145 } 146 Cursor cursor = db.openCursor(null, null); 147 assertEquals(OperationStatus.SUCCESS, 148 cursor.getSearchKey(key, data, null)); 149 assertEquals(COUNT, cursor.count()); 150 cursor.close(); 151 152 153 db.delete(null, key); 154 env.compress(); 155 data.setData(TestUtils.getTestArray(0)); 156 157 158 db.put(null, key, data); 159 160 161 env.checkpoint(forceConfig); 162 int cleaned = env.cleanLog(); 163 assertTrue("cleaned=" + cleaned, cleaned > 0); 164 165 173 closeEnv(); 174 } 175 } 176 | Popular Tags |