From de5b443d5b9d8253981fcce846488844e089fa53 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 1 Apr 2015 03:55:45 +0000 Subject: [PATCH] make this test more verbose when it fails git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1670551 13f79535-47bb-0310-9956-ffa450edef68 --- .../index/TestIndexWriterForceMerge.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterForceMerge.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterForceMerge.java index fcbc461ef08..722acef61ac 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterForceMerge.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterForceMerge.java @@ -18,12 +18,18 @@ package org.apache.lucene.index; */ import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Locale; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -146,6 +152,7 @@ public class TestIndexWriterForceMerge extends LuceneTestCase { if (VERBOSE) { System.out.println("TEST: start disk usage = " + startDiskUsage); } + String startListing = listFiles(dir); dir.resetMaxUsedSizeInBytes(); dir.setTrackDiskUsage(true); @@ -182,10 +189,31 @@ public class TestIndexWriterForceMerge extends LuceneTestCase { + startDiskUsage + " bytes; final usage was " + finalDiskUsage + " bytes; max temp usage was " + maxDiskUsage + " but should have been " + (3 * maxStartFinalDiskUsage) - + " (= 3X starting usage)", maxDiskUsage <= 3 * maxStartFinalDiskUsage); + + " (= 3X starting usage), BEFORE=" + startListing + "AFTER=" + listFiles(dir), maxDiskUsage <= 3 * maxStartFinalDiskUsage); dir.close(); } + // print out listing of files and sizes, but recurse into CFS to debug nested files there. + private String listFiles(Directory dir) throws IOException { + SegmentInfos infos = SegmentInfos.readLatestCommit(dir); + StringBuilder sb = new StringBuilder(); + sb.append(System.lineSeparator()); + for (SegmentCommitInfo info : infos) { + for (String file : info.files()) { + sb.append(String.format(Locale.ROOT, "%-20s%d%n", file, dir.fileLength(file))); + } + if (info.info.getUseCompoundFile()) { + try (Directory cfs = info.info.getCodec().compoundFormat().getCompoundReader(dir, info.info, IOContext.DEFAULT)) { + for (String file : cfs.listAll()) { + sb.append(String.format(Locale.ROOT, " |- (inside compound file) %-20s%d%n", file, cfs.fileLength(file))); + } + } + } + } + sb.append(System.lineSeparator()); + return sb.toString(); + } + // Test calling forceMerge(1, false) whereby forceMerge is kicked // off but we don't wait for it to finish (but // writer.close()) does wait