KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > FileReaderTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2005,2006 Oracle. All rights reserved.
5  *
6  * $Id: FileReaderTest.java,v 1.11 2006/10/30 21:14:46 bostic Exp $
7  */

8
9 package com.sleepycat.je.log;
10
11 import java.io.File JavaDoc;
12 import java.io.IOException JavaDoc;
13
14 import junit.framework.TestCase;
15
16 import com.sleepycat.je.DatabaseException;
17 import com.sleepycat.je.DbInternal;
18 import com.sleepycat.je.Environment;
19 import com.sleepycat.je.EnvironmentConfig;
20 import com.sleepycat.je.dbi.EnvironmentImpl;
21 import com.sleepycat.je.util.TestUtils;
22 import com.sleepycat.je.utilint.DbLsn;
23
24
25 /**
26  * Test edge cases for file reading.
27  */

28 public class FileReaderTest extends TestCase {
29
30     static private final boolean DEBUG = false;
31
32     private File JavaDoc envHome;
33
34
35     public FileReaderTest()
36         throws Exception JavaDoc {
37
38         envHome = new File JavaDoc(System.getProperty(TestUtils.DEST_DIR));
39     }
40
41     public void setUp()
42         throws IOException JavaDoc, DatabaseException {
43
44         TestUtils.removeFiles("Setup", envHome, FileManager.JE_SUFFIX);
45     }
46     
47     public void tearDown()
48         throws IOException JavaDoc, DatabaseException {
49
50         TestUtils.removeFiles("TearDown", envHome, FileManager.JE_SUFFIX);
51     }
52
53     /*
54      * Check that we can handle the case when we are reading forward
55      * with other than the LastFileReader, and the last file exists but is
56      * 0 length. This case came up when a run of MemoryStress was killed off,
57      * and we then attempted to read it with DbPrintLog.
58      */

59     public void testEmptyExtraFile()
60         throws Throwable JavaDoc {
61     
62     EnvironmentConfig envConfig = TestUtils.initEnvConfig();
63         envConfig.setAllowCreate(true);
64         Environment env = new Environment(envHome, envConfig);
65
66         try {
67             /* Make an environment. */
68             env.sync();
69
70             /* Add an extra, 0 length file */
71             EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
72
73             File JavaDoc newFile = new File JavaDoc(envHome, "00000001.jdb");
74             newFile.createNewFile();
75
76             INFileReader reader = new INFileReader(envImpl,
77                                                    1000,
78                                                    DbLsn.NULL_LSN,
79                            DbLsn.NULL_LSN,
80                                                    false,
81                                                    false,
82                                                    DbLsn.NULL_LSN,
83                                                    null);
84             while (reader.readNextEntry()) {
85             }
86
87         } catch (Throwable JavaDoc t) {
88             t.printStackTrace();
89             throw t;
90         } finally {
91             env.close();
92         }
93     }
94 }
95
Popular Tags