yet more verbosity for this test that only fails rarely on OS X

This commit is contained in:
Mike McCandless 2016-02-18 09:27:21 -05:00
parent fc879d1a5d
commit 2018122bcf
1 changed files with 14 additions and 2 deletions

View File

@ -20,6 +20,8 @@ package org.apache.lucene;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@ -36,6 +38,7 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.PrintStreamInfoStream;
@ -48,6 +51,7 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {
volatile boolean mergeCalled;
volatile boolean mergeThreadCreated;
volatile boolean excCalled;
volatile static InfoStream infoStream;
private class MyMergeScheduler extends ConcurrentMergeScheduler {
@ -84,7 +88,14 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {
StackTraceElement[] trace = new Exception().getStackTrace();
for (int i = 0; i < trace.length; i++) {
if ("doMerge".equals(trace[i].getMethodName())) {
throw new IOException("now failing during merge");
IOException ioe = new IOException("now failing during merge");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ioe.printStackTrace(pw);
if (infoStream.isEnabled("IW")) {
infoStream.message("IW", "TEST: now throw exc:\n" + sw.toString());
}
throw ioe;
}
}
}
@ -104,7 +115,8 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {
.setMergePolicy(newLogMergePolicy());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
iwc.setInfoStream(new PrintStreamInfoStream(new PrintStream(baos, true, IOUtils.UTF_8)));
infoStream = new PrintStreamInfoStream(new PrintStream(baos, true, IOUtils.UTF_8));
iwc.setInfoStream(infoStream);
IndexWriter writer = new IndexWriter(dir, iwc);
LogMergePolicy logMP = (LogMergePolicy) writer.getConfig().getMergePolicy();