LUCENE-7136: remove threads from BaseGeoPointTestCase

This commit is contained in:
Robert Muir 2016-03-24 14:13:24 -04:00
parent 139aa0bec5
commit 39aaa108ac
1 changed files with 127 additions and 185 deletions

View File

@ -19,14 +19,11 @@ package org.apache.lucene.spatial.util;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.lucene.analysis.MockAnalyzer;
@ -325,7 +322,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
double[] lons = new double[numPoints];
Arrays.fill(lons, theLon);
verify(small, lats, lons, false);
verify(small, lats, lons);
}
public void testAllLatEqual() throws Exception {
@ -372,7 +369,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
lats[docID] = lat;
}
verify(small, lats, lons, false);
verify(small, lats, lons);
}
public void testAllLonEqual() throws Exception {
@ -421,7 +418,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
lons[docID] = theLon;
}
verify(small, lats, lons, false);
verify(small, lats, lons);
}
public void testMultiValued() throws Exception {
@ -535,25 +532,21 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
public void testRandomTiny() throws Exception {
// Make sure single-leaf-node case is OK:
doTestRandom(10, false);
doTestRandom(10);
}
public void testRandomMedium() throws Exception {
doTestRandom(10000, false);
}
public void testRandomWithThreads() throws Exception {
doTestRandom(10000, true);
doTestRandom(10000);
}
@Nightly
public void testRandomBig() throws Exception {
assumeFalse("Direct codec can OOME on this test", TestUtil.getDocValuesFormat(FIELD_NAME).equals("Direct"));
assumeFalse("Memory codec can OOME on this test", TestUtil.getDocValuesFormat(FIELD_NAME).equals("Memory"));
doTestRandom(200000, false);
doTestRandom(200000);
}
private void doTestRandom(int count, boolean useThreads) throws Exception {
private void doTestRandom(int count) throws Exception {
int numPoints = atLeast(count);
@ -621,7 +614,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
}
}
verify(small, lats, lons, useThreads);
verify(small, lats, lons);
}
public double randomLat(boolean small) {
@ -808,7 +801,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
protected abstract void describe(int docID, double lat, double lon);
}
protected void verify(boolean small, double[] lats, double[] lons, boolean useThreads) throws Exception {
protected void verify(boolean small, double[] lats, double[] lons) throws Exception {
IndexWriterConfig iwc = newIndexWriterConfig();
// Else we can get O(N^2) merging:
int mbd = iwc.getMaxBufferedDocs();
@ -852,44 +845,10 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
// We can't wrap with "exotic" readers because the BKD query must see the BKDDVFormat:
IndexSearcher s = newSearcher(r, false);
if (useThreads) {
// We must disable query cache otherwise test seed may not reproduce since different
// threads may or may not get a cache hit or miss depending on order the JVM
// schedules the threads:
s.setQueryCache(null);
}
// Make sure queries are thread safe:
int numThreads;
if (useThreads) {
numThreads = TestUtil.nextInt(random(), 2, 5);
} else {
numThreads = 1;
}
List<Thread> threads = new ArrayList<>();
final int iters = atLeast(75);
final CountDownLatch startingGun = new CountDownLatch(1);
final AtomicBoolean failed = new AtomicBoolean();
for(int i=0;i<numThreads;i++) {
Thread thread = new Thread() {
@Override
public void run() {
try {
_run();
} catch (Exception e) {
failed.set(true);
throw new RuntimeException(e);
}
}
private void _run() throws Exception {
if (useThreads) {
startingGun.await();
}
NumericDocValues docIDToID = MultiDocValues.getNumericValues(r, "id");
for (int iter=0;iter<iters && failed.get() == false;iter++) {
@ -981,19 +940,19 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
final GeoRect bbox = randomRect(small, false);
// Polygon
double[] lats = new double[5];
double[] lons = new double[5];
lats[0] = bbox.minLat;
lons[0] = bbox.minLon;
lats[1] = bbox.maxLat;
lons[1] = bbox.minLon;
lats[2] = bbox.maxLat;
lons[2] = bbox.maxLon;
lats[3] = bbox.minLat;
lons[3] = bbox.maxLon;
lats[4] = bbox.minLat;
lons[4] = bbox.minLon;
query = newPolygonQuery(FIELD_NAME, lats, lons);
double[] polyLats = new double[5];
double[] polyLons = new double[5];
polyLats[0] = bbox.minLat;
polyLons[0] = bbox.minLon;
polyLats[1] = bbox.maxLat;
polyLons[1] = bbox.minLon;
polyLats[2] = bbox.maxLat;
polyLons[2] = bbox.maxLon;
polyLats[3] = bbox.minLat;
polyLons[3] = bbox.maxLon;
polyLats[4] = bbox.minLat;
polyLons[4] = bbox.minLon;
query = newPolygonQuery(FIELD_NAME, polyLats, polyLons);
verifyHits = new VerifyHits() {
@Override
@ -1016,25 +975,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
verifyHits.test(failed, small, s, docIDToID, deleted, query, lats, lons);
}
}
}
};
thread.setName("T" + i);
if (useThreads) {
thread.start();
} else {
// Just run with main thread:
thread.run();
}
threads.add(thread);
}
if (useThreads) {
startingGun.countDown();
for(Thread thread : threads) {
thread.join();
}
}
IOUtils.close(r, dir);
assertFalse(failed.get());
}
public void testRectBoundariesAreInclusive() throws Exception {