fix AlcoholicMergePolicy to not excessively exaggerate segment sizes as it's getting drunk

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1337653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-05-12 21:02:50 +00:00
parent 42ebab7867
commit 7e511f80d1
2 changed files with 7 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil;
@SuppressCodecs({ "SimpleText", "Memory" })
public class TestSearchWithThreads extends LuceneTestCase {

View File

@ -23,6 +23,8 @@ import java.util.GregorianCalendar;
import java.util.Random;
import java.util.TimeZone;
import org.apache.lucene.util._TestUtil;
/**
* <p>
* Merge policy for testing, it is like an alcoholic.
@ -45,6 +47,7 @@ public class AlcoholicMergePolicy extends LogMergePolicy {
public AlcoholicMergePolicy(TimeZone tz, Random random) {
this.calendar = new GregorianCalendar(tz);
this.random = random;
maxMergeSize = _TestUtil.nextInt(random, 1024*1024, Integer.MAX_VALUE);
}
@Override
@ -58,11 +61,10 @@ public class AlcoholicMergePolicy extends LogMergePolicy {
Drink[] values = Drink.values();
// pick a random drink during the day
return values[random.nextInt(values.length)].drunkFactor * (1 + random.nextInt(Integer.MAX_VALUE / 2));
return values[random.nextInt(values.length)].drunkFactor * info.sizeInBytes();
}
return maxMergeSize == Long.MAX_VALUE ? maxMergeSize : maxMergeSize+1;
return info.sizeInBytes();
}
public static enum Drink {