diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java b/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java index 9d8e0ee8798..a98c208dbab 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java @@ -64,7 +64,7 @@ public class MockRandomMergePolicy extends MergePolicy { // TODO: sometimes make more than 1 merge? mergeSpec = new MergeSpecification(); final int segsToMerge = TestUtil.nextInt(random, 1, numSegments); - mergeSpec.add(new OneMerge(segments.subList(0, segsToMerge))); + mergeSpec.add(new MockRandomOneMerge(segments.subList(0, segsToMerge),random.nextLong())); } return mergeSpec; @@ -93,7 +93,7 @@ public class MockRandomMergePolicy extends MergePolicy { 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(eligibleSegments.subList(upto, upto+inc))); + mergeSpec.add(new MockRandomOneMerge(eligibleSegments.subList(upto, upto+inc), random.nextLong())); upto += inc; } } @@ -122,4 +122,28 @@ public class MockRandomMergePolicy extends MergePolicy { // 80% of the time we create CFS: return random.nextInt(5) != 1; } + + static class MockRandomOneMerge extends OneMerge { + final Random r; + ArrayList readers; + + MockRandomOneMerge(List segments, long seed) { + super(segments); + r = new Random(seed); + } + + @Override + public List getMergeReaders() throws IOException { + if (readers == null) { + readers = new ArrayList(super.getMergeReaders()); + for (int i = 0; i < readers.size(); i++) { + // wrap it (e.g. prevent bulk merge etc) + if (r.nextInt(4) == 0) { + readers.set(i, new FilterAtomicReader(readers.get(i))); + } + } + } + return readers; + } + } }