public void TestLUCENENET521() { var newDirectoryInfo = CreateTempDir("LUCENENET521"); using (var zipFileStream = this.GetType().GetTypeInfo().Assembly.FindAndGetManifestResourceStream(this.GetType(), "LUCENENET521.zip")) { TestUtil.Unzip(zipFileStream, newDirectoryInfo); } var newDirectory = new MMapDirectory(newDirectoryInfo); var conf = new Index.IndexWriterConfig(LuceneVersion.LUCENE_30, new Analysis.Standard.StandardAnalyzer(LuceneVersion.LUCENE_30)); var indexWriter = new Index.IndexWriter(newDirectory, conf); indexWriter.Dispose(); var sharedReader = Index.IndexReader.Open(newDirectory /*, true*/); const int times = 10; const int concurrentTaskCount = 10; var task = new System.Threading.Tasks.Task[concurrentTaskCount]; for (int i = 0; i < concurrentTaskCount; i++) { task[i] = new System.Threading.Tasks.Task(() => Search(sharedReader, times)); task[i].Start(); } System.Threading.Tasks.Task.WaitAll(task); return; }
public virtual void TestMmapIndex() { // sometimes the directory is not cleaned by rmDir, because on Windows it // may take some time until the files are finally dereferenced. So clean the // directory up front, or otherwise new IndexWriter will fail. DirectoryInfo dirPath = CreateTempDir("testLuceneMmap"); RmDir(dirPath); MMapDirectory dir = new MMapDirectory(dirPath, null); // plan to add a set of useful stopwords, consider changing some of the // interior filters. MockAnalyzer analyzer = new MockAnalyzer(Random()); // TODO: something about lock timeouts and leftover locks. IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE)); writer.Commit(); IndexReader reader = DirectoryReader.Open(dir); IndexSearcher searcher = NewSearcher(reader); int num = AtLeast(1000); for (int dx = 0; dx < num; dx++) { string f = RandomField(); Document doc = new Document(); doc.Add(NewTextField("data", f, Field.Store.YES)); writer.AddDocument(doc); } reader.Dispose(); writer.Dispose(); RmDir(dirPath); }
public virtual void TestMmapIndex() { Assert.Ignore("Need to port tests, but we don't really support MMapDirectories anyway"); FSDirectory storeDirectory; storeDirectory = new MMapDirectory(new System.IO.DirectoryInfo(storePathname), null); // plan to add a set of useful stopwords, consider changing some of the // interior filters. StandardAnalyzer analyzer = new StandardAnalyzer(Util.Version.LUCENE_CURRENT, Support.Compatibility.SetFactory.CreateHashSet<string>()); // TODO: something about lock timeouts and leftover locks. IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED); IndexSearcher searcher = new IndexSearcher(storeDirectory, true); for (int dx = 0; dx < 1000; dx++) { System.String f = RandomField(); Document doc = new Document(); doc.Add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED)); writer.AddDocument(doc); } searcher.Close(); writer.Close(); RmDir(new System.IO.FileInfo(storePathname)); }
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(); }
internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc) : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, outerInstance.UseUnmap) { this.outerInstance = outerInstance; this.useUnmapHack = outerInstance.UseUnmap; this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length)); }
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 TestMmapIndex() { Assert.Ignore("Need to port tests, but we don't really support MMapDirectories anyway"); FSDirectory storeDirectory; storeDirectory = new MMapDirectory(new System.IO.DirectoryInfo(storePathname), null); // plan to add a set of useful stopwords, consider changing some of the // interior filters. StandardAnalyzer analyzer = new StandardAnalyzer(Util.Version.LUCENE_CURRENT, Support.Compatibility.SetFactory.CreateHashSet <string>()); // TODO: something about lock timeouts and leftover locks. IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED, null); IndexSearcher searcher = new IndexSearcher(storeDirectory, true, null); for (int dx = 0; dx < 1000; dx++) { System.String f = RandomField(); Document doc = new Document(); doc.Add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED)); writer.AddDocument(doc, null); } searcher.Close(); writer.Close(); RmDir(new System.IO.FileInfo(storePathname)); }
public virtual void TestMmapIndex() { // sometimes the directory is not cleaned by rmDir, because on Windows it // may take some time until the files are finally dereferenced. So clean the // directory up front, or otherwise new IndexWriter will fail. DirectoryInfo dirPath = CreateTempDir("testLuceneMmap"); RmDir(dirPath); MMapDirectory dir = new MMapDirectory(dirPath, null); // plan to add a set of useful stopwords, consider changing some of the // interior filters. MockAnalyzer analyzer = new MockAnalyzer(Random()); // TODO: something about lock timeouts and leftover locks. IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE)); writer.Commit(); IndexReader reader = DirectoryReader.Open(dir); IndexSearcher searcher = NewSearcher(reader); int num = AtLeast(1000); for (int dx = 0; dx < num; dx++) { string f = RandomField(); Document doc = new Document(); doc.Add(NewTextField("data", f, Field.Store.YES)); writer.AddDocument(doc); } reader.Dispose(); writer.Dispose(); RmDir(dirPath); }
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(); } }
internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc) : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, true) { this.outerInstance = outerInstance; this.fc = fc ?? throw new ArgumentNullException("fc"); this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length)); }
public virtual void TestMmapIndex() { FSDirectory storeDirectory; storeDirectory = new MMapDirectory(new System.IO.FileInfo(storePathname), null); // plan to add a set of useful stopwords, consider changing some of the // interior filters. StandardAnalyzer analyzer = new StandardAnalyzer(new System.Collections.Hashtable()); // TODO: something about lock timeouts and leftover locks. IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED); IndexSearcher searcher = new IndexSearcher(storePathname); for (int dx = 0; dx < 1000; dx++) { System.String f = RandomField(); Document doc = new Document(); doc.Add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED)); writer.AddDocument(doc); } searcher.Close(); writer.Close(); RmDir(new System.IO.FileInfo(storePathname)); }
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(); }
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(); }
internal MMapIndexInput(MMapDirectory enclosingInstance, System.IO.FileStream raf) { byte[] data = new byte[raf.Length]; raf.Read(data, 0, (int)raf.Length); InitBlock(enclosingInstance); this.length = raf.Length; this.buffer = new System.IO.MemoryStream(data); }
internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc) : base(resourceDescription, null, fc.Length, outerInstance.ChunkSizePower, outerInstance.UseUnmap) { this.outerInstance = outerInstance; this.UseUnmapHack = outerInstance.UseUnmap; this.Buffers = outerInstance.Map(this, fc, 0, fc.Length); //Called here to let buffers get set up base.Seek(0L); }
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 void TestDisposeIndexInput() { string name = "foobar"; var dir = CreateTempDir("testDisposeIndexInput"); string fileName = Path.Combine(dir.FullName, name); // Create a zero byte file, and close it immediately File.WriteAllText(fileName, string.Empty, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) /* No BOM */); MMapDirectory mmapDir = new MMapDirectory(dir); using (var indexInput = mmapDir.OpenInput(name, NewIOContext(Random()))) { } // Dispose // Now it should be possible to delete the file. This is the condition we are testing for. File.Delete(fileName); }
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); }
private void AssertChunking(Random random, int chunkSize) { DirectoryInfo path = CreateTempDir("mmap" + chunkSize); MMapDirectory mmapDir = new MMapDirectory(path, null, chunkSize); // LUCENENET specific - unmap hack not needed //// we will map a lot, try to turn on the unmap hack //if (MMapDirectory.UNMAP_SUPPORTED) //{ // mmapDir.UseUnmap = true; //} MockDirectoryWrapper dir = new MockDirectoryWrapper(random, mmapDir); RandomIndexWriter writer = new RandomIndexWriter(random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(NewLogMergePolicy())); Document doc = new Document(); Field docid = NewStringField("docid", "0", Field.Store.YES); Field junk = NewStringField("junk", "", Field.Store.YES); doc.Add(docid); doc.Add(junk); int numDocs = 100; for (int i = 0; i < numDocs; i++) { docid.SetStringValue("" + i); junk.SetStringValue(TestUtil.RandomUnicodeString(random)); writer.AddDocument(doc); } IndexReader reader = writer.Reader; writer.Dispose(); int numAsserts = AtLeast(100); for (int i = 0; i < numAsserts; i++) { int docID = random.Next(numDocs); Assert.AreEqual("" + docID, reader.Document(docID).Get("docid")); } reader.Dispose(); dir.Dispose(); }
public MultiMMapIndexInput(MMapDirectory enclosingInstance, System.IO.FileStream raf, int maxBufSize) { InitBlock(enclosingInstance); this.length = raf.Length; this.maxBufSize = maxBufSize; if (maxBufSize <= 0) { throw new System.ArgumentException("Non positive maxBufSize: " + maxBufSize); } if ((length / maxBufSize) > int.MaxValue) { throw new System.ArgumentException("RandomAccessFile too big for maximum buffer size: " + raf.ToString()); } int nrBuffers = (int)(length / maxBufSize); if (((long)nrBuffers * maxBufSize) < length) { nrBuffers++; } this.buffers = new System.IO.MemoryStream[nrBuffers]; this.bufSizes = new int[nrBuffers]; long bufferStart = 0; System.IO.FileStream rafc = raf; for (int bufNr = 0; bufNr < nrBuffers; bufNr++) { byte[] data = new byte[rafc.Length]; raf.Read(data, 0, (int)rafc.Length); int bufSize = (length > (bufferStart + maxBufSize))?maxBufSize:(int)(length - bufferStart); this.buffers[bufNr] = new System.IO.MemoryStream(data); this.bufSizes[bufNr] = bufSize; bufferStart += bufSize; } Seek(0L); }
public virtual void TestMmapIndex() { FSDirectory storeDirectory; storeDirectory = new MMapDirectory(new System.IO.FileInfo(storePathname), null); // plan to add a set of useful stopwords, consider changing some of the // interior filters. StandardAnalyzer analyzer = new StandardAnalyzer(new System.Collections.Hashtable()); // TODO: something about lock timeouts and leftover locks. IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED); IndexSearcher searcher = new IndexSearcher(storePathname); for (int dx = 0; dx < 1000; dx++) { System.String f = RandomField(); Document doc = new Document(); doc.Add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED)); writer.AddDocument(doc); } searcher.Close(); writer.Close(); RmDir(new System.IO.FileInfo(storePathname)); }
public IndexInputSlicerAnonymousClass(MMapDirectory outerInstance, MMapIndexInput full) { this.outerInstance = outerInstance; this.full = full; }
public IndexInputSlicerAnonymousInnerClassHelper(MMapDirectory outerInstance, MMapIndexInput full) : base(outerInstance) { this.outerInstance = outerInstance; this.full = full; }
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(); } }
private void InitBlock(byte[] buffer, MMapDirectory enclosingInstance) { this.buffer = buffer; this.enclosingInstance = enclosingInstance; }
public MultiMMapIndexInput(MMapDirectory enclosingInstance, System.IO.FileStream raf, int maxBufSize) { InitBlock(enclosingInstance); this.length = raf.Length; this.maxBufSize = maxBufSize; if (maxBufSize <= 0) throw new System.ArgumentException("Non positive maxBufSize: " + maxBufSize); if ((length / maxBufSize) > System.Int32.MaxValue) { throw new System.ArgumentException("RandomAccessFile too big for maximum buffer size: " + raf.ToString()); } int nrBuffers = (int) (length / maxBufSize); if (((long) nrBuffers * maxBufSize) < length) nrBuffers++; this.buffers = new System.IO.MemoryStream[nrBuffers]; this.bufSizes = new int[nrBuffers]; long bufferStart = 0; System.IO.FileStream rafc = raf; for (int bufNr = 0; bufNr < nrBuffers; bufNr++) { byte[] data = new byte[rafc.Length]; raf.Read(data, 0, (int) rafc.Length); int bufSize = (length > (bufferStart + maxBufSize))?maxBufSize:(int) (length - bufferStart); this.buffers[bufNr] = new System.IO.MemoryStream(data); this.bufSizes[bufNr] = bufSize; bufferStart += bufSize; } Seek(0L); }
internal MMapIndexInput(MMapDirectory enclosingInstance, System.IO.FileStream raf) { byte[] data = new byte[raf.Length]; raf.Read(data, 0, (int) raf.Length); InitBlock(enclosingInstance); this.length = raf.Length; this.buffer = new System.IO.MemoryStream(data); }
public IndexInputSlicerAnonymousInnerClassHelper(MMapDirectory outerInstance, MMapIndexInput full) : base(outerInstance) { this.OuterInstance = outerInstance; this.Full = full; }
public AnonymousClassPrivilegedExceptionAction(byte[] buffer, MMapDirectory enclosingInstance) { InitBlock(buffer, enclosingInstance); }
private void InitBlock(MMapDirectory enclosingInstance) { this.enclosingInstance = enclosingInstance; }
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(); } }
public virtual void TestDirectInstantiation() { System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(AppSettings.Get("tempDir", System.IO.Path.GetTempPath())); int sz = 2; Directory[] dirs = new Directory[sz]; dirs[0] = new SimpleFSDirectory(path, null); // dirs[1] = new NIOFSDirectory(path, null); System.Console.WriteLine("Skipping NIOFSDirectory() test under Lucene.Net"); dirs[1] = new MMapDirectory(path, null); for (int i = 0; i < sz; i++) { Directory dir = dirs[i]; dir.EnsureOpen(); System.String fname = "foo." + i; System.String lockname = "foo" + i + ".lck"; IndexOutput out_Renamed = dir.CreateOutput(fname, null); out_Renamed.WriteByte((byte)i); out_Renamed.Close(); for (int j = 0; j < sz; j++) { Directory d2 = dirs[j]; d2.EnsureOpen(); Assert.IsTrue(d2.FileExists(fname, null)); Assert.AreEqual(1, d2.FileLength(fname, null)); // don't test read on MMapDirectory, since it can't really be // closed and will cause a failure to delete the file. if (d2 is MMapDirectory) { continue; } IndexInput input = d2.OpenInput(fname, null); Assert.AreEqual((byte)i, input.ReadByte(null)); input.Close(); } // delete with a different dir dirs[(i + 1) % sz].DeleteFile(fname, null); for (int j = 0; j < sz; j++) { Directory d2 = dirs[j]; Assert.IsFalse(d2.FileExists(fname, null)); } Lock lock_Renamed = dir.MakeLock(lockname); Assert.IsTrue(lock_Renamed.Obtain()); for (int j = 0; j < sz; j++) { Directory d2 = dirs[j]; Lock lock2 = d2.MakeLock(lockname); try { Assert.IsFalse(lock2.Obtain(1)); } catch (LockObtainFailedException) { // OK } } lock_Renamed.Release(); // now lock with different dir lock_Renamed = dirs[(i + 1) % sz].MakeLock(lockname); Assert.IsTrue(lock_Renamed.Obtain()); lock_Renamed.Release(); } for (int i = 0; i < sz; i++) { Directory dir = dirs[i]; dir.EnsureOpen(); dir.Close(); Assert.IsFalse(dir.isOpen_ForNUnit); } }
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(); } }
internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc) : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, true) { this.fc = fc ?? throw new ArgumentNullException(nameof(fc)); // LUCENENET specific - changed from IllegalArgumentException to ArgumentNullException (.NET convention) this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length)); }
public virtual void TestDirectInstantiation() { System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(AppSettings.Get("tempDir", System.IO.Path.GetTempPath())); int sz = 2; Directory[] dirs = new Directory[sz]; dirs[0] = new SimpleFSDirectory(path, null); // dirs[1] = new NIOFSDirectory(path, null); System.Console.WriteLine("Skipping NIOFSDirectory() test under Lucene.Net"); dirs[1] = new MMapDirectory(path, null); for (int i = 0; i < sz; i++) { Directory dir = dirs[i]; dir.EnsureOpen(); System.String fname = "foo." + i; System.String lockname = "foo" + i + ".lck"; IndexOutput out_Renamed = dir.CreateOutput(fname); out_Renamed.WriteByte((byte) i); out_Renamed.Close(); for (int j = 0; j < sz; j++) { Directory d2 = dirs[j]; d2.EnsureOpen(); Assert.IsTrue(d2.FileExists(fname)); Assert.AreEqual(1, d2.FileLength(fname)); // don't test read on MMapDirectory, since it can't really be // closed and will cause a failure to delete the file. if (d2 is MMapDirectory) continue; IndexInput input = d2.OpenInput(fname); Assert.AreEqual((byte) i, input.ReadByte()); input.Close(); } // delete with a different dir dirs[(i + 1) % sz].DeleteFile(fname); for (int j = 0; j < sz; j++) { Directory d2 = dirs[j]; Assert.IsFalse(d2.FileExists(fname)); } Lock lock_Renamed = dir.MakeLock(lockname); Assert.IsTrue(lock_Renamed.Obtain()); for (int j = 0; j < sz; j++) { Directory d2 = dirs[j]; Lock lock2 = d2.MakeLock(lockname); try { Assert.IsFalse(lock2.Obtain(1)); } catch (LockObtainFailedException) { // OK } } lock_Renamed.Release(); // now lock with different dir lock_Renamed = dirs[(i + 1) % sz].MakeLock(lockname); Assert.IsTrue(lock_Renamed.Obtain()); lock_Renamed.Release(); } for (int i = 0; i < sz; i++) { Directory dir = dirs[i]; dir.EnsureOpen(); dir.Close(); Assert.IsFalse(dir.isOpen_ForNUnit); } }
private void InitBlock(byte[] buffer, MMapDirectory enclosingInstance) { this.buffer = buffer; this.enclosingInstance = enclosingInstance; }
internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc) : base(resourceDescription, null, fc.Length, outerInstance.ChunkSizePower, outerInstance.UseUnmap) { this.outerInstance = outerInstance; this.UseUnmapHack = outerInstance.UseUnmap; this.Buffers = outerInstance.Map(this, fc, 0, fc.Length); //Called here to let buffers get set up base.Seek(0L); }
public IndexInputSlicerAnonymousInnerClassHelper(MMapDirectory outerInstance, Lucene.Net.Store.MMapDirectory.MMapIndexInput full) : base(outerInstance) { this.OuterInstance = outerInstance; this.Full = full; }
private void InitBlock(MMapDirectory enclosingInstance) { this.enclosingInstance = enclosingInstance; }
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 AnonymousClassPrivilegedExceptionAction(byte[] buffer, MMapDirectory enclosingInstance) { InitBlock(buffer, enclosingInstance); }
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(); }
private void AssertChunking(Random random, int chunkSize) { DirectoryInfo path = CreateTempDir("mmap" + chunkSize); MMapDirectory mmapDir = new MMapDirectory(path, null, chunkSize); // we will map a lot, try to turn on the unmap hack if (MMapDirectory.UNMAP_SUPPORTED) { mmapDir.UseUnmap = true; } MockDirectoryWrapper dir = new MockDirectoryWrapper(random, mmapDir); RandomIndexWriter writer = new RandomIndexWriter(random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(NewLogMergePolicy())); Document doc = new Document(); Field docid = NewStringField("docid", "0", Field.Store.YES); Field junk = NewStringField("junk", "", Field.Store.YES); doc.Add(docid); doc.Add(junk); int numDocs = 100; for (int i = 0; i < numDocs; i++) { docid.StringValue = "" + i; junk.StringValue = TestUtil.RandomUnicodeString(random); writer.AddDocument(doc); } IndexReader reader = writer.Reader; writer.Dispose(); int numAsserts = AtLeast(100); for (int i = 0; i < numAsserts; i++) { int docID = random.Next(numDocs); Assert.AreEqual("" + docID, reader.Document(docID).Get("docid")); } reader.Dispose(); dir.Dispose(); }