mirror of https://github.com/apache/lucene.git
LUCENE-4364: Include a test to make sure, the clones/slices can be closed without affecting the original or other opened ones! NOTE: The test failure on windows was depending on GC if it unmaps buffer before the tearDown runs.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1382291 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a0ed57c99
commit
230696f796
|
@ -71,7 +71,7 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
}
|
||||
try {
|
||||
three.readVInt();
|
||||
fail("Must throw AlreadyClosedExveption");
|
||||
fail("Must throw AlreadyClosedException");
|
||||
} catch (AlreadyClosedException ignore) {
|
||||
// pass
|
||||
}
|
||||
|
@ -80,6 +80,27 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
mmapDir.close();
|
||||
}
|
||||
|
||||
public void testCloneClose() throws Exception {
|
||||
MMapDirectory mmapDir = new MMapDirectory(_TestUtil.getTempDir("testCloneClose"));
|
||||
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
|
||||
io.writeVInt(5);
|
||||
io.close();
|
||||
IndexInput one = mmapDir.openInput("bytes", IOContext.DEFAULT);
|
||||
IndexInput two = one.clone();
|
||||
IndexInput three = two.clone(); // clone of clone
|
||||
two.close();
|
||||
assertEquals(5, one.readVInt());
|
||||
try {
|
||||
two.readVInt();
|
||||
fail("Must throw AlreadyClosedException");
|
||||
} catch (AlreadyClosedException ignore) {
|
||||
// pass
|
||||
}
|
||||
assertEquals(5, three.readVInt());
|
||||
one.close();
|
||||
mmapDir.close();
|
||||
}
|
||||
|
||||
public void testCloneSliceSafety() throws Exception {
|
||||
MMapDirectory mmapDir = new MMapDirectory(_TestUtil.getTempDir("testCloneSliceSafety"));
|
||||
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
|
||||
|
@ -106,13 +127,13 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
}
|
||||
try {
|
||||
three.readInt();
|
||||
fail("Must throw AlreadyClosedExveption");
|
||||
fail("Must throw AlreadyClosedException");
|
||||
} catch (AlreadyClosedException ignore) {
|
||||
// pass
|
||||
}
|
||||
try {
|
||||
four.readInt();
|
||||
fail("Must throw AlreadyClosedExveption");
|
||||
fail("Must throw AlreadyClosedException");
|
||||
} catch (AlreadyClosedException ignore) {
|
||||
// pass
|
||||
}
|
||||
|
@ -123,6 +144,32 @@ public class TestMultiMMap extends LuceneTestCase {
|
|||
mmapDir.close();
|
||||
}
|
||||
|
||||
public void testCloneSliceClose() throws Exception {
|
||||
MMapDirectory mmapDir = new MMapDirectory(_TestUtil.getTempDir("testCloneSliceClose"));
|
||||
IndexOutput io = mmapDir.createOutput("bytes", newIOContext(random()));
|
||||
io.writeInt(1);
|
||||
io.writeInt(2);
|
||||
io.close();
|
||||
IndexInputSlicer slicer = mmapDir.createSlicer("bytes", newIOContext(random()));
|
||||
IndexInput one = slicer.openSlice("first int", 0, 4);
|
||||
IndexInput two = slicer.openSlice("second int", 4, 4);
|
||||
one.close();
|
||||
try {
|
||||
one.readInt();
|
||||
fail("Must throw AlreadyClosedException");
|
||||
} catch (AlreadyClosedException ignore) {
|
||||
// pass
|
||||
}
|
||||
assertEquals(2, two.readInt());
|
||||
// reopen a new slice "one":
|
||||
one = slicer.openSlice("first int", 0, 4);
|
||||
assertEquals(1, one.readInt());
|
||||
one.close();
|
||||
two.close();
|
||||
slicer.close();
|
||||
mmapDir.close();
|
||||
}
|
||||
|
||||
public void testSeekZero() throws Exception {
|
||||
for (int i = 0; i < 31; i++) {
|
||||
MMapDirectory mmapDir = new MMapDirectory(_TestUtil.getTempDir("testSeekZero"), null, 1<<i);
|
||||
|
|
Loading…
Reference in New Issue