collation tests: try to find less jre bugs and just test thread safety

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1098532 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-05-02 12:03:14 +00:00
parent 0b5ba4404c
commit a75e5282c7
3 changed files with 4 additions and 25 deletions

View File

@ -258,27 +258,6 @@ public abstract class CollationTestBase extends LuceneTestCase {
assertEquals(expectedResult, buff.toString()); assertEquals(expectedResult, buff.toString());
} }
private String randomString() {
// ideally we could do this!
// return _TestUtil.randomUnicodeString(random);
//
// http://bugs.icu-project.org/trac/ticket/8060
// http://bugs.icu-project.org/trac/ticket/7732
// ...
//
// as a workaround, just test the BMP for now (and avoid 0xFFFF etc)
int length = _TestUtil.nextInt(random, 0, 10);
char chars[] = new char[length];
for (int i = 0; i < length; i++) {
if (random.nextBoolean()) {
chars[i] = (char) _TestUtil.nextInt(random, 0, 0xD7FF);
} else {
chars[i] = (char) _TestUtil.nextInt(random, 0xE000, 0xFFFD);
}
}
return new String(chars, 0, length);
}
public void assertThreadSafe(final Analyzer analyzer) throws Exception { public void assertThreadSafe(final Analyzer analyzer) throws Exception {
int numTestPoints = 100; int numTestPoints = 100;
int numThreads = _TestUtil.nextInt(random, 3, 5); int numThreads = _TestUtil.nextInt(random, 3, 5);
@ -289,7 +268,7 @@ public abstract class CollationTestBase extends LuceneTestCase {
// and ensure they are the same as the ones we produced in serial fashion. // and ensure they are the same as the ones we produced in serial fashion.
for (int i = 0; i < numTestPoints; i++) { for (int i = 0; i < numTestPoints; i++) {
String term = randomString(); String term = _TestUtil.randomSimpleString(random);
TokenStream ts = analyzer.reusableTokenStream("fake", new StringReader(term)); TokenStream ts = analyzer.reusableTokenStream("fake", new StringReader(term));
TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class); TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
BytesRef bytes = termAtt.getBytesRef(); BytesRef bytes = termAtt.getBytesRef();

View File

@ -87,8 +87,7 @@ public class TestCollationKeyAnalyzer extends CollationTestBase {
public void testThreadSafe() throws Exception { public void testThreadSafe() throws Exception {
int iters = 20 * RANDOM_MULTIPLIER; int iters = 20 * RANDOM_MULTIPLIER;
for (int i = 0; i < iters; i++) { for (int i = 0; i < iters; i++) {
Locale locale = randomLocale(random); Collator collator = Collator.getInstance(Locale.GERMAN);
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.PRIMARY); collator.setStrength(Collator.PRIMARY);
assertThreadSafe(new CollationKeyAnalyzer(TEST_VERSION_CURRENT, collator)); assertThreadSafe(new CollationKeyAnalyzer(TEST_VERSION_CURRENT, collator));
} }

View File

@ -19,6 +19,7 @@ package org.apache.lucene.collation;
import com.ibm.icu.text.Collator; import com.ibm.icu.text.Collator;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
@ -88,7 +89,7 @@ public class TestICUCollationKeyAnalyzer extends CollationTestBase {
public void testThreadSafe() throws Exception { public void testThreadSafe() throws Exception {
int iters = 20 * RANDOM_MULTIPLIER; int iters = 20 * RANDOM_MULTIPLIER;
for (int i = 0; i < iters; i++) { for (int i = 0; i < iters; i++) {
Locale locale = randomLocale(random); Locale locale = Locale.GERMAN;
Collator collator = Collator.getInstance(locale); Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.IDENTICAL); collator.setStrength(Collator.IDENTICAL);
assertThreadSafe(new ICUCollationKeyAnalyzer(TEST_VERSION_CURRENT, collator)); assertThreadSafe(new ICUCollationKeyAnalyzer(TEST_VERSION_CURRENT, collator));