1 8 9 package com.sleepycat.je.logversion; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 14 import junit.framework.TestCase; 15 16 import com.sleepycat.je.DatabaseException; 17 import com.sleepycat.je.EnvironmentConfig; 18 import com.sleepycat.je.Environment; 19 import com.sleepycat.je.log.FileManager; 20 import com.sleepycat.je.log.LogException; 21 import com.sleepycat.je.util.TestUtils; 22 23 30 public class LogHeaderVersionTest extends TestCase { 31 32 private File envHome; 33 34 public LogHeaderVersionTest() { 35 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 36 } 37 38 public void setUp() 39 throws IOException { 40 41 TestUtils.removeLogFiles("Setup", envHome, false); 42 TestUtils.removeFiles("Setup", envHome, FileManager.DEL_SUFFIX); 43 } 44 45 public void tearDown() 46 throws Exception { 47 48 try { 49 TestUtils.removeLogFiles("tearDown", envHome, true); 51 TestUtils.removeFiles("tearDown", envHome, FileManager.DEL_SUFFIX); 52 } catch (Throwable e) { 54 System.out.println("tearDown: " + e); 55 } 56 57 envHome = null; 58 } 59 60 66 public void testGreaterVersionNotAllowed() 67 throws DatabaseException, IOException { 68 69 TestUtils.loadLog(getClass(), Utils.MAX_VERSION_NAME, envHome); 70 71 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 72 envConfig.setAllowCreate(false); 73 envConfig.setTransactional(true); 74 75 try { 76 Environment env = new Environment(envHome, envConfig); 77 try { 78 env.close(); 79 } catch (Exception ignore) {} 80 } catch (DatabaseException e) { 81 if (e.getCause() instanceof LogException) { 82 83 return; 84 } 85 } 86 fail("Expected LogException"); 87 } 88 89 96 public void testLesserVersionNotUpdated() 97 throws DatabaseException, IOException { 98 99 TestUtils.loadLog(getClass(), Utils.MIN_VERSION_NAME, envHome); 100 File logFile = new File (envHome, TestUtils.LOG_FILE_NAME); 101 long origFileSize = logFile.length(); 102 103 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 104 envConfig.setAllowCreate(false); 105 envConfig.setTransactional(true); 106 107 Environment env = new Environment(envHome, envConfig); 108 env.sync(); 109 env.close(); 110 111 assertEquals(origFileSize, logFile.length()); 112 } 113 } 114 | Popular Tags |