fix test bug

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1605003 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-06-24 03:57:58 +00:00
parent bbd4f58af5
commit a50cc2bac2
1 changed files with 7 additions and 2 deletions

View File

@ -332,14 +332,17 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
private static class TrackingCMS extends ConcurrentMergeScheduler { private static class TrackingCMS extends ConcurrentMergeScheduler {
long totMergedBytes; long totMergedBytes;
CountDownLatch atLeastOneMerge;
public TrackingCMS() { public TrackingCMS(CountDownLatch atLeastOneMerge) {
setMaxMergesAndThreads(5, 5); setMaxMergesAndThreads(5, 5);
this.atLeastOneMerge = atLeastOneMerge;
} }
@Override @Override
public void doMerge(MergePolicy.OneMerge merge) throws IOException { public void doMerge(MergePolicy.OneMerge merge) throws IOException {
totMergedBytes += merge.totalBytesSize(); totMergedBytes += merge.totalBytesSize();
atLeastOneMerge.countDown();
super.doMerge(merge); super.doMerge(merge);
} }
} }
@ -351,7 +354,8 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
} }
IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())); IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
iwc.setMaxBufferedDocs(5); iwc.setMaxBufferedDocs(5);
iwc.setMergeScheduler(new TrackingCMS()); CountDownLatch atLeastOneMerge = new CountDownLatch(1);
iwc.setMergeScheduler(new TrackingCMS(atLeastOneMerge));
if (TestUtil.getPostingsFormat("id").equals("SimpleText")) { if (TestUtil.getPostingsFormat("id").equals("SimpleText")) {
// no // no
iwc.setCodec(TestUtil.alwaysPostingsFormat(new Lucene41PostingsFormat())); iwc.setCodec(TestUtil.alwaysPostingsFormat(new Lucene41PostingsFormat()));
@ -366,6 +370,7 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {
w.deleteDocuments(new Term("id", ""+random().nextInt(i+1))); w.deleteDocuments(new Term("id", ""+random().nextInt(i+1)));
} }
} }
atLeastOneMerge.await();
assertTrue(((TrackingCMS) w.getConfig().getMergeScheduler()).totMergedBytes != 0); assertTrue(((TrackingCMS) w.getConfig().getMergeScheduler()).totMergedBytes != 0);
w.shutdown(); w.shutdown();
d.close(); d.close();