1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2005,2008 Oracle. All rights reserved.
*
* $Id: FileReaderTest.java,v 1.16 2008/06/30 20:54:47 linda Exp $
*/
package com.sleepycat.je.log;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.DbInternal;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.dbi.EnvironmentImpl;
import com.sleepycat.je.util.TestUtils;
import com.sleepycat.je.utilint.DbLsn;
/**
* Test edge cases for file reading.
*/
public class FileReaderTest extends TestCase {
private File envHome;
public FileReaderTest()
throws Exception {
envHome = new File(System.getProperty(TestUtils.DEST_DIR));
}
public void setUp()
throws IOException, DatabaseException {
TestUtils.removeFiles("Setup", envHome, FileManager.JE_SUFFIX);
}
public void tearDown()
throws IOException, DatabaseException {
TestUtils.removeFiles("TearDown", envHome, FileManager.JE_SUFFIX);
}
/*
* Check that we can handle the case when we are reading forward
* with other than the LastFileReader, and the last file exists but is
* 0 length. This case came up when a run of MemoryStress was killed off,
* and we then attempted to read it with DbPrintLog.
*/
public void testEmptyExtraFile()
throws Throwable {
EnvironmentConfig envConfig = TestUtils.initEnvConfig();
envConfig.setAllowCreate(true);
Environment env = new Environment(envHome, envConfig);
try {
/* Make an environment. */
env.sync();
/* Add an extra, 0 length file */
EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
File newFile = new File(envHome, "00000001.jdb");
newFile.createNewFile();
INFileReader reader = new INFileReader(envImpl,
1000,
DbLsn.NULL_LSN,
DbLsn.NULL_LSN,
false,
false,
DbLsn.NULL_LSN,
DbLsn.NULL_LSN,
null);
while (reader.readNextEntry()) {
}
} catch (Throwable t) {
t.printStackTrace();
throw t;
} finally {
env.close();
}
}
}
|