print IW infoStream on failure in this test

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1697776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-08-25 22:15:42 +00:00
parent 2330786c5a
commit a65779666d
1 changed files with 32 additions and 3 deletions

View File

@ -17,7 +17,10 @@ package org.apache.lucene.store;
* limitations under the License. * limitations under the License.
*/ */
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.concurrent.CyclicBarrier; import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -30,13 +33,14 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.PrintStreamInfoStream;
/** Base class for per-LockFactory tests. */ /** Base class for per-LockFactory tests. */
public abstract class BaseLockFactoryTestCase extends LuceneTestCase { public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
@ -186,6 +190,16 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
this.numIteration = numIteration; this.numIteration = numIteration;
this.dir = dir; this.dir = dir;
} }
private String toString(ByteArrayOutputStream baos) {
try {
return baos.toString("UTF8");
} catch (UnsupportedEncodingException uee) {
// shouldn't happen
throw new RuntimeException(uee);
}
}
@Override @Override
public void run() { public void run() {
IndexWriter writer = null; IndexWriter writer = null;
@ -193,8 +207,20 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
if (VERBOSE) { if (VERBOSE) {
System.out.println("TEST: WriterThread iter=" + i); System.out.println("TEST: WriterThread iter=" + i);
} }
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
// We only print the IW infoStream output on exc, below:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try { try {
writer = new IndexWriter(dir, new IndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND)); iwc.setInfoStream(new PrintStreamInfoStream(new PrintStream(baos, true, "UTF8")));
} catch (UnsupportedEncodingException uee) {
// shouldn't happen
throw new RuntimeException(uee);
}
iwc.setOpenMode(OpenMode.APPEND);
try {
writer = new IndexWriter(dir, iwc);
} catch (LockObtainFailedException e) { } catch (LockObtainFailedException e) {
// lock obtain timed out // lock obtain timed out
// NOTE: we should at some point // NOTE: we should at some point
@ -206,6 +232,7 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
hitException = true; hitException = true;
System.out.println("Stress Test Index Writer: creation hit unexpected exception: " + e.toString()); System.out.println("Stress Test Index Writer: creation hit unexpected exception: " + e.toString());
e.printStackTrace(System.out); e.printStackTrace(System.out);
System.out.println(toString(baos));
break; break;
} }
if (writer != null) { if (writer != null) {
@ -215,6 +242,7 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
hitException = true; hitException = true;
System.out.println("Stress Test Index Writer: addDoc hit unexpected exception: " + e.toString()); System.out.println("Stress Test Index Writer: addDoc hit unexpected exception: " + e.toString());
e.printStackTrace(System.out); e.printStackTrace(System.out);
System.out.println(toString(baos));
break; break;
} }
try { try {
@ -223,6 +251,7 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
hitException = true; hitException = true;
System.out.println("Stress Test Index Writer: close hit unexpected exception: " + e.toString()); System.out.println("Stress Test Index Writer: close hit unexpected exception: " + e.toString());
e.printStackTrace(System.out); e.printStackTrace(System.out);
System.out.println(toString(baos));
break; break;
} }
writer = null; writer = null;