public virtual void TestCloneSliceClose() { MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneSliceClose")); IndexOutput io = mmapDir.CreateOutput("bytes", NewIOContext(Random())); io.WriteInt32(1); io.WriteInt32(2); io.Dispose(); IndexInputSlicer slicer = mmapDir.CreateSlicer("bytes", NewIOContext(Random())); IndexInput one = slicer.OpenSlice("first int", 0, 4); IndexInput two = slicer.OpenSlice("second int", 4, 4); one.Dispose(); try { one.ReadInt32(); Assert.Fail("Must throw ObjectDisposedException"); } #pragma warning disable 168 catch (ObjectDisposedException ignore) #pragma warning restore 168 { // pass } Assert.AreEqual(2, two.ReadInt32()); // reopen a new slice "one": one = slicer.OpenSlice("first int", 0, 4); Assert.AreEqual(1, one.ReadInt32()); one.Dispose(); two.Dispose(); slicer.Dispose(); mmapDir.Dispose(); }
public virtual void TestCloneSliceSafety() { MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneSliceSafety")); IndexOutput io = mmapDir.CreateOutput("bytes", NewIOContext(Random)); io.WriteInt32(1); io.WriteInt32(2); io.Dispose(); IndexInputSlicer slicer = mmapDir.CreateSlicer("bytes", NewIOContext(Random)); IndexInput one = slicer.OpenSlice("first int", 0, 4); IndexInput two = slicer.OpenSlice("second int", 4, 4); IndexInput three = (IndexInput)one.Clone(); // clone of clone IndexInput four = (IndexInput)two.Clone(); // clone of clone slicer.Dispose(); try { one.ReadInt32(); Assert.Fail("Must throw ObjectDisposedException"); } catch (Exception ignore) when(ignore.IsAlreadyClosedException()) { // pass } try { two.ReadInt32(); Assert.Fail("Must throw ObjectDisposedException"); } catch (Exception ignore) when(ignore.IsAlreadyClosedException()) { // pass } try { three.ReadInt32(); Assert.Fail("Must throw ObjectDisposedException"); } catch (Exception ignore) when(ignore.IsAlreadyClosedException()) { // pass } try { four.ReadInt32(); Assert.Fail("Must throw ObjectDisposedException"); } catch (Exception ignore) when(ignore.IsAlreadyClosedException()) { // pass } one.Dispose(); two.Dispose(); three.Dispose(); four.Dispose(); // test double-close of slicer: slicer.Dispose(); mmapDir.Dispose(); }
/// <summary> /// NOTE: this was readInt() in Lucene /// </summary> public override int ReadInt32() { EnsureOpen(); return(@delegate.ReadInt32()); }