CreateSlicer() public method

public CreateSlicer ( string name, IOContext context ) : IndexInputSlicer
name string
context IOContext
return IndexInputSlicer
Ejemplo n.º 1
0
 public virtual void TestSeekSliceEnd()
 {
     for (int i = 0; i < 17; i++)
     {
         MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSeekSliceEnd"), null, 1 << i);
         IndexOutput   io      = mmapDir.CreateOutput("bytes", NewIOContext(Random));
         var           bytes   = new byte[1 << i];
         Random.NextBytes(bytes);
         io.WriteBytes(bytes, bytes.Length);
         io.Dispose();
         IndexInputSlicer slicer = mmapDir.CreateSlicer("bytes", NewIOContext(Random));
         IndexInput       ii     = slicer.OpenSlice("full slice", 0, bytes.Length);
         var actual = new byte[1 << i];
         ii.ReadBytes(actual, 0, actual.Length);
         Assert.AreEqual(new BytesRef(bytes), new BytesRef(actual));
         ii.Seek(1 << i);
         ii.Dispose();
         slicer.Dispose();
         mmapDir.Dispose();
     }
 }
Ejemplo n.º 2
0
        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");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            try
            {
                two.ReadInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            try
            {
                three.ReadInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            try
            {
                four.ReadInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            one.Dispose();
            two.Dispose();
            three.Dispose();
            four.Dispose();
            // test double-close of slicer:
            slicer.Dispose();
            mmapDir.Dispose();
        }
Ejemplo n.º 3
0
 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();
     }
 }
Ejemplo n.º 4
0
 public virtual void TestSeekSliceZero()
 {
     for (int i = 0; i < 31; i++)
     {
         MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSeekSliceZero"), null, 1 << i);
         IndexOutput io = mmapDir.CreateOutput("zeroBytes", NewIOContext(Random()));
         io.Dispose();
         IndexInputSlicer slicer = mmapDir.CreateSlicer("zeroBytes", NewIOContext(Random()));
         IndexInput ii = slicer.OpenSlice("zero-length slice", 0, 0);
         ii.Seek(0L);
         ii.Dispose();
         slicer.Dispose();
         mmapDir.Dispose();
     }
 }
Ejemplo n.º 5
0
 public virtual void TestSeekSliceEnd()
 {
     for (int i = 0; i < 17; i++)
     {
         MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSeekSliceEnd"), null, 1 << i);
         IndexOutput io = mmapDir.CreateOutput("bytes", NewIOContext(Random()));
         var bytes = new byte[1 << i];
         Random().NextBytes(bytes);
         io.WriteBytes(bytes, bytes.Length);
         io.Dispose();
         IndexInputSlicer slicer = mmapDir.CreateSlicer("bytes", NewIOContext(Random()));
         IndexInput ii = slicer.OpenSlice("full slice", 0, bytes.Length);
         var actual = new byte[1 << i];
         ii.ReadBytes(actual, 0, actual.Length);
         Assert.AreEqual(new BytesRef(bytes), new BytesRef(actual));
         ii.Seek(1 << i);
         ii.Dispose();
         slicer.Dispose();
         mmapDir.Dispose();
     }
 }
Ejemplo n.º 6
0
 public virtual void TestCloneSliceSafety()
 {
     MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneSliceSafety"));
     IndexOutput io = mmapDir.CreateOutput("bytes", NewIOContext(Random()));
     io.WriteInt(1);
     io.WriteInt(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.ReadInt();
         Assert.Fail("Must throw AlreadyClosedException");
     }
     catch (AlreadyClosedException ignore)
     {
         // pass
     }
     try
     {
         two.ReadInt();
         Assert.Fail("Must throw AlreadyClosedException");
     }
     catch (AlreadyClosedException ignore)
     {
         // pass
     }
     try
     {
         three.ReadInt();
         Assert.Fail("Must throw AlreadyClosedException");
     }
     catch (AlreadyClosedException ignore)
     {
         // pass
     }
     try
     {
         four.ReadInt();
         Assert.Fail("Must throw AlreadyClosedException");
     }
     catch (AlreadyClosedException ignore)
     {
         // pass
     }
     one.Dispose();
     two.Dispose();
     three.Dispose();
     four.Dispose();
     // test double-close of slicer:
     slicer.Dispose();
     mmapDir.Dispose();
 }
Ejemplo n.º 7
0
 public virtual void TestCloneSliceClose()
 {
     MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneSliceClose"));
     IndexOutput io = mmapDir.CreateOutput("bytes", NewIOContext(Random()));
     io.WriteInt(1);
     io.WriteInt(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.ReadInt();
         Assert.Fail("Must throw AlreadyClosedException");
     }
     catch (AlreadyClosedException ignore)
     {
         // pass
     }
     Assert.AreEqual(2, two.ReadInt());
     // reopen a new slice "one":
     one = slicer.OpenSlice("first int", 0, 4);
     Assert.AreEqual(1, one.ReadInt());
     one.Dispose();
     two.Dispose();
     slicer.Dispose();
     mmapDir.Dispose();
 }