Skip to content

Apache Lucene open-source search software

LUCENE-5608: small test improvements. Rename SpatialOpRecursivePrefixTreeTest to RandomSpatialOpFuzzyPrefixTreeTest.

David Wayne Smileybd727b49ab1a
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
index 3198e1b8d18..9eed5124324 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
@@ -91,8 +91,10 @@ public class QueryEqualsHashCodeTest extends LuceneTestCase {
Object second = generator.gen(args1);//should be the same
assertEquals(first, second);
assertEquals(first.hashCode(), second.hashCode());
- second = generator.gen(args2);//now should be different
assertNotSame(args1, args2);
+ second = generator.gen(args2);//now should be different
+ assertNotSame(first, second);
+ assertNotSame(first.hashCode(), second.hashCode());
}
private SpatialArgs makeArgs1() {
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
index 37308d4a11e..32e4b1eeaaf 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
@@ -36,9 +36,8 @@ import org.apache.lucene.uninverting.UninvertingReader;
import org.apache.lucene.uninverting.UninvertingReader.Type;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
-import org.apache.lucene.util.TestRuleLimitSysouts.Limit;
+import org.apache.lucene.util.TestUtil;
import org.junit.After;
import org.junit.Before;
@@ -63,7 +62,7 @@ public abstract class SpatialTestCase extends LuceneTestCase {
protected SpatialContext ctx;//subclass must initialize
- Map<String,Type> uninvertMap = new HashMap<>();
+ protected Map<String,Type> uninvertMap = new HashMap<>();
@Override
@Before
@@ -77,8 +76,7 @@ public abstract class SpatialTestCase extends LuceneTestCase {
uninvertMap.put("bbox__maxY", Type.DOUBLE);
uninvertMap.put("pointvector__x", Type.DOUBLE);
uninvertMap.put("pointvector__y", Type.DOUBLE);
- uninvertMap.put("SpatialOpRecursivePrefixTreeTest", Type.SORTED);
-
+
directory = newDirectory();
final Random random = random();
indexWriter = new RandomIndexWriter(random,directory, newIndexWriterConfig(random));
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
index 6d1129066e6..61a45b484e9 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
@@ -45,7 +45,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
@@ -224,6 +223,7 @@ public abstract class StrategyTestCase extends SpatialTestCase {
// }
// CheckHits.checkHits(random(), q, "", indexSearcher, expectedDocs);
+ //TopDocs is sorted but we actually don't care about the order
TopDocs docs = indexSearcher.search(q, 1000);//calculates the score
for (int i = 0; i < docs.scoreDocs.length; i++) {
ScoreDoc gotSD = docs.scoreDocs[i];
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
index 32b40501a7c..7b96f517706 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
@@ -29,7 +29,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Calendar;
-public class DateNRStrategyTest extends BaseNonFuzzySpatialOpStrategyTest {
+public class DateNRStrategyTest extends RandomSpatialOpStrategyTestCase {
static final int ITERATIONS = 10;
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java
similarity index 97%
rename from lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java
rename to lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java
index 198a7cd3c3f..e760bda17f6 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java
@@ -39,6 +39,7 @@ import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
+import org.apache.lucene.uninverting.UninvertingReader;
import org.junit.Before;
import org.junit.Test;
@@ -62,13 +63,23 @@ import static com.spatial4j.core.shape.SpatialRelation.DISJOINT;
import static com.spatial4j.core.shape.SpatialRelation.INTERSECTS;
import static com.spatial4j.core.shape.SpatialRelation.WITHIN;
-public class SpatialOpRecursivePrefixTreeTest extends StrategyTestCase {
+/** Randomized PrefixTree test that considers the fuzziness of the
+ * results introduced by grid approximation. */
+public class RandomSpatialOpFuzzyPrefixTreeTest extends StrategyTestCase {
static final int ITERATIONS = 10;
private SpatialPrefixTree grid;
private SpatialContext ctx2D;
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ //Only for Disjoint. Ugh; need to find a better way. LUCENE-5692
+ uninvertMap.put(getClass().getSimpleName(), UninvertingReader.Type.SORTED);
+ }
+
public void setupGrid(int maxLevels) throws IOException {
if (randomBoolean())
setupQuadGrid(maxLevels);
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java
similarity index 91%
rename from lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java
rename to lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java
index 82ad0865f13..057339a9e04 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java
@@ -22,7 +22,6 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.spatial.StrategyTestCase;
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
-import org.junit.Ignore;
import java.io.IOException;
import java.util.ArrayList;
@@ -36,10 +35,9 @@ import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween
/** Base test harness, ideally for SpatialStrategy impls that have exact results
* (not grid approximated), hence "not fuzzy".
*/
-@Ignore("not actually a test: can this be renamed to *TestCase????")
-public abstract class BaseNonFuzzySpatialOpStrategyTest extends StrategyTestCase {
+public abstract class RandomSpatialOpStrategyTestCase extends StrategyTestCase {
- //TODO this is partially redundant with StrategyTestCase.runTestQuery & testOperation
+ //Note: this is partially redundant with StrategyTestCase.runTestQuery & testOperation
protected void testOperationRandomShapes(final SpatialOperation operation) throws IOException {
//first show that when there's no data, a query will result in no results
@@ -114,18 +112,19 @@ public abstract class BaseNonFuzzySpatialOpStrategyTest extends StrategyTestCase
for (SearchResult result : got.results) {
String id = result.getId();
if (!remainingExpectedIds.remove(id)) {
- fail("Shouldn't match", id, indexedShapes, queryShape);
+ fail("Shouldn't match", id, indexedShapes, queryShape, operation);
}
}
if (!remainingExpectedIds.isEmpty()) {
String id = remainingExpectedIds.iterator().next();
- fail("Should have matched", id, indexedShapes, queryShape);
+ fail("Should have matched", id, indexedShapes, queryShape, operation);
}
}
}
- private void fail(String label, String id, List<Shape> indexedShapes, Shape queryShape) {
- fail(label + " I#" + id + ":" + indexedShapes.get(Integer.parseInt(id)) + " Q:" + queryShape);
+ private void fail(String label, String id, List<Shape> indexedShapes, Shape queryShape, SpatialOperation operation) {
+ fail("[" + operation + "] " + label
+ + " I#" + id + ":" + indexedShapes.get(Integer.parseInt(id)) + " Q:" + queryShape);
}
protected void preQueryHavoc() {