mirror of https://github.com/apache/lucene.git
LUCENE-7136: remove threads from BaseGeoPointTestCase
This commit is contained in:
parent
139aa0bec5
commit
39aaa108ac
|
@ -19,14 +19,11 @@ package org.apache.lucene.spatial.util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.MockAnalyzer;
|
import org.apache.lucene.analysis.MockAnalyzer;
|
||||||
|
@ -325,7 +322,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
||||||
double[] lons = new double[numPoints];
|
double[] lons = new double[numPoints];
|
||||||
Arrays.fill(lons, theLon);
|
Arrays.fill(lons, theLon);
|
||||||
|
|
||||||
verify(small, lats, lons, false);
|
verify(small, lats, lons);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllLatEqual() throws Exception {
|
public void testAllLatEqual() throws Exception {
|
||||||
|
@ -372,7 +369,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
||||||
lats[docID] = lat;
|
lats[docID] = lat;
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(small, lats, lons, false);
|
verify(small, lats, lons);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllLonEqual() throws Exception {
|
public void testAllLonEqual() throws Exception {
|
||||||
|
@ -421,7 +418,7 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
||||||
lons[docID] = theLon;
|
lons[docID] = theLon;
|
||||||
}
|
}
|
||||||
|
|
||||||
verify(small, lats, lons, false);
|
verify(small, lats, lons);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiValued() throws Exception {
|
public void testMultiValued() throws Exception {
|
||||||
|
@ -535,25 +532,21 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
||||||
|
|
||||||
public void testRandomTiny() throws Exception {
|
public void testRandomTiny() throws Exception {
|
||||||
// Make sure single-leaf-node case is OK:
|
// Make sure single-leaf-node case is OK:
|
||||||
doTestRandom(10, false);
|
doTestRandom(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRandomMedium() throws Exception {
|
public void testRandomMedium() throws Exception {
|
||||||
doTestRandom(10000, false);
|
doTestRandom(10000);
|
||||||
}
|
|
||||||
|
|
||||||
public void testRandomWithThreads() throws Exception {
|
|
||||||
doTestRandom(10000, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nightly
|
@Nightly
|
||||||
public void testRandomBig() throws Exception {
|
public void testRandomBig() throws Exception {
|
||||||
assumeFalse("Direct codec can OOME on this test", TestUtil.getDocValuesFormat(FIELD_NAME).equals("Direct"));
|
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"));
|
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);
|
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) {
|
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 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();
|
IndexWriterConfig iwc = newIndexWriterConfig();
|
||||||
// Else we can get O(N^2) merging:
|
// Else we can get O(N^2) merging:
|
||||||
int mbd = iwc.getMaxBufferedDocs();
|
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:
|
// We can't wrap with "exotic" readers because the BKD query must see the BKDDVFormat:
|
||||||
IndexSearcher s = newSearcher(r, false);
|
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 int iters = atLeast(75);
|
||||||
|
|
||||||
final CountDownLatch startingGun = new CountDownLatch(1);
|
|
||||||
final AtomicBoolean failed = new AtomicBoolean();
|
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");
|
NumericDocValues docIDToID = MultiDocValues.getNumericValues(r, "id");
|
||||||
|
|
||||||
for (int iter=0;iter<iters && failed.get() == false;iter++) {
|
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);
|
final GeoRect bbox = randomRect(small, false);
|
||||||
|
|
||||||
// Polygon
|
// Polygon
|
||||||
double[] lats = new double[5];
|
double[] polyLats = new double[5];
|
||||||
double[] lons = new double[5];
|
double[] polyLons = new double[5];
|
||||||
lats[0] = bbox.minLat;
|
polyLats[0] = bbox.minLat;
|
||||||
lons[0] = bbox.minLon;
|
polyLons[0] = bbox.minLon;
|
||||||
lats[1] = bbox.maxLat;
|
polyLats[1] = bbox.maxLat;
|
||||||
lons[1] = bbox.minLon;
|
polyLons[1] = bbox.minLon;
|
||||||
lats[2] = bbox.maxLat;
|
polyLats[2] = bbox.maxLat;
|
||||||
lons[2] = bbox.maxLon;
|
polyLons[2] = bbox.maxLon;
|
||||||
lats[3] = bbox.minLat;
|
polyLats[3] = bbox.minLat;
|
||||||
lons[3] = bbox.maxLon;
|
polyLons[3] = bbox.maxLon;
|
||||||
lats[4] = bbox.minLat;
|
polyLats[4] = bbox.minLat;
|
||||||
lons[4] = bbox.minLon;
|
polyLons[4] = bbox.minLon;
|
||||||
query = newPolygonQuery(FIELD_NAME, lats, lons);
|
query = newPolygonQuery(FIELD_NAME, polyLats, polyLons);
|
||||||
|
|
||||||
verifyHits = new VerifyHits() {
|
verifyHits = new VerifyHits() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1016,25 +975,8 @@ public abstract class BaseGeoPointTestCase extends LuceneTestCase {
|
||||||
verifyHits.test(failed, small, s, docIDToID, deleted, query, lats, lons);
|
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);
|
IOUtils.close(r, dir);
|
||||||
assertFalse(failed.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRectBoundariesAreInclusive() throws Exception {
|
public void testRectBoundariesAreInclusive() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue