Make the nightly test smaller so that it does not fail with GC overhead exceeded (OOM). Clean up random number fetching to make it shorter.

This commit is contained in:
Dawid Weiss 2018-08-01 13:49:39 +02:00
parent 5dffff7df7
commit 3203e99d8f
2 changed files with 43 additions and 42 deletions

View File

@ -45,6 +45,8 @@ import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomInt;
import static org.apache.lucene.geo.GeoEncodingUtils.decodeLatitude; import static org.apache.lucene.geo.GeoEncodingUtils.decodeLatitude;
import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude; import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude;
import static org.apache.lucene.geo.GeoEncodingUtils.encodeLatitude; import static org.apache.lucene.geo.GeoEncodingUtils.encodeLatitude;
@ -104,7 +106,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
@Nightly @Nightly
public void testRandomBig() throws Exception { public void testRandomBig() throws Exception {
doTestRandom(200000); doTestRandom(50000);
} }
private void doTestRandom(int count) throws Exception { private void doTestRandom(int count) throws Exception {
@ -116,7 +118,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
Polygon[] polygons = new Polygon[numPolygons]; Polygon[] polygons = new Polygon[numPolygons];
for (int id = 0; id < numPolygons; ++id) { for (int id = 0; id < numPolygons; ++id) {
int x = random().nextInt(20); int x = randomInt(20);
if (x == 17) { if (x == 17) {
polygons[id] = null; polygons[id] = null;
if (VERBOSE) { if (VERBOSE) {
@ -127,6 +129,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
polygons[id] = GeoTestUtil.nextPolygon(); polygons[id] = GeoTestUtil.nextPolygon();
} }
} }
verify(polygons); verify(polygons);
} }
@ -173,8 +176,8 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
poly2D[id] = Polygon2D.create(quantizePolygon(polygons[id])); poly2D[id] = Polygon2D.create(quantizePolygon(polygons[id]));
} }
w.addDocument(doc); w.addDocument(doc);
if (id > 0 && random().nextInt(100) == 42) { if (id > 0 && randomInt(100) == 42) {
int idToDelete = random().nextInt(id); int idToDelete = randomInt(id);
w.deleteDocuments(new Term("id", ""+idToDelete)); w.deleteDocuments(new Term("id", ""+idToDelete));
deleted.add(idToDelete); deleted.add(idToDelete);
if (VERBOSE) { if (VERBOSE) {
@ -183,7 +186,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
} }
} }
if (random().nextBoolean()) { if (randomBoolean()) {
w.forceMerge(1); w.forceMerge(1);
} }
final IndexReader r = DirectoryReader.open(w); final IndexReader r = DirectoryReader.open(w);

View File

