LUCENE-6477: allow boundary tolerance for poly query verify; fail test fast if one thread fails

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1683448 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-06-04 00:28:52 +00:00
parent 8b50bea848
commit e4e41cfd8b
1 changed files with 24 additions and 10 deletions

View File

@ -17,14 +17,6 @@ package org.apache.lucene.bkdtree;
* limitations under the License. * limitations under the License.
*/ */
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.DocValuesFormat; import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.lucene50.Lucene50Codec; import org.apache.lucene.codecs.lucene50.Lucene50Codec;
@ -51,6 +43,15 @@ import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
// TODO: can test framework assert we don't leak temp files? // TODO: can test framework assert we don't leak temp files?
public class TestBKDTree extends LuceneTestCase { public class TestBKDTree extends LuceneTestCase {
@ -353,6 +354,8 @@ public class TestBKDTree extends LuceneTestCase {
verify(lats, lons); verify(lats, lons);
} }
private static final double TOLERANCE = 1e-7;
private static void verify(double[] lats, double[] lons) throws Exception { private static void verify(double[] lats, double[] lons) throws Exception {
int maxPointsInLeaf = TestUtil.nextInt(random(), 16, 2048); int maxPointsInLeaf = TestUtil.nextInt(random(), 16, 2048);
int maxPointsSortInHeap = TestUtil.nextInt(random(), maxPointsInLeaf, 1024*1024); int maxPointsSortInHeap = TestUtil.nextInt(random(), maxPointsInLeaf, 1024*1024);
@ -415,6 +418,7 @@ public class TestBKDTree extends LuceneTestCase {
final int iters = atLeast(100); final int iters = atLeast(100);
final CountDownLatch startingGun = new CountDownLatch(1); final CountDownLatch startingGun = new CountDownLatch(1);
final AtomicBoolean failed = new AtomicBoolean();
for(int i=0;i<numThreads;i++) { for(int i=0;i<numThreads;i++) {
Thread thread = new Thread() { Thread thread = new Thread() {
@ -423,6 +427,7 @@ public class TestBKDTree extends LuceneTestCase {
try { try {
_run(); _run();
} catch (Exception e) { } catch (Exception e) {
failed.set(true);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -432,7 +437,7 @@ public class TestBKDTree extends LuceneTestCase {
NumericDocValues docIDToID = MultiDocValues.getNumericValues(r, "id"); NumericDocValues docIDToID = MultiDocValues.getNumericValues(r, "id");
for (int iter=0;iter<iters;iter++) { for (int iter=0;iter<iters && failed.get() == false;iter++) {
double lat0 = randomLat(); double lat0 = randomLat();
double lat1 = randomLat(); double lat1 = randomLat();
double lon0 = randomLon(); double lon0 = randomLon();
@ -506,7 +511,16 @@ public class TestBKDTree extends LuceneTestCase {
int id = (int) docIDToID.get(docID); int id = (int) docIDToID.get(docID);
boolean expected = deleted.contains(id) == false && rectContainsPointEnc(lat0, lat1, lon0, lon1, lats[id], lons[id]); boolean expected = deleted.contains(id) == false && rectContainsPointEnc(lat0, lat1, lon0, lon1, lats[id], lons[id]);
if (hits.get(docID) != expected) { if (hits.get(docID) != expected) {
fail(Thread.currentThread().getName() + ": iter=" + iter + " id=" + id + " docID=" + docID + " lat=" + lats[id] + " lon=" + lons[id] + " (bbox: lat=" + lat0 + " TO " + lat1 + " lon=" + lon0 + " TO " + lon1 + ") expected " + expected + " but got: " + hits.get(docID) + " deleted?=" + deleted.contains(id) + " query=" + query); if (query instanceof BKDPointInPolygonQuery &&
(Math.abs(lat0-lats[id]) < TOLERANCE ||
Math.abs(lat1-lats[id]) < TOLERANCE ||
Math.abs(lon0-lons[id]) < TOLERANCE ||
Math.abs(lon1-lons[id]) < TOLERANCE)) {
// The poly check quantizes slightly differently, so we allow for boundary cases to disagree
} else {
// We do exact quantized comparison so the bbox query should never disagree:
fail(Thread.currentThread().getName() + ": iter=" + iter + " id=" + id + " docID=" + docID + " lat=" + lats[id] + " lon=" + lons[id] + " (bbox: lat=" + lat0 + " TO " + lat1 + " lon=" + lon0 + " TO " + lon1 + ") expected " + expected + " but got: " + hits.get(docID) + " deleted?=" + deleted.contains(id) + " query=" + query);
}
} }
} }
} }