LOL! ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: u...@thetaphi.de
> -----Original Message----- > From: rm...@apache.org [mailto:rm...@apache.org] > Sent: Friday, May 11, 2012 4:18 AM > To: comm...@lucene.apache.org > Subject: svn commit: r1337005 - in /lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene: index/AlcoholicMergePolicy.java > util/LuceneTestCase.java > > Author: rmuir > Date: Fri May 11 02:18:24 2012 > New Revision: 1337005 > > URL: http://svn.apache.org/viewvc?rev=1337005&view=rev > Log: > peanut butter hamburgers > > Added: > lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/index/AlcoholicMergePolicy.java > Modified: > lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/util/LuceneTestCase.java > > Added: lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/index/AlcoholicMergePolicy.java > URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/index/AlcoholicMergePolicy.java?rev= > 1337005&view=auto > ================================================================ > ============== > --- lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/index/AlcoholicMergePolicy.java > (added) > +++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/in > +++ dex/AlcoholicMergePolicy.java Fri May 11 02:18:24 2012 > @@ -0,0 +1,84 @@ > +package org.apache.lucene.index; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one or more > + * contributor license agreements. See the NOTICE file distributed > +with > + * this work for additional information regarding copyright ownership. > + * The ASF licenses this file to You under the Apache License, Version > +2.0 > + * (the "License"); you may not use this file except in compliance with > + * the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > + > +import java.io.IOException; > +import java.util.Calendar; > +import java.util.GregorianCalendar; > +import java.util.Random; > +import java.util.TimeZone; > + > +/** > + * <p> > + * Merge policy for testing, it is like an alcoholic. > + * It drinks (merges) at night, and randomly decides what to drink. > + * During the daytime it sleeps. > + * </p> > + * <p> > + * if tests pass with this, then they are likely to pass with any > + * bizarro merge policy users might write. > + * </p> > + * <p> > + * It is a fine bottle of champagne (Ordered by Martijn). > + * </p> > + */ > +public class AlcoholicMergePolicy extends LogMergePolicy { > + > + private final Random random; > + private final Calendar calendar; > + > + public AlcoholicMergePolicy(TimeZone tz, Random random) { > + this.calendar = new GregorianCalendar(tz); > + this.random = random; > + } > + > + @Override > + //@BlackMagic(level=Voodoo); > + protected long size(SegmentInfo info) throws IOException { > + int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); > + if (hourOfDay < 6 || > + hourOfDay > 20 || > + // its 5 o'clock somewhere > + random.nextInt(23) == 5) { > + > + 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 maxMergeSize == Long.MAX_VALUE ? maxMergeSize : > + maxMergeSize+1; > + > + } > + > + public static enum Drink { > + > + Beer(15), Wine(17), Champagne(21), WhiteRussian(22), > + SingleMalt(30); > + > + long drunkFactor; > + > + Drink(long drunkFactor) { > + this.drunkFactor = drunkFactor; > + } > + > + public long drunk() { > + return drunkFactor; > + } > + > + } > + > +} > > Modified: lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/util/LuceneTestCase.java > URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=133700 > 5&r1=1337004&r2=1337005&view=diff > ================================================================ > ============== > --- lucene/dev/trunk/lucene/test- > framework/src/java/org/apache/lucene/util/LuceneTestCase.java (original) > +++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/ut > +++ il/LuceneTestCase.java Fri May 11 02:18:24 2012 > @@ -58,6 +58,7 @@ import org.apache.lucene.index.Directory import > org.apache.lucene.index.FieldFilterAtomicReader; > import org.apache.lucene.index.FieldInfo; > import org.apache.lucene.index.IndexReader.ReaderClosedListener; > +import org.apache.lucene.index.AlcoholicMergePolicy; > import org.apache.lucene.index.IndexReader; > import org.apache.lucene.index.IndexWriterConfig; > import org.apache.lucene.index.LogByteSizeMergePolicy; > @@ -1119,6 +1120,8 @@ public abstract class LuceneTestCase ext > c.setMergePolicy(new MockRandomMergePolicy(r)); > } else if (r.nextBoolean()) { > c.setMergePolicy(newTieredMergePolicy()); > + } else if (r.nextInt(5) == 0) { > + c.setMergePolicy(newAlcoholicMergePolicy()); > } else { > c.setMergePolicy(newLogMergePolicy()); > } > @@ -1135,6 +1138,15 @@ public abstract class LuceneTestCase ext > public static TieredMergePolicy newTieredMergePolicy() { > return newTieredMergePolicy(random()); > } > + > + public static AlcoholicMergePolicy newAlcoholicMergePolicy() { > + return newAlcoholicMergePolicy(random(), timeZone); } > + > + public static AlcoholicMergePolicy newAlcoholicMergePolicy(Random r, > TimeZone tz) { > + return new AlcoholicMergePolicy(tz, new Random(r.nextLong())); } > + > > public static LogMergePolicy newLogMergePolicy(Random r) { > LogMergePolicy logmp = r.nextBoolean() ? new LogDocMergePolicy() : new > LogByteSizeMergePolicy(); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org