public virtual void TestExceptionDuringSync() { MockRAMDirectory dir = new MockRAMDirectory(); FailOnlyInSync failure = new FailOnlyInSync(); dir.FailOn(failure); IndexWriter writer = new IndexWriter(dir, true, new WhitespaceAnalyzer()); failure.SetDoFail(); ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler(); // We expect sync exceptions in the merge threads cms.SetSuppressExceptions(); writer.SetMergeScheduler(cms); writer.SetMaxBufferedDocs(2); writer.SetMergeFactor(5); for (int i = 0; i < 23; i++) AddDoc(writer); cms.Sync(); Assert.IsTrue(failure.didFail); failure.ClearDoFail(); writer.Close(); IndexReader reader = IndexReader.Open(dir); Assert.AreEqual(23, reader.NumDocs()); reader.Close(); dir.Close(); }
public virtual void TestImmediateDiskFullWithThreads() { int NUM_THREADS = 3; for (int iter = 0; iter < 10; iter++) { MockRAMDirectory dir = new MockRAMDirectory(); IndexWriter writer = new IndexWriter(dir, true, new WhitespaceAnalyzer()); ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler(); // We expect disk full exceptions in the merge threads cms.SetSuppressExceptions(); writer.SetMergeScheduler(cms); writer.SetMaxBufferedDocs(2); writer.SetMergeFactor(4); dir.SetMaxSizeInBytes(4 * 1024 + 20 * iter); IndexerThread[] threads = new IndexerThread[NUM_THREADS]; for (int i = 0; i < NUM_THREADS; i++) threads[i] = new IndexerThread(this, writer, true); for (int i = 0; i < NUM_THREADS; i++) threads[i].Start(); for (int i = 0; i < NUM_THREADS; i++) { // Without fix for LUCENE-1130: one of the // threads will hang threads[i].Join(); Assert.IsTrue(threads[i].error == null, "hit unexpected Throwable"); } try { writer.Close(false); } catch (System.IO.IOException ioe) { } dir.Close(); } }
// Runs test, with multiple threads, using the specific // failure to trigger an IOException public virtual void _testMultipleThreadsFailure(MockRAMDirectory.Failure failure) { int NUM_THREADS = 3; for (int iter = 0; iter < 5; iter++) { MockRAMDirectory dir = new MockRAMDirectory(); IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler(); // We expect disk full exceptions in the merge threads cms.SetSuppressExceptions(); writer.SetMergeScheduler(cms); writer.SetMaxBufferedDocs(2); writer.SetMergeFactor(4); IndexerThread[] threads = new IndexerThread[NUM_THREADS]; for (int i = 0; i < NUM_THREADS; i++) threads[i] = new IndexerThread(this, writer, true); for (int i = 0; i < NUM_THREADS; i++) threads[i].Start(); System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 10)); dir.FailOn(failure); failure.SetDoFail(); for (int i = 0; i < NUM_THREADS; i++) { threads[i].Join(); Assert.IsTrue(threads[i].error == null, "hit unexpected Throwable"); } bool success = false; try { writer.Close(false); success = true; } catch (System.IO.IOException ioe) { failure.ClearDoFail(); writer.Close(false); } if (success) { IndexReader reader = IndexReader.Open(dir); for (int j = 0; j < reader.MaxDoc(); j++) { if (!reader.IsDeleted(j)) { reader.Document(j); reader.GetTermFreqVectors(j); } } reader.Close(); } dir.Close(); } }
public virtual void TestCloseWithThreads() { int NUM_THREADS = 3; for (int iter = 0; iter < 20; iter++) { MockRAMDirectory dir = new MockRAMDirectory(); IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler(); // We expect AlreadyClosedException cms.SetSuppressExceptions(); writer.SetMergeScheduler(cms); writer.SetMaxBufferedDocs(10); writer.SetMergeFactor(4); IndexerThread[] threads = new IndexerThread[NUM_THREADS]; for (int i = 0; i < NUM_THREADS; i++) threads[i] = new IndexerThread(this, writer, false); for (int i = 0; i < NUM_THREADS; i++) threads[i].Start(); bool done = false; while (!done) { System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 100)); for (int i = 0; i < NUM_THREADS; i++) // only stop when at least one thread has added a doc if (threads[i].addCount > 0) { done = true; break; } } writer.Close(false); // Make sure threads that are adding docs are not hung: for (int i = 0; i < NUM_THREADS; i++) { // Without fix for LUCENE-1130: one of the // threads will hang threads[i].Join(); if (threads[i].IsAlive) Assert.Fail("thread seems to be hung"); } // Quick test to make sure index is not corrupt: IndexReader reader = IndexReader.Open(dir); TermDocs tdocs = reader.TermDocs(new Term("field", "aaa")); int count = 0; while (tdocs.Next()) { count++; } Assert.IsTrue(count > 0); reader.Close(); dir.Close(); } }