Apache Solr open-source search software
LUCENE-5408: fixed tests; some strategies require DocValues
David Wayne Smileye75fd19a7d6a
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.javaindex be214c1e99a..30bad06b5f9 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/DistanceStrategyTest.java@@ -90,6 +90,11 @@ public class DistanceStrategyTest extends StrategyTestCase {this.strategy = strategy;}+ @Override+ protected boolean needsDocValues() {+ return (strategy instanceof SerializedDVStrategy);+ }+@Testpublic void testDistanceOrder() throws IOException {adoc("100", ctx.makePoint(2, 1));diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.javaindex 896cdfd76b2..f1b7f8f625f 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java@@ -20,8 +20,11 @@ package org.apache.lucene.spatial;import com.spatial4j.core.context.SpatialContext;import com.spatial4j.core.shape.Point;import com.spatial4j.core.shape.Rectangle;+import org.apache.lucene.analysis.MockAnalyzer;+import org.apache.lucene.codecs.lucene45.Lucene45DocValuesFormat;import org.apache.lucene.document.Document;import org.apache.lucene.index.DirectoryReader;+import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.StoredDocument;import org.apache.lucene.search.IndexSearcher;@@ -31,12 +34,14 @@ import org.apache.lucene.search.TopDocs;import org.apache.lucene.store.Directory;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;+import org.apache.lucene.util._TestUtil;import org.junit.After;import org.junit.Before;import java.io.IOException;import java.util.ArrayList;import java.util.List;+import java.util.Random;import static com.carrotsearch.randomizedtesting.RandomizedTest.randomGaussian;import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;@@ -57,11 +62,24 @@ public abstract class SpatialTestCase extends LuceneTestCase {super.setUp();directory = newDirectory();- indexWriter = new RandomIndexWriter(random(),directory);+ final Random random = random();+ indexWriter = new RandomIndexWriter(random,directory, newIndexWriterConfig(random));indexReader = indexWriter.getReader();indexSearcher = newSearcher(indexReader);}+ protected IndexWriterConfig newIndexWriterConfig(Random random) {+ final IndexWriterConfig indexWriterConfig = LuceneTestCase.newIndexWriterConfig(random, LuceneTestCase.TEST_VERSION_CURRENT, new MockAnalyzer(random));+ //TODO can we randomly choose a doc-values supported format?+ if (needsDocValues())+ indexWriterConfig.setCodec( _TestUtil.alwaysDocValuesFormat(new Lucene45DocValuesFormat()));;+ return indexWriterConfig;+ }++ protected boolean needsDocValues() {+ return false;+ }+@Override@Afterpublic void tearDown() throws Exception {diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/serialized/SerializedStrategyTest.java b/lucene/spatial/src/test/org/apache/lucene/spatial/serialized/SerializedStrategyTest.javaindex 62769f0148b..7ad5f2f68ef 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/serialized/SerializedStrategyTest.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/serialized/SerializedStrategyTest.java@@ -18,15 +18,12 @@ package org.apache.lucene.spatial.serialized;*/import com.spatial4j.core.context.SpatialContext;-import com.spatial4j.core.shape.Shape;import org.apache.lucene.search.FilteredQuery;import org.apache.lucene.search.MatchAllDocsQuery;import org.apache.lucene.search.Query;-import org.apache.lucene.search.QueryWrapperFilter;import org.apache.lucene.spatial.SpatialMatchConcern;import org.apache.lucene.spatial.SpatialTestQuery;import org.apache.lucene.spatial.StrategyTestCase;-import org.apache.lucene.spatial.bbox.BBoxStrategy;import org.junit.Before;import org.junit.Test;@@ -42,6 +39,11 @@ public class SerializedStrategyTest extends StrategyTestCase {this.strategy = new SerializedDVStrategy(ctx, "serialized");}+ @Override+ protected boolean needsDocValues() {+ return (strategy instanceof SerializedDVStrategy);+ }+//called by StrategyTestCase; we can't let it call our makeQuery which will UOE ex.@Overrideprotected Query makeQuery(SpatialTestQuery q) {