public virtual void TestSlicedSeeking()
{
for (int i = 0; i < 10; i++)
{
MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSlicedSeeking"), null, 1 << i);
IndexOutput io = mmapDir.CreateOutput("bytes", NewIOContext(Random()));
var bytes = new byte[1 << (i + 1)]; // make sure we switch buffers
Random().NextBytes(bytes);
io.WriteBytes(bytes, bytes.Length);
io.Dispose();
IndexInput ii = mmapDir.OpenInput("bytes", NewIOContext(Random()));
var actual = new byte[1 << (i + 1)]; // first read all bytes
ii.ReadBytes(actual, 0, actual.Length);
ii.Dispose();
Assert.AreEqual(new BytesRef(bytes), new BytesRef(actual));
IndexInputSlicer slicer = mmapDir.CreateSlicer("bytes", NewIOContext(Random()));
for (int sliceStart = 0; sliceStart < bytes.Length; sliceStart++)
{
for (int sliceLength = 0; sliceLength < bytes.Length - sliceStart; sliceLength++)
{
var slice = new byte[sliceLength];
IndexInput input = slicer.OpenSlice("bytesSlice", sliceStart, slice.Length);
input.ReadBytes(slice, 0, slice.Length);
input.Dispose();
Assert.AreEqual(new BytesRef(bytes, sliceStart, sliceLength), new BytesRef(slice));
}
}
slicer.Dispose();
mmapDir.Dispose();
}
}