Exemplo n.º 1
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();
     }
 }
Exemplo n.º 2
0
        public virtual void TestCloneClose()
        {
            MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneClose"));
            IndexOutput   io      = mmapDir.CreateOutput("bytes", NewIOContext(Random()));

            io.WriteVInt32(5);
            io.Dispose();
            IndexInput one   = mmapDir.OpenInput("bytes", IOContext.DEFAULT);
            IndexInput two   = (IndexInput)one.Clone();
            IndexInput three = (IndexInput)two.Clone(); // clone of clone

            two.Dispose();
            Assert.AreEqual(5, one.ReadVInt32());
            try
            {
                two.ReadVInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            Assert.AreEqual(5, three.ReadVInt32());
            one.Dispose();
            three.Dispose();
            mmapDir.Dispose();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
 public virtual void TestCloneClose()
 {
     MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneClose"));
     IndexOutput io = mmapDir.CreateOutput("bytes", NewIOContext(Random()));
     io.WriteVInt(5);
     io.Dispose();
     IndexInput one = mmapDir.OpenInput("bytes", IOContext.DEFAULT);
     IndexInput two = (IndexInput)one.Clone();
     IndexInput three = (IndexInput)two.Clone(); // clone of clone
     two.Dispose();
     Assert.AreEqual(5, one.ReadVInt());
     try
     {
         two.ReadVInt();
         Assert.Fail("Must throw AlreadyClosedException");
     }
     catch (AlreadyClosedException ignore)
     {
         // pass
     }
     Assert.AreEqual(5, three.ReadVInt());
     one.Dispose();
     three.Dispose();
     mmapDir.Dispose();
 }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
 public virtual void TestSeekZero()
 {
     for (int i = 0; i < 31; i++)
     {
         MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSeekZero"), null, 1 << i);
         IndexOutput   io      = mmapDir.CreateOutput("zeroBytes", NewIOContext(Random()));
         io.Dispose();
         IndexInput ii = mmapDir.OpenInput("zeroBytes", NewIOContext(Random()));
         ii.Seek(0L);
         ii.Dispose();
         mmapDir.Dispose();
     }
 }
Exemplo n.º 7
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();
     }
 }
Exemplo n.º 8
0
        public virtual void TestCloneSafety()
        {
            MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneSafety"));
            IndexOutput   io      = mmapDir.CreateOutput("bytes", NewIOContext(Random()));

            io.WriteVInt(5);
            io.Dispose();
            IndexInput one   = mmapDir.OpenInput("bytes", IOContext.DEFAULT);
            IndexInput two   = (IndexInput)one.Clone();
            IndexInput three = (IndexInput)two.Clone(); // clone of clone

            one.Dispose();
            try
            {
                one.ReadVInt();
                Assert.Fail("Must throw AlreadyClosedException");
            }
            catch (AlreadyClosedException ignore)
            {
                // pass
            }
            try
            {
                two.ReadVInt();
                Assert.Fail("Must throw AlreadyClosedException");
            }
            catch (AlreadyClosedException ignore)
            {
                // pass
            }
            try
            {
                three.ReadVInt();
                Assert.Fail("Must throw AlreadyClosedException");
            }
            catch (AlreadyClosedException ignore)
            {
                // pass
            }
            two.Dispose();
            three.Dispose();
            // test double close of master:
            one.Dispose();
            mmapDir.Dispose();
        }
Exemplo n.º 9
0
 public virtual void TestSeekEnd()
 {
     for (int i = 0; i < 17; i++)
     {
         MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSeekEnd"), 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();
         IndexInput ii     = mmapDir.OpenInput("bytes", NewIOContext(Random()));
         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();
         mmapDir.Dispose();
     }
 }
Exemplo n.º 10
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();
     }
 }
Exemplo n.º 11
0
 public virtual void TestSeekZero()
 {
     for (int i = 0; i < 31; i++)
     {
         MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSeekZero"), null, 1 << i);
         IndexOutput io = mmapDir.CreateOutput("zeroBytes", NewIOContext(Random()));
         io.Dispose();
         IndexInput ii = mmapDir.OpenInput("zeroBytes", NewIOContext(Random()));
         ii.Seek(0L);
         ii.Dispose();
         mmapDir.Dispose();
     }
 }
Exemplo n.º 12
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();
     }
 }
Exemplo n.º 13
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();
 }
Exemplo n.º 14
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();
 }