LUCENE-3083: MockRandomMergePolicy should respect segmentsToOptimize (tests-only bug)

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1101056 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-05-09 15:17:33 +00:00
parent b30e4e4ec8
commit ce7da76d16
1 changed files with 23 additions and 8 deletions

View File

@ -58,21 +58,36 @@ public class MockRandomMergePolicy extends MergePolicy {
SegmentInfos segmentInfos, int maxSegmentCount, Set<SegmentInfo> segmentsToOptimize)
throws CorruptIndexException, IOException {
//System.out.println("MRMP: findMergesForOptimize sis=" + segmentInfos);
final SegmentInfos eligibleSegments = new SegmentInfos();
for(SegmentInfo info : segmentInfos) {
if (segmentsToOptimize.contains(info)) {
eligibleSegments.add(info);
}
}
//System.out.println("MRMP: findMergesForOptimize sis=" + segmentInfos + " eligible=" + eligibleSegments);
MergeSpecification mergeSpec = null;
if (segmentInfos.size() > 1 || (segmentInfos.size() == 1 && segmentInfos.info(0).hasDeletions())) {
if (eligibleSegments.size() > 1 || (eligibleSegments.size() == 1 && eligibleSegments.get(0).hasDeletions())) {
mergeSpec = new MergeSpecification();
SegmentInfos segmentInfos2 = new SegmentInfos();
segmentInfos2.addAll(segmentInfos);
Collections.shuffle(segmentInfos2, random);
// Already shuffled having come out of a set but
// shuffle again for good measure:
Collections.shuffle(eligibleSegments, random);
int upto = 0;
while(upto < segmentInfos.size()) {
int max = Math.min(10, segmentInfos.size()-upto);
while(upto < eligibleSegments.size()) {
int max = Math.min(10, eligibleSegments.size()-upto);
int inc = max <= 2 ? max : _TestUtil.nextInt(random, 2, max);
mergeSpec.add(new OneMerge(segmentInfos2.range(upto, upto+inc)));
mergeSpec.add(new OneMerge(eligibleSegments.range(upto, upto+inc)));
upto += inc;
}
}
if (mergeSpec != null) {
for(OneMerge merge : mergeSpec.merges) {
for(SegmentInfo info : merge.segments) {
assert segmentsToOptimize.contains(info);
}
}
}
return mergeSpec;
}