mirror of https://github.com/apache/lucene.git
LUCENE-6206: don't fail test if it encounters jdk bug
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1655659 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7121dbc494
commit
5a8b3c26e0
|
@ -104,17 +104,20 @@ public class TestCollationDocValuesField extends LuceneTestCase {
|
|||
IndexSearcher is = newSearcher(ir);
|
||||
|
||||
int numChecks = atLeast(100);
|
||||
for (int i = 0; i < numChecks; i++) {
|
||||
String start = TestUtil.randomSimpleString(random());
|
||||
String end = TestUtil.randomSimpleString(random());
|
||||
BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
|
||||
BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
|
||||
Query query = new ConstantScoreQuery(DocValuesRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
|
||||
doTestRanges(is, start, end, query, collator);
|
||||
}
|
||||
|
||||
ir.close();
|
||||
dir.close();
|
||||
try {
|
||||
for (int i = 0; i < numChecks; i++) {
|
||||
String start = TestUtil.randomSimpleString(random());
|
||||
String end = TestUtil.randomSimpleString(random());
|
||||
BytesRef lowerVal = new BytesRef(collator.getCollationKey(start).toByteArray());
|
||||
BytesRef upperVal = new BytesRef(collator.getCollationKey(end).toByteArray());
|
||||
Query query = new ConstantScoreQuery(DocValuesRangeFilter.newBytesRefRange("collated", lowerVal, upperVal, true, true));
|
||||
doTestRanges(is, start, end, query, collator);
|
||||
}
|
||||
} finally {
|
||||
ir.close();
|
||||
dir.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestRanges(IndexSearcher is, String startPoint, String endPoint, Query query, Collator collator) throws Exception {
|
||||
|
@ -124,8 +127,8 @@ public class TestCollationDocValuesField extends LuceneTestCase {
|
|||
TopDocs docs = is.search(query, is.getIndexReader().maxDoc());
|
||||
for (ScoreDoc doc : docs.scoreDocs) {
|
||||
String value = is.doc(doc.doc).get("field");
|
||||
assertTrue(collator.compare(value, startPoint) >= 0);
|
||||
assertTrue(collator.compare(value, endPoint) <= 0);
|
||||
assertTrue(collate(collator, value, startPoint) >= 0);
|
||||
assertTrue(collate(collator, value, endPoint) <= 0);
|
||||
}
|
||||
|
||||
// negative test
|
||||
|
@ -135,7 +138,7 @@ public class TestCollationDocValuesField extends LuceneTestCase {
|
|||
docs = is.search(bq, is.getIndexReader().maxDoc());
|
||||
for (ScoreDoc doc : docs.scoreDocs) {
|
||||
String value = is.doc(doc.doc).get("field");
|
||||
assertTrue(collator.compare(value, startPoint) < 0 || collator.compare(value, endPoint) > 0);
|
||||
assertTrue(collate(collator, value, startPoint) < 0 || collate(collator, value, endPoint) > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.lang.reflect.Method;
|
|||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -143,6 +144,7 @@ import org.junit.Test;
|
|||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.JUnit4MethodProvider;
|
||||
import com.carrotsearch.randomizedtesting.LifecycleScope;
|
||||
import com.carrotsearch.randomizedtesting.MixWithSuiteName;
|
||||
|
@ -2544,4 +2546,17 @@ public abstract class LuceneTestCase extends Assert {
|
|||
assert enabled = true; // Intentional side-effect!!!
|
||||
assertsAreEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two strings with a collator, also looking to see if the the strings
|
||||
* are impacted by jdk bugs. may not avoid all jdk bugs in tests.
|
||||
* see LUCENE-2606
|
||||
*/
|
||||
public static int collate(Collator collator, String s1, String s2) {
|
||||
int v1 = collator.compare(s1, s2);
|
||||
int v2 = collator.getCollationKey(s1).compareTo(collator.getCollationKey(s2));
|
||||
// if collation keys don't really respect collation order, things are screwed.
|
||||
assumeTrue("hit JDK collator bug", v1 == v2);
|
||||
return v1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue