LUCENE-6750: add verbosity when this test fails

This commit is contained in:
Mike McCandless 2016-02-07 13:35:00 -05:00
parent f8bd22e58c
commit 1d4d9c588c
1 changed files with 27 additions and 12 deletions

View File

@ -17,6 +17,10 @@
package org.apache.lucene; package org.apache.lucene;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
@ -24,16 +28,16 @@ import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LogMergePolicy; import org.apache.lucene.index.LogMergePolicy;
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.MergePolicy.OneMerge; import org.apache.lucene.index.MergePolicy.OneMerge;
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.MergeScheduler; import org.apache.lucene.index.MergeScheduler;
import org.apache.lucene.index.MergeTrigger; import org.apache.lucene.index.MergeTrigger;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.PrintStreamInfoStream;
import java.io.IOException;
/** /**
* Holds tests cases to verify external APIs are accessible * Holds tests cases to verify external APIs are accessible
@ -94,10 +98,15 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {
Field idField = newStringField("id", "", Field.Store.YES); Field idField = newStringField("id", "", Field.Store.YES);
doc.add(idField); doc.add(idField);
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())) IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()))
.setMergeScheduler(new MyMergeScheduler()) .setMergeScheduler(new MyMergeScheduler())
.setMaxBufferedDocs(2).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH) .setMaxBufferedDocs(2).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH)
.setMergePolicy(newLogMergePolicy())); .setMergePolicy(newLogMergePolicy());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
iwc.setInfoStream(new PrintStreamInfoStream(new PrintStream(baos, true, IOUtils.UTF_8)));
IndexWriter writer = new IndexWriter(dir, iwc);
LogMergePolicy logMP = (LogMergePolicy) writer.getConfig().getMergePolicy(); LogMergePolicy logMP = (LogMergePolicy) writer.getConfig().getMergePolicy();
logMP.setMergeFactor(10); logMP.setMergeFactor(10);
for(int i=0;i<20;i++) { for(int i=0;i<20;i++) {
@ -111,9 +120,15 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {
} }
writer.rollback(); writer.rollback();
try {
assertTrue(mergeThreadCreated); assertTrue(mergeThreadCreated);
assertTrue(mergeCalled); assertTrue(mergeCalled);
assertTrue(excCalled); assertTrue(excCalled);
} catch (AssertionError ae) {
System.out.println("TEST FAILED; IW infoStream output:");
System.out.println(baos.toString(IOUtils.UTF_8));
throw ae;
}
dir.close(); dir.close();
} }