You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2015/01/29 14:47:11 UTC
svn commit: r1655659 - in /lucene/dev/trunk: ./ lucene/ lucene/analysis/
lucene/analysis/common/
lucene/analysis/common/src/test/org/apache/lucene/collation/
lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/util/
Author: rmuir
Date: Thu Jan 29 13:47:10 2015
New Revision: 1655659
URL: http://svn.apache.org/r1655659
Log:
LUCENE-6206: don't fail test if it encounters jdk bug
Modified:
lucene/dev/trunk/ (props changed)
lucene/dev/trunk/lucene/ (props changed)
lucene/dev/trunk/lucene/analysis/ (props changed)
lucene/dev/trunk/lucene/analysis/common/ (props changed)
lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java
lucene/dev/trunk/lucene/test-framework/ (props changed)
lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
Modified: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java?rev=1655659&r1=1655658&r2=1655659&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java (original)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java Thu Jan 29 13:47:10 2015
@@ -104,17 +104,20 @@ public class TestCollationDocValuesField
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
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
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);
}
}
}
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=1655659&r1=1655658&r2=1655659&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/util/LuceneTestCase.java Thu Jan 29 13:47:10 2015
@@ -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 ext
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;
+ }
}