MMapDirectory mmapDir = new MMapDirectory(_TestUtil.getTempDir("testCloneSliceSafety"));
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);
IndexInput three = one.clone(); // clone of clone
IndexInput four = two.clone(); // clone of clone
slicer.close();
try {
one.readInt();
fail("Must throw AlreadyClosedException");
} catch (AlreadyClosedException ignore) {
// pass
}
try {
two.readInt();
fail("Must throw AlreadyClosedException");
} catch (AlreadyClosedException ignore) {
// pass
}
try {
three.readInt();
fail("Must throw AlreadyClosedException");
} catch (AlreadyClosedException ignore) {
// pass
}
try {
four.readInt();
fail("Must throw AlreadyClosedException");
} catch (AlreadyClosedException ignore) {
// pass
}
one.close();
two.close();
three.close();
four.close();
// test double-close of slicer:
slicer.close();
mmapDir.close();
}