Apache Solr open-source search software
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.
Uwe Schindler230696f7963c
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.javaindex 5db2fc6d914..2d9240e7867 100644--- a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java+++ b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java@@ -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);