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 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(); } }
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(); }
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(); }
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(); } }
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(); } }
public override void Index <T>() { FSDirectory entityDirectory = null; IndexWriter writer = null; var entityType = typeof(T); var indexDirectory = new DirectoryInfo(this.IndexDirectory); if (indexDirectory.Exists) { indexDirectory.Delete(true); } try { entityDirectory = new Lucene.Net.Store.MMapDirectory(new DirectoryInfo(Path.Combine(indexDirectory.FullName, entityType.Name))); writer = new IndexWriter(entityDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); } finally { if (entityDirectory != null) { entityDirectory.Dispose(); } if (writer != null) { writer.Dispose(); } } var localContext = (IDataContext <ISession>) this.DataContext; var fullTextSession = NHibernate.Search.Search.CreateFullTextSession(localContext.Session); foreach (var instance in localContext.Session.CreateCriteria <T>().List <T>()) { fullTextSession.Index(instance); } var sessionImplementation = localContext.Session.GetSessionImplementation(); sessionImplementation.Listeners.PostDeleteEventListeners = new IPostDeleteEventListener[] { new FullTextIndexEventListener() }; sessionImplementation.Listeners.PostInsertEventListeners = new IPostInsertEventListener[] { new FullTextIndexEventListener() }; sessionImplementation.Listeners.PostUpdateEventListeners = new IPostUpdateEventListener[] { new FullTextIndexEventListener() }; }
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(); }
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(); } }
public virtual void TestDefaultFSLockFactoryPrefix() { // Make sure we get null prefix, which wont happen if setLockFactory is ever called. DirectoryInfo dirName = CreateTempDir("TestLockFactory.10"); Directory dir = new SimpleFSDirectory(dirName); Assert.IsNull(dir.LockFactory.LockPrefix, "Default lock prefix should be null"); dir.Dispose(); dir = new MMapDirectory(dirName); Assert.IsNull(dir.LockFactory.LockPrefix, "Default lock prefix should be null"); dir.Dispose(); dir = new NIOFSDirectory(dirName); Assert.IsNull(dir.LockFactory.LockPrefix, "Default lock prefix should be null"); dir.Dispose(); System.IO.Directory.Delete(dirName.FullName, true); }
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(); }
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(); } }