public virtual void TestMaybeRefreshBlockingLock() { // make sure that maybeRefreshBlocking releases the lock, otherwise other // threads cannot obtain it. Directory dir = NewDirectory(); RandomIndexWriter w = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, dir); w.Dispose(); SearcherManager sm = new SearcherManager(dir, null); ThreadJob t = new ThreadAnonymousClass2(this, sm); t.Start(); t.Join(); // if maybeRefreshBlocking didn't release the lock, this will fail. assertTrue("failde to obtain the refreshLock!", sm.MaybeRefresh()); sm.Dispose(); dir.Dispose(); }
public virtual void TestUncaughtException() { ThreadJob t = new ThreadAnonymousClass2(this); t.Start(); t.Join(); }
public virtual void TestThreadStarvationNoDeleteNRTReader() { IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)); conf.SetMergePolicy(Random.NextBoolean() ? NoMergePolicy.COMPOUND_FILES : NoMergePolicy.NO_COMPOUND_FILES); Directory d = NewDirectory(); CountdownEvent latch = new CountdownEvent(1); CountdownEvent signal = new CountdownEvent(1); LatchedIndexWriter _writer = new LatchedIndexWriter(d, conf, latch, signal); TrackingIndexWriter writer = new TrackingIndexWriter(_writer); SearcherManager manager = new SearcherManager(_writer, false, null); Document doc = new Document(); doc.Add(NewTextField("test", "test", Field.Store.YES)); writer.AddDocument(doc); manager.MaybeRefresh(); var t = new ThreadAnonymousClass(this, latch, signal, writer, manager); t.Start(); _writer.waitAfterUpdate = true; // wait in addDocument to let some reopens go through long lastGen = writer.UpdateDocument(new Term("foo", "bar"), doc); // once this returns the doc is already reflected in the last reopen assertFalse(manager.IsSearcherCurrent()); // false since there is a delete in the queue IndexSearcher searcher = manager.Acquire(); try { assertEquals(2, searcher.IndexReader.NumDocs); } finally { manager.Release(searcher); } ControlledRealTimeReopenThread <IndexSearcher> thread = new ControlledRealTimeReopenThread <IndexSearcher>(writer, manager, 0.01, 0.01); thread.Start(); // start reopening if (Verbose) { Console.WriteLine("waiting now for generation " + lastGen); } AtomicBoolean finished = new AtomicBoolean(false); var waiter = new ThreadAnonymousClass2(this, lastGen, thread, finished); waiter.Start(); manager.MaybeRefresh(); waiter.Join(1000); if (!finished) { waiter.Interrupt(); fail("thread deadlocked on waitForGeneration"); } thread.Dispose(); thread.Join(); IOUtils.Dispose(manager, _writer, d); }
public virtual void TestConcurrency() { // tests that addTaxonomy and addCategory work in parallel int numCategories = AtLeast(10000); // build an input taxonomy index Directory src = NewDirectory(); var tw = new DirectoryTaxonomyWriter(src); for (int i = 0; i < numCategories; i++) { tw.AddCategory(new FacetLabel("a", Convert.ToString(i, CultureInfo.InvariantCulture))); } tw.Dispose(); // now add the taxonomy to an empty taxonomy, while adding the categories // again, in parallel -- in the end, no duplicate categories should exist. Directory dest = NewDirectory(); var destTw = new DirectoryTaxonomyWriter(dest); var t = new ThreadAnonymousClass2(this, numCategories, destTw); t.Start(); IOrdinalMap map = new MemoryOrdinalMap(); destTw.AddTaxonomy(src, map); t.Join(); destTw.Dispose(); // now validate var dtr = new DirectoryTaxonomyReader(dest); // +2 to account for the root category + "a" Assert.AreEqual(numCategories + 2, dtr.Count); var categories = new JCG.HashSet <FacetLabel>(); for (int i = 1; i < dtr.Count; i++) { FacetLabel cat = dtr.GetPath(i); Assert.IsTrue(categories.Add(cat), "category " + cat + " already existed"); } dtr.Dispose(); IOUtils.Dispose(src, dest); }
public virtual void Test() { // update variables int commitPercent = Random.Next(20); int softCommitPercent = Random.Next(100); // what percent of the commits are soft int deletePercent = Random.Next(50); int deleteByQueryPercent = Random.Next(25); int ndocs = AtLeast(50); int nWriteThreads = TestUtil.NextInt32(Random, 1, TestNightly ? 10 : 5); int maxConcurrentCommits = TestUtil.NextInt32(Random, 1, TestNightly ? 10 : 5); // number of committers at a time... needed if we want to avoid commit errors due to exceeding the max bool tombstones = Random.NextBoolean(); // query variables AtomicInt64 operations = new AtomicInt64(AtLeast(10000)); // number of query operations to perform in total int nReadThreads = TestUtil.NextInt32(Random, 1, TestNightly ? 10 : 5); InitModel(ndocs); FieldType storedOnlyType = new FieldType(); storedOnlyType.IsStored = true; if (Verbose) { Console.WriteLine("\n"); Console.WriteLine("TEST: commitPercent=" + commitPercent); Console.WriteLine("TEST: softCommitPercent=" + softCommitPercent); Console.WriteLine("TEST: deletePercent=" + deletePercent); Console.WriteLine("TEST: deleteByQueryPercent=" + deleteByQueryPercent); Console.WriteLine("TEST: ndocs=" + ndocs); Console.WriteLine("TEST: nWriteThreads=" + nWriteThreads); Console.WriteLine("TEST: nReadThreads=" + nReadThreads); Console.WriteLine("TEST: maxConcurrentCommits=" + maxConcurrentCommits); Console.WriteLine("TEST: tombstones=" + tombstones); Console.WriteLine("TEST: operations=" + operations); Console.WriteLine("\n"); } AtomicInt32 numCommitting = new AtomicInt32(); IList <ThreadJob> threads = new JCG.List <ThreadJob>(); Directory dir = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))); writer.DoRandomForceMergeAssert = false; writer.Commit(); reader = DirectoryReader.Open(dir); for (int i = 0; i < nWriteThreads; i++) { ThreadJob thread = new ThreadAnonymousClass(this, "WRITER" + i, commitPercent, softCommitPercent, deletePercent, deleteByQueryPercent, ndocs, maxConcurrentCommits, tombstones, operations, storedOnlyType, numCommitting, writer); threads.Add(thread); } for (int i = 0; i < nReadThreads; i++) { ThreadJob thread = new ThreadAnonymousClass2(this, "READER" + i, ndocs, tombstones, operations); threads.Add(thread); } foreach (ThreadJob thread in threads) { thread.Start(); } foreach (ThreadJob thread in threads) { thread.Join(); } writer.Dispose(); if (Verbose) { Console.WriteLine("TEST: close reader=" + reader); } reader.Dispose(); dir.Dispose(); }