1 8 9 package com.sleepycat.je.log; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 import java.io.RandomAccessFile ; 14 15 import junit.framework.TestCase; 16 17 import com.sleepycat.je.DatabaseException; 18 import com.sleepycat.je.DbInternal; 19 import com.sleepycat.je.Environment; 20 import com.sleepycat.je.EnvironmentConfig; 21 import com.sleepycat.je.dbi.EnvironmentImpl; 22 import com.sleepycat.je.recovery.NoRootException; 23 import com.sleepycat.je.util.TestUtils; 24 25 public class FileEdgeCaseTest extends TestCase { 26 27 private File envHome; 28 private Environment env; 29 private String firstFile; 30 31 public FileEdgeCaseTest() { 32 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 33 } 34 35 public void setUp() 36 throws IOException { 37 38 TestUtils.removeLogFiles("Setup", envHome, false); 39 } 40 41 public void tearDown() 42 throws Exception { 43 44 48 try { 49 if (env != null) { 50 env.close(); 51 env = null; 52 } 53 } catch (DatabaseException e) { 54 e.printStackTrace(); 55 } 57 TestUtils.removeLogFiles("TearDown", envHome, false); 58 } 59 60 85 public void testPostChecksumError() 86 throws IOException , DatabaseException { 87 88 EnvironmentConfig config = new EnvironmentConfig(); 89 config.setAllowCreate(true); 90 env = new Environment(envHome, config); 91 92 EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env); 93 FileManager fm = envImpl.getFileManager(); 94 firstFile = fm.getFullFileName(0, FileManager.JE_SUFFIX); 95 96 env.close(); 97 env = null; 98 99 100 corruptSecondEntry(); 101 102 106 try { 107 env = new Environment(envHome, config); 108 } catch (NoRootException expected) { 109 } 110 111 115 try { 116 env = new Environment(envHome, config); 117 } catch (NoRootException expected) { 118 } 119 } 120 121 124 private void corruptSecondEntry() 125 throws IOException { 126 127 RandomAccessFile file = 128 new RandomAccessFile (firstFile, 129 FileManager.FileMode. 130 READWRITE_MODE.getModeValue()); 131 132 int headerSize = FileHeader.entrySize(); 133 try { 134 byte [] junk = new byte[20]; 135 file.seek(headerSize + LogManager.HEADER_BYTES + 2); 136 file.write(junk); 137 } catch (Exception e) { 138 e.printStackTrace(); 139 } finally { 140 file.close(); 141 } 142 } 143 } 144 | Popular Tags |