mirror of https://github.com/apache/lucene.git
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:
parent
2330786c5a
commit
a65779666d
|
@ -17,7 +17,10 @@ package org.apache.lucene.store;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
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.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.PrintStreamInfoStream;
|
||||
|
||||
/** Base class for per-LockFactory tests. */
|
||||
public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
|
||||
|
@ -186,6 +190,16 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
|
|||
this.numIteration = numIteration;
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
private String toString(ByteArrayOutputStream baos) {
|
||||
try {
|
||||
return baos.toString("UTF8");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
// shouldn't happen
|
||||
throw new RuntimeException(uee);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
IndexWriter writer = null;
|
||||
|
@ -193,8 +207,20 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
|
|||
if (VERBOSE) {
|
||||
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 {
|
||||
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) {
|
||||
// lock obtain timed out
|
||||
// NOTE: we should at some point
|
||||
|
@ -206,6 +232,7 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
|
|||
hitException = true;
|
||||
System.out.println("Stress Test Index Writer: creation hit unexpected exception: " + e.toString());
|
||||
e.printStackTrace(System.out);
|
||||
System.out.println(toString(baos));
|
||||
break;
|
||||
}
|
||||
if (writer != null) {
|
||||
|
@ -215,6 +242,7 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
|
|||
hitException = true;
|
||||
System.out.println("Stress Test Index Writer: addDoc hit unexpected exception: " + e.toString());
|
||||
e.printStackTrace(System.out);
|
||||
System.out.println(toString(baos));
|
||||
break;
|
||||
}
|
||||
try {
|
||||
|
@ -223,6 +251,7 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
|
|||
hitException = true;
|
||||
System.out.println("Stress Test Index Writer: close hit unexpected exception: " + e.toString());
|
||||
e.printStackTrace(System.out);
|
||||
System.out.println(toString(baos));
|
||||
break;
|
||||
}
|
||||
writer = null;
|
||||
|
@ -230,7 +259,7 @@ public abstract class BaseLockFactoryTestCase extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class SearcherThread extends Thread {
|
||||
private Directory dir;
|
||||
private int numIteration;
|
||||
|
|
Loading…
Reference in New Issue