mirror of https://github.com/apache/lucene.git
LUCENE-5644: i moved this test over to new class
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1593027 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
abde483cd4
commit
ba888c0987
|
@ -2788,66 +2788,4 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
r.close();
|
r.close();
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// LUCENE-5644
|
|
||||||
public void testSegmentCountOnFlush() throws Exception {
|
|
||||||
Directory dir = newDirectory();
|
|
||||||
final IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
|
|
||||||
final CountDownLatch startingGun = new CountDownLatch(1);
|
|
||||||
final CountDownLatch startDone = new CountDownLatch(2);
|
|
||||||
final CountDownLatch middleGun = new CountDownLatch(1);
|
|
||||||
final CountDownLatch finalGun = new CountDownLatch(1);
|
|
||||||
Thread[] threads = new Thread[2];
|
|
||||||
for(int i=0;i<threads.length;i++) {
|
|
||||||
final int threadID = i;
|
|
||||||
threads[i] = new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
startingGun.await();
|
|
||||||
Document doc = new Document();
|
|
||||||
doc.add(newTextField("field", "here is some text", Field.Store.NO));
|
|
||||||
w.addDocument(doc);
|
|
||||||
startDone.countDown();
|
|
||||||
|
|
||||||
middleGun.await();
|
|
||||||
if (threadID == 0) {
|
|
||||||
w.addDocument(doc);
|
|
||||||
} else {
|
|
||||||
finalGun.await();
|
|
||||||
w.addDocument(doc);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
threads[i].start();
|
|
||||||
}
|
|
||||||
|
|
||||||
startingGun.countDown();
|
|
||||||
startDone.await();
|
|
||||||
|
|
||||||
IndexReader r = DirectoryReader.open(w, true);
|
|
||||||
assertEquals(2, r.numDocs());
|
|
||||||
int numSegments = r.leaves().size();
|
|
||||||
// 1 segment if the threads ran sequentially, else 2:
|
|
||||||
assertTrue(numSegments <= 2);
|
|
||||||
r.close();
|
|
||||||
|
|
||||||
middleGun.countDown();
|
|
||||||
threads[0].join();
|
|
||||||
|
|
||||||
finalGun.countDown();
|
|
||||||
threads[1].join();
|
|
||||||
|
|
||||||
r = DirectoryReader.open(w, true);
|
|
||||||
assertEquals(4, r.numDocs());
|
|
||||||
// Both threads should have shared a single thread state since they did not try to index concurrently:
|
|
||||||
assertEquals(1+numSegments, r.leaves().size());
|
|
||||||
r.close();
|
|
||||||
|
|
||||||
w.close();
|
|
||||||
dir.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue