public virtual void TestOpenTwoIndexWritersOnDifferentThreads() { Directory dir = NewDirectory(); CountdownEvent oneIWConstructed = new CountdownEvent(1); DelayedIndexAndCloseRunnable thread1 = new DelayedIndexAndCloseRunnable(this, dir, oneIWConstructed); DelayedIndexAndCloseRunnable thread2 = new DelayedIndexAndCloseRunnable(this, dir, oneIWConstructed); thread1.Start(); thread2.Start(); oneIWConstructed.Wait(); thread1.StartIndexing(); thread2.StartIndexing(); thread1.Join(); thread2.Join(); // ensure the directory is closed if we hit the timeout and throw assume // TODO: can we improve this in LuceneTestCase? I dont know what the logic would be... try { AssumeFalse("aborting test: timeout obtaining lock", thread1.failure is LockObtainFailedException); AssumeFalse("aborting test: timeout obtaining lock", thread2.failure is LockObtainFailedException); Assert.IsFalse(thread1.failed, "Failed due to: " + thread1.failure); Assert.IsFalse(thread2.failed, "Failed due to: " + thread2.failure); // now verify that we have two documents in the index IndexReader reader = DirectoryReader.Open(dir); Assert.AreEqual(2, reader.NumDocs, "IndexReader should have one document per thread running"); reader.Dispose(); } finally { dir.Dispose(); } }
public virtual void TestOpenTwoIndexWritersOnDifferentThreads() { Directory dir = NewDirectory(); CountDownLatch oneIWConstructed = new CountDownLatch(1); DelayedIndexAndCloseRunnable thread1 = new DelayedIndexAndCloseRunnable(dir, oneIWConstructed); DelayedIndexAndCloseRunnable thread2 = new DelayedIndexAndCloseRunnable(dir, oneIWConstructed); thread1.Start(); thread2.Start(); oneIWConstructed.@await(); thread1.StartIndexing(); thread2.StartIndexing(); thread1.Join(); thread2.Join(); // ensure the directory is closed if we hit the timeout and throw assume // TODO: can we improve this in LuceneTestCase? I dont know what the logic would be... try { AssumeFalse("aborting test: timeout obtaining lock", thread1.Failure is LockObtainFailedException); AssumeFalse("aborting test: timeout obtaining lock", thread2.Failure is LockObtainFailedException); Assert.IsFalse(thread1.Failed, "Failed due to: " + thread1.Failure); Assert.IsFalse(thread2.Failed, "Failed due to: " + thread2.Failure); // now verify that we have two documents in the index IndexReader reader = DirectoryReader.Open(dir); Assert.AreEqual(2, reader.NumDocs, "IndexReader should have one document per thread running"); reader.Dispose(); } finally { dir.Dispose(); } }