public void testIndexAndMerge() throws Exception {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw, true);
Directory directory = FSDirectory.getDirectory(indexDir, true);
directory.close();
indexDoc("one", "test.txt");
printSegment(out, "one");
indexDoc("two", "test2.txt");
printSegment(out, "two");
merge("one", "two", "merge", false);
printSegment(out, "merge");
merge("one", "two", "merge2", false);
printSegment(out, "merge2");
merge("merge", "merge2", "merge3", false);
printSegment(out, "merge3");
out.close();
sw.close();
String multiFileOutput = sw.getBuffer().toString();
//System.out.println(multiFileOutput);
sw = new StringWriter();
out = new PrintWriter(sw, true);
directory = FSDirectory.getDirectory(indexDir, true);
directory.close();
indexDoc("one", "test.txt");
printSegment(out, "one");
indexDoc("two", "test2.txt");
printSegment(out, "two");
merge("one", "two", "merge", true);
printSegment(out, "merge");
merge("one", "two", "merge2", true);
printSegment(out, "merge2");
merge("merge", "merge2", "merge3", true);
printSegment(out, "merge3");
out.close();
sw.close();
String singleFileOutput = sw.getBuffer().toString();
assertEquals(multiFileOutput, singleFileOutput);
}
This test executes a number of merges and compares the contents of
the segments created when using compound file or not using one.
TODO: the original test used to print the segment contents to System.out
for visual validation. To have the same effect, a new method
checkSegment(String name, ...) should be created that would
assert various things about the segment. |