You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Uwe Schindler <uw...@thetaphi.de> on 2012/05/11 04:36:09 UTC
RE: svn commit: r1337005 - in /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene: index/AlcoholicMergePolicy.java util/LuceneTestCase.java
LOL!
-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de
> -----Original Message-----
> From: rmuir@apache.org [mailto:rmuir@apache.org]
> Sent: Friday, May 11, 2012 4:18 AM
> To: commits@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-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org
Re: svn commit: r1337005 - in /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene:
index/AlcoholicMergePolicy.java util/LuceneTestCase.java
Posted by Martijn van Groningen <ma...@gmail.com>.
There is room for improvement :)
Yeah we should introduce an amount and order of drinks.
Also the drinking speed is important and whether non-alcoholic
beverages are consumed during the night.
Martijn
On 11 May 2012 1growFactor2:33, Dawid Weiss
<da...@cs.put.poznan.pl> wrote:
>>> + public static enum Drink {
>>> +
>>> + Beer(15), Wine(17), Champagne(21), WhiteRussian(22),
>>> + SingleMalt(30);
>>> +
>>> +
>>> + public long drunk() {
>>> + return drunkFactor;
>>> + }
>
> I think this isn't an independent value. This isn't even a Markov
> chain as it doesn't depend on the last state of the observed object
> and the drink to follow -- full history of drinks consumed so far
> would have to be considered, their order and quantities matter (i.e.,
> beer after champagne, singlemalt after beer etc.). Overflows (or
> so-called burst points) would certainly have to be empirically
> established as there is no theoretical model for them known in
> literature...
>
> Dawid
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>
--
Met vriendelijke groet,
Martijn van Groningen
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org
Re: svn commit: r1337005 - in /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene:
index/AlcoholicMergePolicy.java util/LuceneTestCase.java
Posted by Dawid Weiss <da...@cs.put.poznan.pl>.
>> + public static enum Drink {
>> +
>> + Beer(15), Wine(17), Champagne(21), WhiteRussian(22),
>> + SingleMalt(30);
>> +
>> +
>> + public long drunk() {
>> + return drunkFactor;
>> + }
I think this isn't an independent value. This isn't even a Markov
chain as it doesn't depend on the last state of the observed object
and the drink to follow -- full history of drinks consumed so far
would have to be considered, their order and quantities matter (i.e.,
beer after champagne, singlemalt after beer etc.). Overflows (or
so-called burst points) would certainly have to be empirically
established as there is no theoretical model for them known in
literature...
Dawid
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org