@ -19,13 +19,16 @@ package org.apache.lucene.geo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random;
import org.apache.lucene.util.NumericUtils; import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.SloppyMath; import org.apache.lucene.util.SloppyMath;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import com.carrotsearch.randomizedtesting.RandomizedContext; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomDouble;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomInt;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
import static org.apache.lucene.util.LuceneTestCase.random;
/** static methods for testing geo */ /** static methods for testing geo */
public class GeoTestUtil { public class GeoTestUtil {
@ -63,7 +66,7 @@ public class GeoTestUtil {
// first pick a base value. // first pick a base value.
final double baseValue; final double baseValue;
int surpriseMe = random().nextInt(17); int surpriseMe = randomInt(17);
if (surpriseMe == 0) { if (surpriseMe == 0) {
// random bits // random bits
long lowBits = NumericUtils.doubleToSortableLong(low); long lowBits = NumericUtils.doubleToSortableLong(low);
@ -81,18 +84,18 @@ public class GeoTestUtil {
} else if (surpriseMe == 4) { } else if (surpriseMe == 4) {
// divide up space into block of 360 // divide up space into block of 360
double delta = (high - low) / 360; double delta = (high - low) / 360;
int block = random().nextInt(360); int block = randomInt(360);
baseValue = low + delta * block; baseValue = low + delta * block;
} else { } else {
// distributed ~ evenly // distributed ~ evenly
baseValue = low + (high - low) * random().nextDouble(); baseValue = low + (high - low) * randomDouble();
} }
assert baseValue >= low; assert baseValue >= low;
assert baseValue <= high; assert baseValue <= high;
// either return the base value or adjust it by 1 ulp in a random direction (if possible) // either return the base value or adjust it by 1 ulp in a random direction (if possible)
int adjustMe = random().nextInt(17); int adjustMe = randomInt(17);
if (adjustMe == 0) { if (adjustMe == 0) {
return Math.nextAfter(adjustMe, high); return Math.nextAfter(adjustMe, high);
} else if (adjustMe == 1) { } else if (adjustMe == 1) {
@ -106,7 +109,7 @@ public class GeoTestUtil {
private static double nextLatitudeNear(double otherLatitude, double delta) { private static double nextLatitudeNear(double otherLatitude, double delta) {
delta = Math.abs(delta); delta = Math.abs(delta);
GeoUtils.checkLatitude(otherLatitude); GeoUtils.checkLatitude(otherLatitude);
int surpriseMe = random().nextInt(97); int surpriseMe = randomInt(97);
if (surpriseMe == 0) { if (surpriseMe == 0) {
// purely random // purely random
return nextLatitude(); return nextLatitude();
@ -123,7 +126,7 @@ public class GeoTestUtil {
private static double nextLongitudeNear(double otherLongitude, double delta) { private static double nextLongitudeNear(double otherLongitude, double delta) {
delta = Math.abs(delta); delta = Math.abs(delta);
GeoUtils.checkLongitude(otherLongitude); GeoUtils.checkLongitude(otherLongitude);
int surpriseMe = random().nextInt(97); int surpriseMe = randomInt(97);
if (surpriseMe == 0) { if (surpriseMe == 0) {
// purely random // purely random
return nextLongitude(); return nextLongitude();
@ -145,7 +148,7 @@ public class GeoTestUtil {
assert maxLatitude >= minLatitude; assert maxLatitude >= minLatitude;
GeoUtils.checkLatitude(minLatitude); GeoUtils.checkLatitude(minLatitude);
GeoUtils.checkLatitude(maxLatitude); GeoUtils.checkLatitude(maxLatitude);
if (random().nextInt(47) == 0) { if (randomInt(47) == 0) {
// purely random // purely random
return nextLatitude(); return nextLatitude();
} else { } else {
@ -166,7 +169,7 @@ public class GeoTestUtil {
assert maxLongitude >= minLongitude; assert maxLongitude >= minLongitude;
GeoUtils.checkLongitude(minLongitude); GeoUtils.checkLongitude(minLongitude);
GeoUtils.checkLongitude(maxLongitude); GeoUtils.checkLongitude(maxLongitude);
if (random().nextInt(47) == 0) { if (randomInt(47) == 0) {
// purely random // purely random
return nextLongitude(); return nextLongitude();
} else { } else {
@ -211,7 +214,7 @@ public class GeoTestUtil {
public static double[] nextPointNear(Rectangle rectangle) { public static double[] nextPointNear(Rectangle rectangle) {
if (rectangle.crossesDateline()) { if (rectangle.crossesDateline()) {
// pick a "side" of the two boxes we really are // pick a "side" of the two boxes we really are
if (random().nextBoolean()) { if (randomBoolean()) {
return nextPointNear(new Rectangle(rectangle.minLat, rectangle.maxLat, -180, rectangle.maxLon)); return nextPointNear(new Rectangle(rectangle.minLat, rectangle.maxLat, -180, rectangle.maxLon));
} else { } else {
return nextPointNear(new Rectangle(rectangle.minLat, rectangle.maxLat, rectangle.minLon, 180)); return nextPointNear(new Rectangle(rectangle.minLat, rectangle.maxLat, rectangle.minLon, 180));
@ -229,11 +232,11 @@ public class GeoTestUtil {
Polygon holes[] = polygon.getHoles(); Polygon holes[] = polygon.getHoles();
// if there are any holes, target them aggressively // if there are any holes, target them aggressively
if (holes.length > 0 && random().nextInt(3) == 0) { if (holes.length > 0 && randomInt(3) == 0) {
return nextPointNear(holes[random().nextInt(holes.length)]); return nextPointNear(holes[randomInt(holes.length)]);
} }
int surpriseMe = random().nextInt(97); int surpriseMe = randomInt(97);
if (surpriseMe == 0) { if (surpriseMe == 0) {
// purely random // purely random
return new double[] { nextLatitude(), nextLongitude() }; return new double[] { nextLatitude(), nextLongitude() };
@ -242,7 +245,7 @@ public class GeoTestUtil {
return new double[] { nextLatitudeBetween(polygon.minLat, polygon.maxLat), nextLongitudeBetween(polygon.minLon, polygon.maxLon) }; return new double[] { nextLatitudeBetween(polygon.minLat, polygon.maxLat), nextLongitudeBetween(polygon.minLon, polygon.maxLon) };
} else if (surpriseMe < 20) { } else if (surpriseMe < 20) {
// target a vertex // target a vertex
int vertex = random().nextInt(polyLats.length - 1); int vertex = randomInt(polyLats.length - 1);
return new double[] { nextLatitudeNear(polyLats[vertex], polyLats[vertex+1] - polyLats[vertex]), return new double[] { nextLatitudeNear(polyLats[vertex], polyLats[vertex+1] - polyLats[vertex]),
nextLongitudeNear(polyLons[vertex], polyLons[vertex+1] - polyLons[vertex]) }; nextLongitudeNear(polyLons[vertex], polyLons[vertex+1] - polyLons[vertex]) };
} else if (surpriseMe < 30) { } else if (surpriseMe < 30) {
@ -250,14 +253,14 @@ public class GeoTestUtil {
Polygon container = boxPolygon(new Rectangle(polygon.minLat, polygon.maxLat, polygon.minLon, polygon.maxLon)); Polygon container = boxPolygon(new Rectangle(polygon.minLat, polygon.maxLat, polygon.minLon, polygon.maxLon));
double containerLats[] = container.getPolyLats(); double containerLats[] = container.getPolyLats();
double containerLons[] = container.getPolyLons(); double containerLons[] = container.getPolyLons();
int startVertex = random().nextInt(containerLats.length - 1); int startVertex = randomInt(containerLats.length - 1);
return nextPointAroundLine(containerLats[startVertex], containerLons[startVertex], return nextPointAroundLine(containerLats[startVertex], containerLons[startVertex],
containerLats[startVertex+1], containerLons[startVertex+1]); containerLats[startVertex+1], containerLons[startVertex+1]);
} else { } else {
// target points around diagonals between vertices // target points around diagonals between vertices
int startVertex = random().nextInt(polyLats.length - 1); int startVertex = randomInt(polyLats.length - 1);
// but favor edges heavily // but favor edges heavily
int endVertex = random().nextBoolean() ? startVertex + 1 : random().nextInt(polyLats.length - 1); int endVertex = randomBoolean() ? startVertex + 1 : randomInt(polyLats.length - 1);
return nextPointAroundLine(polyLats[startVertex], polyLons[startVertex], return nextPointAroundLine(polyLats[startVertex], polyLons[startVertex],
polyLats[endVertex], polyLons[endVertex]); polyLats[endVertex], polyLons[endVertex]);
} }
@ -270,11 +273,11 @@ public class GeoTestUtil {
// if there are any holes, target them aggressively // if there are any holes, target them aggressively
Polygon holes[] = polygon.getHoles(); Polygon holes[] = polygon.getHoles();
if (holes.length > 0 && random().nextInt(3) == 0) { if (holes.length > 0 && randomInt(3) == 0) {
return nextBoxNear(holes[random().nextInt(holes.length)]); return nextBoxNear(holes[randomInt(holes.length)]);
} }
int surpriseMe = random().nextInt(97); int surpriseMe = randomInt(97);
if (surpriseMe == 0) { if (surpriseMe == 0) {
// formed from two interesting points // formed from two interesting points
point1 = nextPointNear(polygon); point1 = nextPointNear(polygon);
@ -286,7 +289,7 @@ public class GeoTestUtil {
// now figure out a good delta: we use a rough heuristic, up to the length of an edge // now figure out a good delta: we use a rough heuristic, up to the length of an edge
double polyLats[] = polygon.getPolyLats(); double polyLats[] = polygon.getPolyLats();
double polyLons[] = polygon.getPolyLons(); double polyLons[] = polygon.getPolyLons();
int vertex = random().nextInt(polyLats.length - 1); int vertex = randomInt(polyLats.length - 1);
double deltaX = polyLons[vertex+1] - polyLons[vertex]; double deltaX = polyLons[vertex+1] - polyLons[vertex];
double deltaY = polyLats[vertex+1] - polyLats[vertex]; double deltaY = polyLats[vertex+1] - polyLats[vertex];
double edgeLength = Math.sqrt(deltaX * deltaX + deltaY * deltaY); double edgeLength = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
@ -386,14 +389,14 @@ public class GeoTestUtil {
/** returns next pseudorandom polygon */ /** returns next pseudorandom polygon */
public static Polygon nextPolygon() { public static Polygon nextPolygon() {
if (random().nextBoolean()) { if (randomBoolean()) {
return surpriseMePolygon(); return surpriseMePolygon();
} else if (random().nextInt(10) == 1) { } else if (randomInt(10) == 1) {
// this poly is slow to create ... only do it 10% of the time: // this poly is slow to create ... only do it 10% of the time:
while (true) { while (true) {
int gons = TestUtil.nextInt(random(), 4, 500); int gons = randomIntBetween(4, 500);
// So the poly can cover at most 50% of the earth's surface: // So the poly can cover at most 50% of the earth's surface:
double radiusMeters = random().nextDouble() * GeoUtils.EARTH_MEAN_RADIUS_METERS * Math.PI / 2.0 + 1.0; double radiusMeters = randomDouble() * GeoUtils.EARTH_MEAN_RADIUS_METERS * Math.PI / 2.0 + 1.0;
try { try {
return createRegularPolygon(nextLatitude(), nextLongitude(), radiusMeters, gons); return createRegularPolygon(nextLatitude(), nextLongitude(), radiusMeters, gons);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
@ -403,7 +406,7 @@ public class GeoTestUtil {
} }
Rectangle box = nextBoxInternal(false); Rectangle box = nextBoxInternal(false);
if (random().nextBoolean()) { if (randomBoolean()) {
// box // box
return boxPolygon(box); return boxPolygon(box);
} else { } else {
@ -480,19 +483,19 @@ public class GeoTestUtil {
//System.out.println("\nPOLY ITER"); //System.out.println("\nPOLY ITER");
double centerLat = nextLatitude(); double centerLat = nextLatitude();
double centerLon = nextLongitude(); double centerLon = nextLongitude();
double radius = 0.1 + 20 * random().nextDouble(); double radius = 0.1 + 20 * randomDouble();
double radiusDelta = random().nextDouble(); double radiusDelta = randomDouble();
ArrayList<Double> lats = new ArrayList<>(); ArrayList<Double> lats = new ArrayList<>();
ArrayList<Double> lons = new ArrayList<>(); ArrayList<Double> lons = new ArrayList<>();
double angle = 0.0; double angle = 0.0;
while (true) { while (true) {
angle += random().nextDouble()*40.0; angle += randomDouble() * 40.0;
//System.out.println(" angle " + angle); //System.out.println(" angle " + angle);
if (angle > 360) { if (angle > 360) {
break; break;
} }
double len = radius * (1.0 - radiusDelta + radiusDelta * random().nextDouble()); double len = radius * (1.0 - radiusDelta + radiusDelta * randomDouble());
//System.out.println(" len=" + len); //System.out.println(" len=" + len);
double lat = centerLat + len * Math.cos(SloppyMath.toRadians(angle)); double lat = centerLat + len * Math.cos(SloppyMath.toRadians(angle));
double lon = centerLon + len * Math.sin(SloppyMath.toRadians(angle)); double lon = centerLon + len * Math.sin(SloppyMath.toRadians(angle));
@ -521,11 +524,6 @@ public class GeoTestUtil {
} }
} }
/** Keep it simple, we don't need to take arbitrary Random for geo tests */
private static Random random() {
return RandomizedContext.current().getRandom();
}
/** /**
* Returns svg of polygon for debugging. * Returns svg of polygon for debugging.
* <p> * <p>