From dcb19cd007dea15ee0d28b3764d30d04d4a8aeec Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 13 May 2015 20:45:16 +0000 Subject: [PATCH] add test case git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1679273 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/TestIndexWriter.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index a66541fe7d3..51445f47cba 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -2691,5 +2691,35 @@ public class TestIndexWriter extends LuceneTestCase { r.close(); d.close(); } + + public void testManySeparateThreads() throws Exception { + Directory dir = newDirectory(); + IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); + iwc.setMaxBufferedDocs(1000); + final IndexWriter w = new IndexWriter(dir, iwc); + // Index 100 docs, each from a new thread, but always only 1 thread is in IW at once: + for(int i=0;i<100;i++) { + Thread thread = new Thread() { + @Override + public void run() { + Document doc = new Document(); + doc.add(newStringField("foo", "bar", Field.Store.NO)); + try { + w.addDocument(doc); + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + } + }; + thread.start(); + thread.join(); + } + w.close(); + + IndexReader r = DirectoryReader.open(dir); + assertEquals(1, r.leaves().size()); + r.close(); + dir.close(); + } }