From 972da5872fabbc0cd12fa2e12171be8e24f665fa Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 10 May 2010 07:47:12 +0000 Subject: [PATCH] LUCENE-2449: add 'knob' (-Drandom.multiplier=N, defaults to 1) to tune up how much random testing is done; fix sneaky bugs (workaround java's bug in new String(int[], int, int); nasty key reuse bug in DBLRUCache) that this deeper testing uncovered git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@942676 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/LICENSE.txt | 34 +++++++ lucene/common-build.xml | 2 + .../index/codecs/preflex/TermInfosReader.java | 30 ++++-- .../standard/StandardTermsDictReader.java | 12 ++- .../apache/lucene/search/FuzzyTermsEnum.java | 6 +- .../apache/lucene/search/MultiSearcher.java | 2 + .../lucene/util/DoubleBarrelLRUCache.java | 5 + .../org/apache/lucene/util/UnicodeUtil.java | 94 +++++++++++++++++++ .../util/automaton/BasicOperations.java | 9 +- .../lucene/analysis/TestCharArrayMap.java | 3 +- .../lucene/analysis/TestCharTokenizers.java | 3 +- .../org/apache/lucene/index/FlexTestUtil.java | 2 +- .../apache/lucene/index/TestAtomicUpdate.java | 2 +- .../apache/lucene/index/TestByteSlices.java | 3 +- .../org/apache/lucene/index/TestCodecs.java | 3 +- .../lucene/index/TestIndexReaderReopen.java | 3 +- .../apache/lucene/index/TestIndexWriter.java | 9 +- .../org/apache/lucene/index/TestPayloads.java | 2 +- .../lucene/index/TestStressIndexing.java | 2 +- .../lucene/index/TestStressIndexing2.java | 2 +- .../apache/lucene/index/TestTransactions.java | 3 +- .../apache/lucene/search/TestBoolean2.java | 3 +- .../search/TestBooleanMinShouldMatch.java | 3 +- .../lucene/search/TestCustomSearcherSort.java | 7 +- .../TestMultiValuedNumericRangeQuery.java | 5 +- .../search/TestNumericRangeQuery32.java | 10 +- .../search/TestNumericRangeQuery64.java | 9 +- .../lucene/search/TestRegexpRandom.java | 5 +- .../lucene/search/TestRegexpRandom2.java | 4 +- .../apache/lucene/search/TestScorerPerf.java | 8 +- .../org/apache/lucene/search/TestSort.java | 3 +- .../apache/lucene/search/TestThreadSafe.java | 3 +- .../lucene/search/TestWildcardRandom.java | 5 +- .../apache/lucene/store/TestWindowsMMap.java | 3 +- .../org/apache/lucene/util/TestArrayUtil.java | 2 +- .../lucene/util/TestDoubleBarrelLRUCache.java | 76 +++++++++++---- .../util/TestIndexableBinaryStringTools.java | 4 +- .../apache/lucene/util/TestOpenBitSet.java | 4 +- .../apache/lucene/util/TestPriorityQueue.java | 2 +- .../apache/lucene/util/TestSmallFloat.java | 2 +- .../apache/lucene/util/TestStringIntern.java | 2 +- .../apache/lucene/util/TestUnicodeUtil.java | 79 +++++++++++++++- .../org/apache/lucene/util/_TestUtil.java | 6 ++ .../util/automaton/TestBasicOperations.java | 8 +- .../util/automaton/TestDeterminism.java | 3 +- .../automaton/TestDeterminizeLexicon.java | 21 ++--- .../util/automaton/TestUTF32ToUTF8.java | 20 ++-- .../lucene/util/packed/TestPackedInts.java | 3 +- 48 files changed, 415 insertions(+), 116 deletions(-) diff --git a/lucene/LICENSE.txt b/lucene/LICENSE.txt index be159cb46a5..554d0c03cf9 100644 --- a/lucene/LICENSE.txt +++ b/lucene/LICENSE.txt @@ -300,3 +300,37 @@ Here is the copyright for those sources: # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. + +Some code in src/java/org/apache/lucene/util/UnicodeUtil.java was +derived from ICU (http://www.icu-project.org) +The full license is available here: + http://source.icu-project.org/repos/icu/icu/trunk/license.html + +/* + * Copyright (C) 1999-2010, International Business Machines + * Corporation and others. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * provided that the above copyright notice(s) and this permission notice appear + * in all copies of the Software and that both the above copyright notice(s) and + * this permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE + * LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall not + * be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization of the + * copyright holder. + */ + \ No newline at end of file diff --git a/lucene/common-build.xml b/lucene/common-build.xml index 53cc6f80b89..f99e7f69e84 100644 --- a/lucene/common-build.xml +++ b/lucene/common-build.xml @@ -55,6 +55,7 @@ + @@ -439,6 +440,7 @@ + diff --git a/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java b/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java index 7a7af748032..9886d32c1f4 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/preflex/TermInfosReader.java @@ -61,7 +61,26 @@ public final class TermInfosReader { } } - private final DoubleBarrelLRUCache termsCache = new DoubleBarrelLRUCache(DEFAULT_CACHE_SIZE); + private static class CloneableTerm extends DoubleBarrelLRUCache.CloneableKey { + private Term term; + public CloneableTerm(Term t) { + this.term = t; + } + + public boolean equals(Object other) { + return this.term.equals(other); + } + + public int hashCode() { + return term.hashCode(); + } + + public Object clone() { + return new CloneableTerm(term); + } + } + + private final DoubleBarrelLRUCache termsCache = new DoubleBarrelLRUCache(DEFAULT_CACHE_SIZE); /** * Per-thread resources managed by ThreadLocal @@ -197,8 +216,7 @@ public final class TermInfosReader { if (size == 0) return null; ensureIndexIsRead(); - - TermInfoAndOrd tiOrd = termsCache.get(term); + TermInfoAndOrd tiOrd = termsCache.get(new CloneableTerm(term)); ThreadResources resources = getThreadResources(); if (!mustSeekEnum && tiOrd != null) { @@ -209,7 +227,7 @@ public final class TermInfosReader { } TermInfo seekEnum(SegmentTermEnum enumerator, Term term) throws IOException { - return seekEnum(enumerator, term, termsCache.get(term)); + return seekEnum(enumerator, term, termsCache.get(new CloneableTerm(term))); } TermInfo seekEnum(SegmentTermEnum enumerator, Term term, TermInfoAndOrd tiOrd) throws IOException { @@ -235,7 +253,7 @@ public final class TermInfosReader { // wipe out the cache when they iterate over a large numbers // of terms in order if (tiOrd == null) { - termsCache.put(term, new TermInfoAndOrd(ti, (int) enumerator.position)); + termsCache.put(new CloneableTerm(term), new TermInfoAndOrd(ti, (int) enumerator.position)); } else { assert sameTermInfo(ti, tiOrd, enumerator); assert (int) enumerator.position == tiOrd.termOrd; @@ -264,7 +282,7 @@ public final class TermInfosReader { if (enumerator.term() != null && term.compareTo(enumerator.term()) == 0) { ti = enumerator.termInfo(); if (tiOrd == null) { - termsCache.put(term, new TermInfoAndOrd(ti, (int) enumerator.position)); + termsCache.put(new CloneableTerm(term), new TermInfoAndOrd(ti, (int) enumerator.position)); } else { assert sameTermInfo(ti, tiOrd, enumerator); assert (int) enumerator.position == tiOrd.termOrd; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java index 2d742822be7..647e4d0c9ec 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/standard/StandardTermsDictReader.java @@ -73,7 +73,7 @@ public class StandardTermsDictReader extends FieldsProducer { private StandardTermsIndexReader indexReader; // Used as key for the terms cache - private static class FieldAndTerm { + private static class FieldAndTerm extends DoubleBarrelLRUCache.CloneableKey { String field; BytesRef term; @@ -91,6 +91,11 @@ public class StandardTermsDictReader extends FieldsProducer { return other.field == field && term.bytesEquals(other.term); } + @Override + public Object clone() { + return new FieldAndTerm(this); + } + @Override public int hashCode() { return field.hashCode() * 31 + term.hashCode(); @@ -291,7 +296,7 @@ public class StandardTermsDictReader extends FieldsProducer { fieldTerm.term = term; TermState cachedState; if (useCache) { - cachedState = termsCache.get(fieldTerm); + cachedState = termsCache.get(new FieldAndTerm(fieldTerm)); if (cachedState != null) { state.copy(cachedState); seekPending = true; @@ -370,13 +375,12 @@ public class StandardTermsDictReader extends FieldsProducer { } else if (cmp > 0) { return SeekStatus.NOT_FOUND; } - // The purpose of the terms dict index is to seek // the enum to the closest index term before the // term we are looking for. So, we should never // cross another index term (besides the first // one) while we are scanning: - assert state.ord == startOrd || !fieldIndexReader.isIndexTerm(state.ord, state.docFreq, true); + assert state.ord == startOrd || !fieldIndexReader.isIndexTerm(state.ord, state.docFreq, true): "state.ord=" + state.ord + " startOrd=" + startOrd + " ir.isIndexTerm=" + fieldIndexReader.isIndexTerm(state.ord, state.docFreq, true) + " state.docFreq=" + state.docFreq; } return SeekStatus.END; diff --git a/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java b/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java index 085eaa59758..b2f1fcf6197 100644 --- a/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java +++ b/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java @@ -133,7 +133,7 @@ public final class FuzzyTermsEnum extends TermsEnum { if (runAutomata == null && maxDistance <= LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) { LevenshteinAutomata builder = - new LevenshteinAutomata(new String(termText, realPrefixLength, termText.length - realPrefixLength)); + new LevenshteinAutomata(UnicodeUtil.newString(termText, realPrefixLength, termText.length - realPrefixLength)); runAutomata = new ArrayList(maxDistance); for (int i = 0; i <= maxDistance; i++) { @@ -141,7 +141,7 @@ public final class FuzzyTermsEnum extends TermsEnum { // constant prefix if (realPrefixLength > 0) { Automaton prefix = BasicAutomata.makeString( - new String(termText, 0, realPrefixLength)); + UnicodeUtil.newString(termText, 0, realPrefixLength)); a = BasicOperations.concatenate(prefix, a); } runAutomata.add(new ByteRunAutomaton(a)); @@ -364,7 +364,7 @@ public final class FuzzyTermsEnum extends TermsEnum { this.text = new int[termLength - realPrefixLength]; System.arraycopy(termText, realPrefixLength, text, 0, text.length); - final String prefix = new String(termText, 0, realPrefixLength); + final String prefix = UnicodeUtil.newString(termText, 0, realPrefixLength); prefixBytesRef = new BytesRef(prefix); initializeMaxDistances(); this.d = initDistanceArray(); diff --git a/lucene/src/java/org/apache/lucene/search/MultiSearcher.java b/lucene/src/java/org/apache/lucene/search/MultiSearcher.java index c11da81e668..a7653e7f542 100644 --- a/lucene/src/java/org/apache/lucene/search/MultiSearcher.java +++ b/lucene/src/java/org/apache/lucene/search/MultiSearcher.java @@ -201,6 +201,7 @@ public class MultiSearcher extends Searcher { public TopDocs search(Weight weight, Filter filter, int nDocs) throws IOException { + nDocs = Math.min(nDocs, maxDoc()); final HitQueue hq = new HitQueue(nDocs, false); int totalHits = 0; @@ -221,6 +222,7 @@ public class MultiSearcher extends Searcher { @Override public TopFieldDocs search (Weight weight, Filter filter, int n, Sort sort) throws IOException { + n = Math.min(n, maxDoc()); FieldDocSortedHitQueue hq = new FieldDocSortedHitQueue(n); int totalHits = 0; diff --git a/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java b/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java index f0986f32219..5074f20820b 100644 --- a/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java +++ b/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java @@ -42,6 +42,11 @@ import java.util.Map; */ final public class DoubleBarrelLRUCache { + + public static abstract class CloneableKey { + abstract public Object clone(); + } + private final Map cache1; private final Map cache2; private final AtomicInteger countdown; diff --git a/lucene/src/java/org/apache/lucene/util/UnicodeUtil.java b/lucene/src/java/org/apache/lucene/util/UnicodeUtil.java index 3b9f242387f..a672b244e60 100644 --- a/lucene/src/java/org/apache/lucene/util/UnicodeUtil.java +++ b/lucene/src/java/org/apache/lucene/util/UnicodeUtil.java @@ -49,6 +49,42 @@ package org.apache.lucene.util; * remains attached. */ +/* + * Additional code came from the IBM ICU library. + * + * http://www.icu-project.org + * + * Full Copyright for that code follows. + */ + +/* + * Copyright (C) 1999-2010, International Business Machines + * Corporation and others. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * provided that the above copyright notice(s) and this permission notice appear + * in all copies of the Software and that both the above copyright notice(s) and + * this permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE + * LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder shall not + * be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization of the + * copyright holder. + */ + /** * Class to encode java's UTF16 char[] into UTF8 byte[] * without always allocating a new byte[] as @@ -579,4 +615,62 @@ final public class UnicodeUtil { utf32.offset = 0; utf32.length = utf32Count; } + + /** Shift value for lead surrogate to form a supplementary character. */ + private static final int LEAD_SURROGATE_SHIFT_ = 10; + /** Mask to retrieve the significant value from a trail surrogate.*/ + private static final int TRAIL_SURROGATE_MASK_ = 0x3FF; + /** Trail surrogate minimum value */ + private static final int TRAIL_SURROGATE_MIN_VALUE = 0xDC00; + /** Lead surrogate minimum value */ + private static final int LEAD_SURROGATE_MIN_VALUE = 0xD800; + /** The minimum value for Supplementary code points */ + private static final int SUPPLEMENTARY_MIN_VALUE = 0x10000; + /** Value that all lead surrogate starts with */ + private static final int LEAD_SURROGATE_OFFSET_ = LEAD_SURROGATE_MIN_VALUE + - (SUPPLEMENTARY_MIN_VALUE >> LEAD_SURROGATE_SHIFT_); + + /** + * Cover JDK 1.5 API. Create a String from an array of codePoints. + * + * @param codePoints The code array + * @param offset The start of the text in the code point array + * @param count The number of code points + * @return a String representing the code points between offset and count + * @throws IllegalArgumentException If an invalid code point is encountered + * @throws IndexOutOfBoundsException If the offset or count are out of bounds. + */ + public static String newString(int[] codePoints, int offset, int count) { + if (count < 0) { + throw new IllegalArgumentException(); + } + char[] chars = new char[count]; + int w = 0; + for (int r = offset, e = offset + count; r < e; ++r) { + int cp = codePoints[r]; + if (cp < 0 || cp > 0x10ffff) { + throw new IllegalArgumentException(); + } + while (true) { + try { + if (cp < 0x010000) { + chars[w] = (char) cp; + w++; + } else { + chars[w] = (char) (LEAD_SURROGATE_OFFSET_ + (cp >> LEAD_SURROGATE_SHIFT_)); + chars[w + 1] = (char) (TRAIL_SURROGATE_MIN_VALUE + (cp & TRAIL_SURROGATE_MASK_)); + w += 2; + } + break; + } catch (IndexOutOfBoundsException ex) { + int newlen = (int) (Math.ceil((double) codePoints.length * (w + 2) + / (r - offset + 1))); + char[] temp = new char[newlen]; + System.arraycopy(chars, 0, temp, 0, w); + chars = temp; + } + } + } + return new String(chars, 0, w); + } } diff --git a/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java b/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java index 551f70b4157..fb598729a3d 100644 --- a/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java +++ b/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java @@ -30,7 +30,6 @@ package org.apache.lucene.util.automaton; import org.apache.lucene.util.ArrayUtil; -import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util.RamUsageEstimator; import java.util.ArrayList; @@ -855,13 +854,7 @@ final public class BasicOperations { // "defined" in UTF32. Don't call this on a transition // that only accepts UTF16 surrogate values!! private static int getRandomCodePoint(final Random r, final Transition t) { - while(true) { - final int v = t.min+r.nextInt(t.max-t.min+1); - if (v < UnicodeUtil.UNI_SUR_HIGH_START || - v > UnicodeUtil.UNI_SUR_LOW_END) { - return v; - } - } + return t.min+r.nextInt(t.max-t.min+1); } public static class RandomAcceptedStrings { diff --git a/lucene/src/test/org/apache/lucene/analysis/TestCharArrayMap.java b/lucene/src/test/org/apache/lucene/analysis/TestCharArrayMap.java index 4ad71f3c486..7765001f3c1 100644 --- a/lucene/src/test/org/apache/lucene/analysis/TestCharArrayMap.java +++ b/lucene/src/test/org/apache/lucene/analysis/TestCharArrayMap.java @@ -19,6 +19,7 @@ package org.apache.lucene.analysis; import java.util.*; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; public class TestCharArrayMap extends LuceneTestCase { Random r = newRandom(); @@ -55,7 +56,7 @@ public class TestCharArrayMap extends LuceneTestCase { } public void testCharArrayMap() { - for (int i=0; i<5; i++) { // pump this up for more random testing + for (int i=0; i<5*_TestUtil.getRandomMultiplier(); i++) { // pump this up for more random testing doRandom(1000,false); doRandom(1000,true); } diff --git a/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java b/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java index 30c867b7a48..26f1737dbeb 100644 --- a/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java +++ b/lucene/src/test/org/apache/lucene/analysis/TestCharTokenizers.java @@ -23,6 +23,7 @@ import java.io.StringReader; import java.util.Random; import org.apache.lucene.util.Version; +import org.apache.lucene.util._TestUtil; /** * Testcase for {@link CharTokenizer} subclasses @@ -38,7 +39,7 @@ public class TestCharTokenizers extends BaseTokenStreamTestCase { Random newRandom = newRandom(); // create random input int num = 1024 + newRandom.nextInt(1024); - for (int i = 1; i < num; i++) { + for (int i = 1; i < num*_TestUtil.getRandomMultiplier(); i++) { builder.append("\ud801\udc1cabc"); if((i % 10) == 0) builder.append(" "); diff --git a/lucene/src/test/org/apache/lucene/index/FlexTestUtil.java b/lucene/src/test/org/apache/lucene/index/FlexTestUtil.java index 46b0a8d8d78..580e0627fa7 100644 --- a/lucene/src/test/org/apache/lucene/index/FlexTestUtil.java +++ b/lucene/src/test/org/apache/lucene/index/FlexTestUtil.java @@ -428,7 +428,7 @@ public class FlexTestUtil { } private static void testRandomSeeks(Random rand, IndexReader r) throws Exception { - final int ITER = 100; + final int ITER = 100 * _TestUtil.getRandomMultiplier(); List allFields = new ArrayList(); Fields fields = MultiFields.getFields(r); if (fields == null) { diff --git a/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java b/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java index 47e5eb3bc05..221ebaa0a6d 100644 --- a/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java +++ b/lucene/src/test/org/apache/lucene/index/TestAtomicUpdate.java @@ -47,7 +47,7 @@ public class TestAtomicUpdate extends LuceneTestCase { private static abstract class TimedThread extends Thread { volatile boolean failed; int count; - private static float RUN_TIME_SEC = 0.5f; + private static float RUN_TIME_SEC = 0.5f * (float)_TestUtil.getRandomMultiplier(); private TimedThread[] allThreads; abstract public void doWork() throws Throwable; diff --git a/lucene/src/test/org/apache/lucene/index/TestByteSlices.java b/lucene/src/test/org/apache/lucene/index/TestByteSlices.java index f28adcde1fc..037bbb102cd 100644 --- a/lucene/src/test/org/apache/lucene/index/TestByteSlices.java +++ b/lucene/src/test/org/apache/lucene/index/TestByteSlices.java @@ -18,6 +18,7 @@ import java.util.Random; import java.util.ArrayList; import java.util.List; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; public class TestByteSlices extends LuceneTestCase { @@ -73,7 +74,7 @@ public class TestByteSlices extends LuceneTestCase { counters[stream] = 0; } - for(int iter=0;iter<10000;iter++) { + for(int iter=0;iter<10000*_TestUtil.getRandomMultiplier();iter++) { int stream = r.nextInt(NUM_STREAM); if (VERBOSE) System.out.println("write stream=" + stream); diff --git a/lucene/src/test/org/apache/lucene/index/TestCodecs.java b/lucene/src/test/org/apache/lucene/index/TestCodecs.java index ec2be6bc5b4..1ef85cd7207 100644 --- a/lucene/src/test/org/apache/lucene/index/TestCodecs.java +++ b/lucene/src/test/org/apache/lucene/index/TestCodecs.java @@ -44,6 +44,7 @@ import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.MultiCodecTestCase; import org.apache.lucene.util.Version; +import org.apache.lucene.util._TestUtil; // TODO: test multiple codecs here? @@ -68,7 +69,7 @@ public class TestCodecs extends MultiCodecTestCase { private Random RANDOM; private static String[] fieldNames = new String[] {"one", "two", "three", "four"}; - private final static int NUM_TEST_ITER = 20; + private final static int NUM_TEST_ITER = 20*_TestUtil.getRandomMultiplier(); private final static int NUM_TEST_THREADS = 3; private final static int NUM_FIELDS = 4; private final static int NUM_TERMS_RAND = 50; // must be > 16 to test skipping diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java index e99cc6639a6..d34555027db 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java @@ -47,6 +47,7 @@ import org.apache.lucene.store.MockRAMDirectory; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.BitVector; +import org.apache.lucene.util._TestUtil; public class TestIndexReaderReopen extends LuceneTestCase { @@ -702,7 +703,7 @@ public class TestIndexReaderReopen extends LuceneTestCase { public void testThreadSafety() throws Exception { final Directory dir = new MockRAMDirectory(); - final int n = 30; + final int n = 30*_TestUtil.getRandomMultiplier(); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig( TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT))); diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java index 8eb9f2ac12a..b501eea94f2 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -3407,7 +3407,7 @@ public class TestIndexWriter extends LuceneTestCase { BytesRef utf8 = new BytesRef(20); UnicodeUtil.UTF16Result utf16 = new UnicodeUtil.UTF16Result(); - for(int iter=0;iter<100000;iter++) { + for(int iter=0;iter<100000*_TestUtil.getRandomMultiplier();iter++) { boolean hasIllegal = fillUnicode(buffer, expected, 0, 20); UnicodeUtil.UTF16toUTF8(buffer, 0, 20, utf8); @@ -3438,7 +3438,7 @@ public class TestIndexWriter extends LuceneTestCase { boolean hasIllegal = false; byte[] last = new byte[60]; - for(int iter=0;iter<100000;iter++) { + for(int iter=0;iter<100000*_TestUtil.getRandomMultiplier();iter++) { final int prefix; @@ -4748,7 +4748,7 @@ public class TestIndexWriter extends LuceneTestCase { Random rnd = newRandom(); final Set allTerms = new HashSet(); - for(int i=0;i<200;i++) { + for(int i=0;i<200*_TestUtil.getRandomMultiplier();i++) { final String s; if (rnd.nextBoolean()) { @@ -4783,7 +4783,6 @@ public class TestIndexWriter extends LuceneTestCase { // Test each sub-segment final IndexReader[] subs = r.getSequentialSubReaders(); - assertEquals(5, subs.length); for(int i=0;i resultMap = new TreeMap(); // store hits in TreeMap - TreeMap does not allow duplicates; existing entries are silently overwritten @@ -163,7 +164,7 @@ implements Serializable { } // now make a query using the sort criteria - ScoreDoc[] resultSort = searcher.search (query, null, 1000, sort).scoreDocs; + ScoreDoc[] resultSort = searcher.search (query, null, Integer.MAX_VALUE, sort).scoreDocs; checkHits(resultSort, "Sort by custom criteria: "); // check for duplicates // besides the sorting both sets of hits must be identical diff --git a/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java b/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java index c4da3296b59..d0dcceb2375 100644 --- a/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java +++ b/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java @@ -30,6 +30,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; public class TestMultiValuedNumericRangeQuery extends LuceneTestCase { @@ -47,7 +48,7 @@ public class TestMultiValuedNumericRangeQuery extends LuceneTestCase { DecimalFormat format = new DecimalFormat("00000000000", new DecimalFormatSymbols(Locale.US)); - for (int l=0; l<5000; l++) { + for (int l=0; l<5000*_TestUtil.getRandomMultiplier(); l++) { Document doc = new Document(); for (int m=0, c=rnd.nextInt(10); m<=c; m++) { int value = rnd.nextInt(Integer.MAX_VALUE); @@ -59,7 +60,7 @@ public class TestMultiValuedNumericRangeQuery extends LuceneTestCase { writer.close(); Searcher searcher=new IndexSearcher(directory, true); - for (int i=0; i<50; i++) { + for (int i=0; i<50*_TestUtil.getRandomMultiplier(); i++) { int lower=rnd.nextInt(Integer.MAX_VALUE); int upper=rnd.nextInt(Integer.MAX_VALUE); if (lower>upper) { diff --git a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java index 20d755bd3b9..2b9cdb13114 100644 --- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java +++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java @@ -24,13 +24,13 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.NumericField; import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriter.MaxFieldLength; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCaseJ4; import org.apache.lucene.util.NumericUtils; +import org.apache.lucene.util._TestUtil; import org.junit.Test; import org.junit.AfterClass; @@ -43,7 +43,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCaseJ4 { // shift the starting of the values to the left, to also have negative values: private static final int startOffset = - 1 << 15; // number of docs to generate for testing - private static final int noDocs = 10000; + private static final int noDocs = 10000*_TestUtil.getRandomMultiplier(); private static RAMDirectory directory = null; private static IndexSearcher searcher = null; @@ -327,7 +327,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCaseJ4 { final Random rnd=newRandom(); String field="field"+precisionStep; int termCountT=0,termCountC=0; - for (int i=0; i<10; i++) { + for (int i=0; i<10*_TestUtil.getRandomMultiplier(); i++) { int lower=(int)(rnd.nextDouble()*noDocs*distance)+startOffset; int upper=(int)(rnd.nextDouble()*noDocs*distance)+startOffset; if (lower>upper) { @@ -405,7 +405,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCaseJ4 { final Random rnd=newRandom(); String field="ascfield"+precisionStep; // 10 random tests - for (int i=0; i<10; i++) { + for (int i=0; i<10*_TestUtil.getRandomMultiplier(); i++) { int lower=(int)(rnd.nextDouble()*noDocs - noDocs/2); int upper=(int)(rnd.nextDouble()*noDocs - noDocs/2); if (lower>upper) { @@ -481,7 +481,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCaseJ4 { String field="field"+precisionStep; // 10 random tests, the index order is ascending, // so using a reverse sort field should retun descending documents - for (int i=0; i<10; i++) { + for (int i=0; i<10*_TestUtil.getRandomMultiplier(); i++) { int lower=(int)(rnd.nextDouble()*noDocs*distance)+startOffset; int upper=(int)(rnd.nextDouble()*noDocs*distance)+startOffset; if (lower>upper) { diff --git a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java index 2fa92b45bde..a6678f62db5 100644 --- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java +++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java @@ -29,6 +29,7 @@ import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCaseJ4; import org.apache.lucene.util.NumericUtils; +import org.apache.lucene.util._TestUtil; import org.junit.Test; import org.junit.AfterClass; @@ -41,7 +42,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCaseJ4 { // shift the starting of the values to the left, to also have negative values: private static final long startOffset = - 1L << 31; // number of docs to generate for testing - private static final int noDocs = 10000; + private static final int noDocs = 10000*_TestUtil.getRandomMultiplier(); private static RAMDirectory directory = null; private static IndexSearcher searcher = null; @@ -345,7 +346,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCaseJ4 { final Random rnd=newRandom(); String field="field"+precisionStep; int termCountT=0,termCountC=0; - for (int i=0; i<10; i++) { + for (int i=0; i<10*_TestUtil.getRandomMultiplier(); i++) { long lower=(long)(rnd.nextDouble()*noDocs*distance)+startOffset; long upper=(long)(rnd.nextDouble()*noDocs*distance)+startOffset; if (lower>upper) { @@ -428,7 +429,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCaseJ4 { final Random rnd=newRandom(); String field="ascfield"+precisionStep; // 10 random tests - for (int i=0; i<10; i++) { + for (int i=0; i<10*_TestUtil.getRandomMultiplier(); i++) { long lower=(long)(rnd.nextDouble()*noDocs - noDocs/2); long upper=(long)(rnd.nextDouble()*noDocs - noDocs/2); if (lower>upper) { @@ -514,7 +515,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCaseJ4 { String field="field"+precisionStep; // 10 random tests, the index order is ascending, // so using a reverse sort field should retun descending documents - for (int i=0; i<10; i++) { + for (int i=0; i<10*_TestUtil.getRandomMultiplier(); i++) { long lower=(long)(rnd.nextDouble()*noDocs*distance)+startOffset; long upper=(long)(rnd.nextDouble()*noDocs*distance)+startOffset; if (lower>upper) { diff --git a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java index b1b1fa58f57..3f048e96c9f 100644 --- a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java +++ b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java @@ -28,6 +28,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; /** * Create an index with terms from 0000-9999. @@ -91,7 +92,7 @@ public class TestRegexpRandom extends LuceneTestCase { public void testRegexps() throws Exception { random = newRandom(System.nanoTime()); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 100*_TestUtil.getRandomMultiplier(); i++) { assertPatternHits("NNNN", 1); assertPatternHits(".NNN", 10); assertPatternHits("N.NN", 10); @@ -99,7 +100,7 @@ public class TestRegexpRandom extends LuceneTestCase { assertPatternHits("NNN.", 10); } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10*_TestUtil.getRandomMultiplier(); i++) { assertPatternHits(".{1,2}NN", 100); assertPatternHits("N.{1,2}N", 100); assertPatternHits("NN.{1,2}", 100); diff --git a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java index 2eddc468024..fcb4d2a771b 100644 --- a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java +++ b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java @@ -57,7 +57,7 @@ public class TestRegexpRandom2 extends LuceneTestCase { Field field = new Field("field", "", Field.Store.NO, Field.Index.ANALYZED); doc.add(field); - for (int i = 0; i < 2000; i++) { + for (int i = 0; i < 2000*_TestUtil.getRandomMultiplier(); i++) { field.setValue(_TestUtil.randomUnicodeString(random)); writer.addDocument(doc); } @@ -113,7 +113,7 @@ public class TestRegexpRandom2 extends LuceneTestCase { /** test a bunch of random regular expressions */ public void testRegexps() throws Exception { - for (int i = 0; i < 1000; i++) + for (int i = 0; i < 1000*_TestUtil.getRandomMultiplier(); i++) assertSame(AutomatonTestUtil.randomRegexp(random).toString()); } diff --git a/lucene/src/test/org/apache/lucene/search/TestScorerPerf.java b/lucene/src/test/org/apache/lucene/search/TestScorerPerf.java index dfbf8647368..f333878d43a 100755 --- a/lucene/src/test/org/apache/lucene/search/TestScorerPerf.java +++ b/lucene/src/test/org/apache/lucene/search/TestScorerPerf.java @@ -2,6 +2,8 @@ package org.apache.lucene.search; import org.apache.lucene.util.DocIdBitSet; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; + import java.util.Random; import java.util.BitSet; import java.io.IOException; @@ -317,9 +319,9 @@ public class TestScorerPerf extends LuceneTestCase { r = newRandom(); createDummySearcher(); validate=true; - sets=randBitSets(1000,10); - doConjunctions(10000,5); - doNestedConjunctions(10000,3,3); + sets=randBitSets(1000*_TestUtil.getRandomMultiplier(),10*_TestUtil.getRandomMultiplier()); + doConjunctions(10000*_TestUtil.getRandomMultiplier(),5*_TestUtil.getRandomMultiplier()); + doNestedConjunctions(10000*_TestUtil.getRandomMultiplier(),3*_TestUtil.getRandomMultiplier(),3*_TestUtil.getRandomMultiplier()); s.close(); } diff --git a/lucene/src/test/org/apache/lucene/search/TestSort.java b/lucene/src/test/org/apache/lucene/search/TestSort.java index b39b7829999..3dedff07f0f 100644 --- a/lucene/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/src/test/org/apache/lucene/search/TestSort.java @@ -45,6 +45,7 @@ import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.DocIdBitSet; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; /** * Unit tests for sorting code. @@ -56,7 +57,7 @@ import org.apache.lucene.util.LuceneTestCase; public class TestSort extends LuceneTestCase implements Serializable { - private static final int NUM_STRINGS = 6000; + private static final int NUM_STRINGS = 6000*_TestUtil.getRandomMultiplier(); private Searcher full; private Searcher searchX; private Searcher searchY; diff --git a/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java b/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java index 37c9241ba5e..e91562a58df 100755 --- a/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java +++ b/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java @@ -17,6 +17,7 @@ package org.apache.lucene.search; */ import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.index.IndexReader; @@ -147,7 +148,7 @@ public class TestThreadSafe extends LuceneTestCase { buildDir(dir1, 15, 5, 2000); // do many small tests so the thread locals go away inbetween - for (int i=0; i<100; i++) { + for (int i=0; i<100*_TestUtil.getRandomMultiplier(); i++) { ir1 = IndexReader.open(dir1, false); doTest(10,100); } diff --git a/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java b/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java index 1262dd04c5f..f61d6ff1942 100644 --- a/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java +++ b/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java @@ -28,6 +28,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; /** * Create an index with terms from 0000-9999. @@ -92,7 +93,7 @@ public class TestWildcardRandom extends LuceneTestCase { public void testWildcards() throws Exception { random = newRandom(System.nanoTime()); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 100*_TestUtil.getRandomMultiplier(); i++) { assertPatternHits("NNNN", 1); assertPatternHits("?NNN", 10); assertPatternHits("N?NN", 10); @@ -100,7 +101,7 @@ public class TestWildcardRandom extends LuceneTestCase { assertPatternHits("NNN?", 10); } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10*_TestUtil.getRandomMultiplier(); i++) { assertPatternHits("??NN", 100); assertPatternHits("N??N", 100); assertPatternHits("NN??", 100); diff --git a/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java b/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java index 8a9bd1559c0..9dd0ca26b1e 100644 --- a/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java +++ b/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java @@ -22,6 +22,7 @@ import java.util.Random; import java.io.File; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; @@ -83,7 +84,7 @@ public class TestWindowsMMap extends LuceneTestCase { writer.commit(); IndexSearcher searcher = new IndexSearcher(dir, true); - for(int dx = 0; dx < 1000; dx ++) { + for(int dx = 0; dx < 1000*_TestUtil.getRandomMultiplier(); dx ++) { String f = randomField(); Document doc = new Document(); doc.add(new Field("data", f, Field.Store.YES, Field.Index.ANALYZED)); diff --git a/lucene/src/test/org/apache/lucene/util/TestArrayUtil.java b/lucene/src/test/org/apache/lucene/util/TestArrayUtil.java index b34c6b93f4d..c2fa8fb1d21 100644 --- a/lucene/src/test/org/apache/lucene/util/TestArrayUtil.java +++ b/lucene/src/test/org/apache/lucene/util/TestArrayUtil.java @@ -49,7 +49,7 @@ public class TestArrayUtil extends LuceneTestCase { public void testInvalidElementSizes() { final Random r = newRandom(); - for(int iter=0;iter<10000;iter++) { + for(int iter=0;iter<10000*_TestUtil.getRandomMultiplier();iter++) { final int minTargetSize = r.nextInt(Integer.MAX_VALUE); final int elemSize = r.nextInt(11); final int v = ArrayUtil.oversize(minTargetSize, elemSize); diff --git a/lucene/src/test/org/apache/lucene/util/TestDoubleBarrelLRUCache.java b/lucene/src/test/org/apache/lucene/util/TestDoubleBarrelLRUCache.java index 233d176f6a5..03a935a6fef 100644 --- a/lucene/src/test/org/apache/lucene/util/TestDoubleBarrelLRUCache.java +++ b/lucene/src/test/org/apache/lucene/util/TestDoubleBarrelLRUCache.java @@ -17,57 +17,58 @@ package org.apache.lucene.util; * limitations under the License. */ +import org.apache.lucene.util.LuceneTestCase; public class TestDoubleBarrelLRUCache extends LuceneTestCase { - private void testCache(DoubleBarrelLRUCache cache, int n) throws Exception { + private void testCache(DoubleBarrelLRUCache cache, int n) throws Exception { Object dummy = new Object(); for (int i = 0; i < n; i++) { - cache.put(Integer.valueOf(i), dummy); + cache.put(new CloneableInteger(i), dummy); } // access every 2nd item in cache for (int i = 0; i < n; i+=2) { - assertNotNull(cache.get(Integer.valueOf(i))); + assertNotNull(cache.get(new CloneableInteger(i))); } // add n/2 elements to cache, the ones that weren't // touched in the previous loop should now be thrown away for (int i = n; i < n + (n / 2); i++) { - cache.put(Integer.valueOf(i), dummy); + cache.put(new CloneableInteger(i), dummy); } // access every 4th item in cache for (int i = 0; i < n; i+=4) { - assertNotNull(cache.get(Integer.valueOf(i))); + assertNotNull(cache.get(new CloneableInteger(i))); } // add 3/4n elements to cache, the ones that weren't // touched in the previous loops should now be thrown away for (int i = n; i < n + (n * 3 / 4); i++) { - cache.put(Integer.valueOf(i), dummy); + cache.put(new CloneableInteger(i), dummy); } // access every 4th item in cache for (int i = 0; i < n; i+=4) { - assertNotNull(cache.get(Integer.valueOf(i))); + assertNotNull(cache.get(new CloneableInteger(i))); } } public void testLRUCache() throws Exception { final int n = 100; - testCache(new DoubleBarrelLRUCache(n), n); + testCache(new DoubleBarrelLRUCache(n), n); } private class CacheThread extends Thread { - private final Object[] objs; - private final DoubleBarrelLRUCache c; + private final CloneableObject[] objs; + private final DoubleBarrelLRUCache c; private final long endTime; volatile boolean failed; - public CacheThread(DoubleBarrelLRUCache c, - Object[] objs, long endTime) { + public CacheThread(DoubleBarrelLRUCache c, + CloneableObject[] objs, long endTime) { this.c = c; this.objs = objs; this.endTime = endTime; @@ -82,10 +83,10 @@ public class TestDoubleBarrelLRUCache extends LuceneTestCase { final int limit = objs.length; while(true) { - final Object obj = objs[(int) ((count/2) % limit)]; + final CloneableObject obj = objs[(int) ((count/2) % limit)]; Object v = c.get(obj); if (v == null) { - c.put(obj, obj); + c.put(new CloneableObject(obj), obj); miss++; } else { assert obj == v; @@ -117,11 +118,11 @@ public class TestDoubleBarrelLRUCache extends LuceneTestCase { final int CACHE_SIZE = 512; final int OBJ_COUNT = 3*CACHE_SIZE; - DoubleBarrelLRUCache c = new DoubleBarrelLRUCache(1024); + DoubleBarrelLRUCache c = new DoubleBarrelLRUCache(1024); - Object[] objs = new Object[OBJ_COUNT]; + CloneableObject[] objs = new CloneableObject[OBJ_COUNT]; for(int i=0;i terms = new ArrayList(); private Random random; - @Override - protected void setUp() throws Exception { - super.setUp(); - random = newRandom(); - for (int i = 0; i < 5000; i++) { - String randomString = _TestUtil.randomUnicodeString(random); - terms.add(randomString); - automata.add(BasicAutomata.makeString(randomString)); - } - } - public void testLexicon() { - for (int i = 0; i < 3; i++) { + random = newRandom(); + for (int i = 0; i < 3*_TestUtil.getRandomMultiplier(); i++) { + automata.clear(); + terms.clear(); + for (int j = 0; j < 5000; j++) { + String randomString = _TestUtil.randomUnicodeString(random); + terms.add(randomString); + automata.add(BasicAutomata.makeString(randomString)); + } assertLexicon(); } } diff --git a/lucene/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java b/lucene/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java index 4476fe8bd8a..6343410df9e 100644 --- a/lucene/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java +++ b/lucene/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java @@ -99,8 +99,8 @@ public class TestUTF32ToUTF8 extends LuceneTestCase { public void testRandomRanges() throws Exception { final Random r = random; - int ITERS = 10; - int ITERS_PER_DFA = 100; + int ITERS = 10*_TestUtil.getRandomMultiplier(); + int ITERS_PER_DFA = 100*_TestUtil.getRandomMultiplier(); for(int iter=0;iter