public virtual void TestClonedStreamsClosing() { SetUp_2(); CompoundFileReader cr = new CompoundFileReader(dir, "f.comp", null); // basic clone IndexInput expected = dir.OpenInput("f11", null); // this test only works for FSIndexInput Assert.IsTrue(_TestHelper.IsSimpleFSIndexInput(expected)); Assert.IsTrue(_TestHelper.IsSimpleFSIndexInputOpen(expected)); IndexInput one = cr.OpenInput("f11", null); Assert.IsTrue(IsCSIndexInputOpen(one)); IndexInput two = (IndexInput)one.Clone(null); Assert.IsTrue(IsCSIndexInputOpen(two)); AssertSameStreams("basic clone one", expected, one); expected.Seek(0, null); AssertSameStreams("basic clone two", expected, two); // Now close the first stream one.Dispose(); Assert.IsTrue(IsCSIndexInputOpen(one), "Only close when cr is closed"); // The following should really fail since we couldn't expect to // access a file once close has been called on it (regardless of // buffering and/or clone magic) expected.Seek(0, null); two.Seek(0, null); AssertSameStreams("basic clone two/2", expected, two); // Now close the compound reader cr.Dispose(); Assert.IsFalse(IsCSIndexInputOpen(one), "Now closed one"); Assert.IsFalse(IsCSIndexInputOpen(two), "Now closed two"); // The following may also fail since the compound stream is closed expected.Seek(0, null); two.Seek(0, null); //assertSameStreams("basic clone two/3", expected, two); // Now close the second clone two.Dispose(); expected.Seek(0, null); two.Seek(0, null); //assertSameStreams("basic clone two/4", expected, two); expected.Dispose(); }