From 0166171566d70e776b872f312cc6a9b4fce937da Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 1 Apr 2016 13:28:11 -0400 Subject: [PATCH] LUCENE-7162: set SerialMergeScheduler in all spatial tests. We can test thread safety of e.g. BKD structures elsewhere in a simpler way. It is important for geo tests to be simpler and easier to reproduce and debug. --- .../document/TestLatLonPointDistanceSort.java | 7 ++++- .../spatial/util/BaseGeoPointTestCase.java | 29 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java index 43d3a269b20..ac402b6b6f2 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java +++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonPointDistanceSort.java @@ -20,7 +20,9 @@ import java.io.IOException; import java.util.Arrays; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.SerialMergeScheduler; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; @@ -176,7 +178,10 @@ public class TestLatLonPointDistanceSort extends LuceneTestCase { private void doRandomTest(int numDocs, int numQueries) throws IOException { Directory dir = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random(), dir); + IndexWriterConfig iwc = newIndexWriterConfig(); + // else seeds may not to reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); + RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc); for (int i = 0; i < numDocs; i++) { Document doc = new Document(); diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java index da69b2452af..93b0b1cf8c8 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/util/BaseGeoPointTestCase.java @@ -49,6 +49,7 @@ import org.apache.lucene.index.NumericDocValues; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.SegmentWriteState; +import org.apache.lucene.index.SerialMergeScheduler; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; @@ -498,10 +499,11 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { double[] lons = new double[2*numPoints]; Directory dir = newDirectory(); IndexWriterConfig iwc = newIndexWriterConfig(); - initIndexWriterConfig(FIELD_NAME, iwc); // We rely on docID order: iwc.setMergePolicy(newLogMergePolicy()); + // and on seeds being able to reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc); boolean small = random().nextBoolean(); @@ -724,9 +726,6 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { } } - protected void initIndexWriterConfig(String field, IndexWriterConfig iwc) { - } - protected abstract void addPointToDoc(String field, Document doc, double lat, double lon); protected abstract Query newRectQuery(String field, double minLat, double maxLat, double minLon, double maxLon); @@ -767,6 +766,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { protected void verifyRandomRectangles(boolean small, double[] lats, double[] lons) throws Exception { IndexWriterConfig iwc = newIndexWriterConfig(); + // Else seeds may not reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); // Else we can get O(N^2) merging: int mbd = iwc.getMaxBufferedDocs(); if (mbd != -1 && mbd < lats.length/100) { @@ -873,6 +874,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { } else { b.append("FAIL: id=" + id + " should not match but did\n"); } + b.append(" box=" + rect + "\n"); b.append(" query=" + query + " docID=" + docID + "\n"); b.append(" lat=" + lats[id] + " lon=" + lons[id] + "\n"); b.append(" deleted?=" + (liveDocs != null && liveDocs.get(docID) == false)); @@ -894,6 +896,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { protected void verifyRandomDistances(boolean small, double[] lats, double[] lons) throws Exception { IndexWriterConfig iwc = newIndexWriterConfig(); + // Else seeds may not reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); // Else we can get O(N^2) merging: int mbd = iwc.getMaxBufferedDocs(); if (mbd != -1 && mbd < lats.length/100) { @@ -1039,6 +1043,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { protected void verifyRandomPolygons(boolean small, double[] lats, double[] lons) throws Exception { IndexWriterConfig iwc = newIndexWriterConfig(); + // Else seeds may not reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); // Else we can get O(N^2) merging: int mbd = iwc.getMaxBufferedDocs(); if (mbd != -1 && mbd < lats.length/100) { @@ -1181,6 +1187,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { } Directory dir = newDirectory(); IndexWriterConfig iwc = newIndexWriterConfig(); + // Else seeds may not reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc); for(int x=0;x<3;x++) { double lat; @@ -1235,6 +1243,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { private void doRandomDistanceTest(int numDocs, int numQueries) throws IOException { Directory dir = newDirectory(); IndexWriterConfig iwc = newIndexWriterConfig(); + // Else seeds may not reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); int pointsInLeaf = 2 + random().nextInt(4); iwc.setCodec(new FilterCodec("Lucene60", TestUtil.getDefaultCodec()) { @Override @@ -1367,10 +1377,13 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase { Directory directory = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random(), directory, - newIndexWriterConfig(new MockAnalyzer(random())) - .setMaxBufferedDocs(TestUtil.nextInt(random(), 100, 1000)) - .setMergePolicy(newLogMergePolicy())); + // TODO: must these simple tests really rely on docid order? + IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())); + iwc.setMaxBufferedDocs(TestUtil.nextInt(random(), 100, 1000)); + iwc.setMergePolicy(newLogMergePolicy()); + // Else seeds may not reproduce: + iwc.setMergeScheduler(new SerialMergeScheduler()); + RandomIndexWriter writer = new RandomIndexWriter(random(), directory, iwc); for (double p[] : pts) { Document doc = new Document();