From 1d4d9c588ca433262feb79297262dca73e327f2e Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Sun, 7 Feb 2016 13:35:00 -0500 Subject: [PATCH] LUCENE-6750: add verbosity when this test fails --- .../lucene/TestMergeSchedulerExternal.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/TestMergeSchedulerExternal.java b/lucene/core/src/test/org/apache/lucene/TestMergeSchedulerExternal.java index 241e966c8e8..d4aaeb13fb6 100644 --- a/lucene/core/src/test/org/apache/lucene/TestMergeSchedulerExternal.java +++ b/lucene/core/src/test/org/apache/lucene/TestMergeSchedulerExternal.java @@ -17,6 +17,10 @@ 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.document.Document; 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.IndexWriterConfig; 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; import org.apache.lucene.index.MergeScheduler; import org.apache.lucene.index.MergeTrigger; 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.LuceneTestCase; - -import java.io.IOException; +import org.apache.lucene.util.PrintStreamInfoStream; /** * Holds tests cases to verify external APIs are accessible @@ -93,11 +97,16 @@ public class TestMergeSchedulerExternal extends LuceneTestCase { Document doc = new Document(); Field idField = newStringField("id", "", Field.Store.YES); doc.add(idField); - - IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())) - .setMergeScheduler(new MyMergeScheduler()) - .setMaxBufferedDocs(2).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH) - .setMergePolicy(newLogMergePolicy())); + + IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())) + .setMergeScheduler(new MyMergeScheduler()) + .setMaxBufferedDocs(2).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH) + .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(); logMP.setMergeFactor(10); for(int i=0;i<20;i++) { @@ -110,10 +119,16 @@ public class TestMergeSchedulerExternal extends LuceneTestCase { // OK } writer.rollback(); - - assertTrue(mergeThreadCreated); - assertTrue(mergeCalled); - assertTrue(excCalled); + + try { + assertTrue(mergeThreadCreated); + assertTrue(mergeCalled); + 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(); }