From 230696f7963c681d84c650de5d0e3c48fa2ff9db Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sat, 8 Sep 2012 12:16:47 +0000 Subject: [PATCH] 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 --- .../apache/lucene/store/TestMultiMMap.java | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java index 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<