diff --git a/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java b/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java index e8bc977931b..f2ee32950c8 100644 --- a/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java +++ b/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java @@ -58,21 +58,36 @@ public class MockRandomMergePolicy extends MergePolicy { SegmentInfos segmentInfos, int maxSegmentCount, Set 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; }