Index: src/test/org/apache/lucene/index/TestIndexWriterReader.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexWriterReader.java (revision 950226) +++ src/test/org/apache/lucene/index/TestIndexWriterReader.java (working copy) @@ -32,6 +32,7 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; +import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.MockRAMDirectory; import org.apache.lucene.store.AlreadyClosedException; @@ -840,4 +841,25 @@ w.close(); } + public void testSegmentWarmer() throws Exception { + Directory dir = new MockRAMDirectory(); + IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(2).setReaderPooling(true)); + w.setMergedSegmentWarmer(new IndexWriter.IndexReaderWarmer() { + public void warm(IndexReader r) throws IOException { + final IndexSearcher s = new IndexSearcher(r); + final TopDocs hits = s.search(new TermQuery(new Term("foo", "bar")), 10); + assertEquals(20, hits.totalHits); + } + }); + + Document doc = new Document(); + doc.add(new Field("foo", "bar", Field.Store.YES, Field.Index.NOT_ANALYZED)); + for(int i=0;i<20;i++) { + w.addDocument(doc); + } + w.waitForMerges(); + w.close(); + dir.close(); + } } Index: src/test/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- src/test/org/apache/lucene/util/LuceneTestCase.java (revision 950226) +++ src/test/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -129,7 +129,18 @@ @Override protected void tearDown() throws Exception { BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount); + try { + Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler); + if (!uncaughtExceptions.isEmpty()) { + System.err.println("The following exceptions were thrown by threads:"); + for (UncaughtExceptionEntry entry : uncaughtExceptions) { + System.err.println("*** Thread: " + entry.thread.getName() + " ***"); + entry.exception.printStackTrace(System.err); + } + fail("Some threads throwed uncaught exceptions!"); + } + // this isn't as useful as calling directly from the scope where the // index readers are used, because they could be gc'ed just before // tearDown is called. @@ -145,17 +156,7 @@ } finally { purgeFieldCache(FieldCache.DEFAULT); } - - Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler); - if (!uncaughtExceptions.isEmpty()) { - System.err.println("The following exceptions were thrown by threads:"); - for (UncaughtExceptionEntry entry : uncaughtExceptions) { - System.err.println("*** Thread: " + entry.thread.getName() + " ***"); - entry.exception.printStackTrace(System.err); - } - fail("Some threads throwed uncaught exceptions!"); - } - + super.tearDown(); }