lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1101056 - /lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java
Date Mon, 09 May 2011 15:17:33 GMT
Author: mikemccand
Date: Mon May  9 15:17:33 2011
New Revision: 1101056

URL: http://svn.apache.org/viewvc?rev=1101056&view=rev
Log:
LUCENE-3083: MockRandomMergePolicy should respect segmentsToOptimize (tests-only bug)

Modified:
    lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java

Modified: lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java?rev=1101056&r1=1101055&r2=1101056&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java
(original)
+++ lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/index/MockRandomMergePolicy.java
Mon May  9 15:17:33 2011
@@ -58,21 +58,36 @@ public class MockRandomMergePolicy exten
       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;
   }
 



Mime
View raw message