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
This commit is contained in:
Robert Muir 2015-04-01 03:55:45 +00:00
parent 809998adff
commit de5b443d5b
1 changed files with 29 additions and 1 deletions

View File

@ -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