You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2018/08/01 13:45:39 UTC

[2/4] lucene-solr:master: Revert "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."

Revert "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 reverts commit 3203e99d8fbcaac3458fcf882d4ec229f97dfa43.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e56c8722
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e56c8722
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e56c8722

Branch: refs/heads/master
Commit: e56c8722ce99338e980b32e100b96f2c19af9ddf
Parents: 86a39fa
Author: Adrien Grand <jp...@gmail.com>
Authored: Wed Aug 1 15:44:57 2018 +0200
Committer: Adrien Grand <jp...@gmail.com>
Committed: Wed Aug 1 15:44:57 2018 +0200

----------------------------------------------------------------------
 .../lucene/document/TestLatLonShapeQueries.java | 15 ++---
 .../java/org/apache/lucene/geo/GeoTestUtil.java | 70 ++++++++++----------
 2 files changed, 42 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e56c8722/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShapeQueries.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShapeQueries.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShapeQueries.java
index 21d4e83..03941b9 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShapeQueries.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestLatLonShapeQueries.java
@@ -45,8 +45,6 @@ import org.apache.lucene.util.FixedBitSet;
 import org.apache.lucene.util.IOUtils;
 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.decodeLongitude;
 import static org.apache.lucene.geo.GeoEncodingUtils.encodeLatitude;
@@ -106,7 +104,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
 
   @Nightly
   public void testRandomBig() throws Exception {
-    doTestRandom(50000);
+    doTestRandom(200000);
   }
 
   private void doTestRandom(int count) throws Exception {
@@ -118,7 +116,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
 
     Polygon[] polygons = new Polygon[numPolygons];
     for (int id = 0; id < numPolygons; ++id) {
-      int x = randomInt(20);
+      int x = random().nextInt(20);
       if (x == 17) {
         polygons[id] = null;
         if (VERBOSE) {
@@ -129,7 +127,6 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
         polygons[id] = GeoTestUtil.nextPolygon();
       }
     }
-
     verify(polygons);
   }
 
@@ -176,8 +173,8 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
         poly2D[id] = Polygon2D.create(quantizePolygon(polygons[id]));
       }
       w.addDocument(doc);
-      if (id > 0 && randomInt(100) == 42) {
-        int idToDelete = randomInt(id);
+      if (id > 0 && random().nextInt(100) == 42) {
+        int idToDelete = random().nextInt(id);
         w.deleteDocuments(new Term("id", ""+idToDelete));
         deleted.add(idToDelete);
         if (VERBOSE) {
@@ -186,7 +183,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
       }
     }
 
-    if (randomBoolean()) {
+    if (random().nextBoolean()) {
       w.forceMerge(1);
     }
     final IndexReader r = DirectoryReader.open(w);
@@ -201,7 +198,7 @@ public class TestLatLonShapeQueries extends LuceneTestCase {
 
     for (int iter = 0; iter < iters; ++iter) {
       if (VERBOSE) {
-        System.out.println("\nTEST: iter=" + (iter + 1) + " of " + iters + " s=" + s);
+        System.out.println("\nTEST: iter=" + (iter+1) + " of " + iters + " s=" + s);
       }
 
       // BBox

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