diff --git a/build.gradle b/build.gradle index 2ae28268b9b..e50b1b70b6d 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ import java.time.format.DateTimeFormatter plugins { id "base" - id "com.palantir.consistent-versions" version "1.14.0" + id "com.palantir.consistent-versions" version "1.28.0" id "org.owasp.dependencycheck" version "5.3.0" id 'de.thetaphi.forbiddenapis' version '3.1' apply false id "de.undercouch.download" version "4.1.1" apply false @@ -167,11 +167,6 @@ apply from: file('gradle/testing/profiling.gradle') apply from: file('gradle/testing/beasting.gradle') apply from: file('gradle/help.gradle') -// Ant-compatibility layer. ALL OF THESE SHOULD BE GONE at some point. They are -// here so that we can coexist with current ant build but they are indicative -// of potential problems with the build conventions, dependencies, etc. -apply from: file('gradle/ant-compat/test-classes-cross-deps.gradle') - apply from: file('gradle/documentation/documentation.gradle') apply from: file('gradle/documentation/changes-to-html.gradle') apply from: file('gradle/documentation/markdown.gradle') diff --git a/gradle/ant-compat/test-classes-cross-deps.gradle b/gradle/ant-compat/test-classes-cross-deps.gradle deleted file mode 100644 index c75202b9b8c..00000000000 --- a/gradle/ant-compat/test-classes-cross-deps.gradle +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Set up cross-project dependency on test classes. This should be resolved by pulling reused classes into -// a separate regular module. Exporting test classes is sort of weird. -configure([project(":lucene:spatial3d"), - project(":lucene:analysis:common"), - project(":lucene:backward-codecs"), - project(":lucene:queryparser")]) { - plugins.withType(JavaPlugin) { - configurations { - testClassesExported - } - - artifacts { - testClassesExported sourceSets.test.java.outputDir, { - builtBy testClasses - } - } - } -} - -configure(project(":lucene:spatial-extras")) { - plugins.withType(JavaPlugin) { - dependencies { - testImplementation project(path: ':lucene:spatial3d', configuration: 'testClassesExported') - } - } -} diff --git a/gradle/publishing/defaults-maven.gradle b/gradle/publishing/defaults-maven.gradle index 575668b0028..7f7345c3f1a 100644 --- a/gradle/publishing/defaults-maven.gradle +++ b/gradle/publishing/defaults-maven.gradle @@ -84,6 +84,20 @@ configure(subprojects.findAll { it.path in rootProject.published }) { prj -> } } + // Skip any test fixtures in publishing. + afterEvaluate { + configurations.matching { + return it.name in [ + "testFixturesApiElements", + "testFixturesRuntimeElements" + ] + }.all { + project.components.java.withVariantsFromConfiguration(it) { + skip() + } + } + } + // Do not generate gradle metadata files. tasks.withType(GenerateModuleMetadata) { enabled = false diff --git a/gradle/validation/forbidden-apis.gradle b/gradle/validation/forbidden-apis.gradle index 3a06e2651b8..832dcde8940 100644 --- a/gradle/validation/forbidden-apis.gradle +++ b/gradle/validation/forbidden-apis.gradle @@ -69,10 +69,12 @@ allprojects { prj -> suppressAnnotations += [ "**.SuppressForbidden" ] + + doFirst dynamicSignatures.curry(configurations.compileClasspath, "lucene") } // Configure defaults for sourceSets.test - forbiddenApisTest { + tasks.matching { it.name in ["forbiddenApisTest", "forbiddenApisTestFixtures"] }.all { bundledSignatures += [ 'jdk-unsafe', 'jdk-deprecated', @@ -87,6 +89,12 @@ allprojects { prj -> suppressAnnotations += [ "**.SuppressForbidden" ] + + if (it.name == "forbiddenApisTestFixtures") { + doFirst dynamicSignatures.curry(configurations.testFixturesCompileClasspath, "lucene") + } else { + doFirst dynamicSignatures.curry(configurations.testCompileClasspath, "lucene") + } } // Configure defaults for sourceSets.tools (if present). @@ -103,9 +111,21 @@ allprojects { prj -> ] doFirst dynamicSignatures.curry(configurations.toolsCompileClasspath, "lucene") + inputs.dir(file(resources)) } + // We rely on resolved configurations to compute the relevant set of rule + // files for forbiddenApis. Since we don't want to resolve these configurations until + // the task is executed, we can't really use them as task inputs properly. This is a + // chicken-and-egg problem. + // + // This is the simplest workaround possible: just point at all the rule files and indicate + // them as inputs. This way if a rule is modified, checks will be reapplied. + configure(tasks.matching { it.name.startsWith("forbiddenApis") }) { task -> + task.inputs.dir(file(resources)) + } + // Disable sysout signatures for these projects. if (prj.path in [ ":lucene:demo", @@ -116,24 +136,5 @@ allprojects { prj -> 'jdk-system-out' ] } - - forbiddenApisMain { - doFirst dynamicSignatures.curry(configurations.compileClasspath, "lucene") - } - - forbiddenApisTest { - doFirst dynamicSignatures.curry(configurations.testCompileClasspath, "lucene") - } - - // We rely on resolved configurations to compute the relevant set of rule - // files for forbiddenApis. Since we don't want to resolve these configurations until - // the task is executed, we can't really use them as task inputs properly. This is a - // chicken-and-egg problem. - // - // This is the simplest workaround possible: just point at all the rule files and indicate - // them as inputs. This way if a rule is modified, checks will be reapplied. - configure([forbiddenApisMain, forbiddenApisTest]) { task -> - task.inputs.dir(file(resources)) - } }) } \ No newline at end of file diff --git a/gradle/validation/forbidden-apis/com.fasterxml.jackson.core.jackson-annotations.solr.txt b/gradle/validation/forbidden-apis/com.fasterxml.jackson.core.jackson-annotations.solr.txt deleted file mode 100644 index af88dea6791..00000000000 --- a/gradle/validation/forbidden-apis/com.fasterxml.jackson.core.jackson-annotations.solr.txt +++ /dev/null @@ -1,2 +0,0 @@ -@defaultMessage Use org.apache.solr.common.annotation.JsonProperty instead -com.fasterxml.jackson.annotation.JsonProperty diff --git a/gradle/validation/forbidden-apis/defaults.solr.txt b/gradle/validation/forbidden-apis/defaults.solr.txt deleted file mode 100644 index 50c69ac0227..00000000000 --- a/gradle/validation/forbidden-apis/defaults.solr.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -@defaultMessage Spawns threads without MDC logging context; use ExecutorUtil.newMDCAwareFixedThreadPool instead -java.util.concurrent.Executors#newFixedThreadPool(int,java.util.concurrent.ThreadFactory) - -@defaultMessage Spawns threads without MDC logging context; use ExecutorUtil.newMDCAwareSingleThreadExecutor instead -java.util.concurrent.Executors#newSingleThreadExecutor(java.util.concurrent.ThreadFactory) - -@defaultMessage Spawns threads without MDC logging context; use ExecutorUtil.newMDCAwareCachedThreadPool instead -java.util.concurrent.Executors#newCachedThreadPool(java.util.concurrent.ThreadFactory) - -@defaultMessage Use ExecutorUtil.MDCAwareThreadPoolExecutor instead of ThreadPoolExecutor -java.util.concurrent.ThreadPoolExecutor#(int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.BlockingQueue,java.util.concurrent.ThreadFactory,java.util.concurrent.RejectedExecutionHandler) -java.util.concurrent.ThreadPoolExecutor#(int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.BlockingQueue) -java.util.concurrent.ThreadPoolExecutor#(int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.BlockingQueue,java.util.concurrent.ThreadFactory) -java.util.concurrent.ThreadPoolExecutor#(int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.BlockingQueue,java.util.concurrent.RejectedExecutionHandler) - -@defaultMessage Use RTimer/TimeOut/System.nanoTime for time comparisons, and `new Date()` output/debugging/stats of timestamps. If for some miscellaneous reason, you absolutely need to use this, use a SuppressForbidden. -java.lang.System#currentTimeMillis() - -@defaultMessage Use slf4j classes instead -java.util.logging.** diff --git a/gradle/validation/forbidden-apis/java.solr.txt b/gradle/validation/forbidden-apis/java.solr.txt deleted file mode 100644 index 2ea1125fdbe..00000000000 --- a/gradle/validation/forbidden-apis/java.solr.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -@defaultMessage Creates threads without a thread name -java.lang.Thread#() -java.lang.Thread#(java.lang.Runnable) -java.lang.Thread#(java.lang.ThreadGroup,java.lang.Runnable) - diff --git a/gradle/validation/forbidden-apis/javax.servlet.javax.servlet-api.solr.txt b/gradle/validation/forbidden-apis/javax.servlet.javax.servlet-api.solr.txt deleted file mode 100644 index dc82e8fe45d..00000000000 --- a/gradle/validation/forbidden-apis/javax.servlet.javax.servlet-api.solr.txt +++ /dev/null @@ -1,43 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -@defaultMessage Servlet API method is parsing request parameters without using the correct encoding if no extra configuration is given in the servlet container - -javax.servlet.ServletRequest#getParameter(java.lang.String) -javax.servlet.ServletRequest#getParameterMap() -javax.servlet.ServletRequest#getParameterNames() -javax.servlet.ServletRequest#getParameterValues(java.lang.String) - -javax.servlet.http.HttpServletRequest#getSession() @ Servlet API getter has side effect of creating sessions - -@defaultMessage Servlet API method is broken and slow in some environments (e.g., Jetty's UTF-8 readers) - -javax.servlet.ServletRequest#getReader() -javax.servlet.ServletResponse#getWriter() -javax.servlet.ServletInputStream#readLine(byte[],int,int) -javax.servlet.ServletOutputStream#print(boolean) -javax.servlet.ServletOutputStream#print(char) -javax.servlet.ServletOutputStream#print(double) -javax.servlet.ServletOutputStream#print(float) -javax.servlet.ServletOutputStream#print(int) -javax.servlet.ServletOutputStream#print(long) -javax.servlet.ServletOutputStream#print(java.lang.String) -javax.servlet.ServletOutputStream#println(boolean) -javax.servlet.ServletOutputStream#println(char) -javax.servlet.ServletOutputStream#println(double) -javax.servlet.ServletOutputStream#println(float) -javax.servlet.ServletOutputStream#println(int) -javax.servlet.ServletOutputStream#println(long) -javax.servlet.ServletOutputStream#println(java.lang.String) diff --git a/gradle/validation/forbidden-apis/org.apache.logging.log4j.log4j-api.solr.txt b/gradle/validation/forbidden-apis/org.apache.logging.log4j.log4j-api.solr.txt deleted file mode 100644 index 7816b651a9d..00000000000 --- a/gradle/validation/forbidden-apis/org.apache.logging.log4j.log4j-api.solr.txt +++ /dev/null @@ -1,3 +0,0 @@ -@defaultMessage Use slf4j classes instead -org.apache.log4j.** -org.apache.logging.log4j.** diff --git a/lucene/spatial-extras/build.gradle b/lucene/spatial-extras/build.gradle index 83889d36f57..252056b9d8f 100644 --- a/lucene/spatial-extras/build.gradle +++ b/lucene/spatial-extras/build.gradle @@ -27,6 +27,7 @@ dependencies { api 'io.sgr:s2-geometry-library-java' testImplementation project(':lucene:test-framework') + testImplementation testFixtures(project(':lucene:spatial3d')) testImplementation 'org.locationtech.jts:jts-core' testImplementation 'org.locationtech.spatial4j:spatial4j::tests' diff --git a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/TestGeo3dRpt.java b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/TestGeo3dRpt.java index 20ed2173cb8..425142e82d1 100644 --- a/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/TestGeo3dRpt.java +++ b/lucene/spatial-extras/src/test/org/apache/lucene/spatial/spatial4j/TestGeo3dRpt.java @@ -16,6 +16,7 @@ */ package org.apache.lucene.spatial.spatial4j; +import static org.apache.lucene.spatial3d.geom.RandomGeo3dShapeGenerator.*; import static org.locationtech.spatial4j.distance.DistanceUtils.DEGREES_TO_RADIANS; import java.io.IOException; @@ -39,7 +40,6 @@ import org.apache.lucene.spatial3d.geom.GeoPoint; import org.apache.lucene.spatial3d.geom.GeoPointShape; import org.apache.lucene.spatial3d.geom.GeoPolygonFactory; import org.apache.lucene.spatial3d.geom.PlanetModel; -import org.apache.lucene.spatial3d.geom.RandomGeo3dShapeGenerator; import org.junit.Test; import org.locationtech.spatial4j.shape.Rectangle; import org.locationtech.spatial4j.shape.Shape; @@ -47,7 +47,6 @@ import org.locationtech.spatial4j.shape.Shape; public class TestGeo3dRpt extends RandomSpatialOpStrategyTestCase { private PlanetModel planetModel; - private RandomGeo3dShapeGenerator shapeGenerator; private SpatialPrefixTree grid; private RecursivePrefixTreeStrategy rptStrategy; @@ -73,8 +72,7 @@ public class TestGeo3dRpt extends RandomSpatialOpStrategyTestCase { } private void setupStrategy() { - shapeGenerator = new RandomGeo3dShapeGenerator(); - planetModel = shapeGenerator.randomPlanetModel(); + planetModel = randomPlanetModel(); Geo3dSpatialContextFactory factory = new Geo3dSpatialContextFactory(); factory.planetModel = planetModel; ctx = factory.newSpatialContext(); @@ -135,8 +133,8 @@ public class TestGeo3dRpt extends RandomSpatialOpStrategyTestCase { @Override protected Shape randomIndexedShape() { - int type = shapeGenerator.randomShapeType(); - GeoAreaShape areaShape = shapeGenerator.randomGeoAreaShape(type, planetModel); + int type = randomShapeType(); + GeoAreaShape areaShape = randomGeoAreaShape(type, planetModel); if (areaShape instanceof GeoPointShape) { return new Geo3dPointShape((GeoPointShape) areaShape, ctx); } @@ -145,8 +143,8 @@ public class TestGeo3dRpt extends RandomSpatialOpStrategyTestCase { @Override protected Shape randomQueryShape() { - int type = shapeGenerator.randomShapeType(); - GeoAreaShape areaShape = shapeGenerator.randomGeoAreaShape(type, planetModel); + int type = randomShapeType(); + GeoAreaShape areaShape = randomGeoAreaShape(type, planetModel); return new Geo3dShape<>(areaShape, ctx); } diff --git a/lucene/spatial3d/build.gradle b/lucene/spatial3d/build.gradle index 415981b5360..db2064c9396 100644 --- a/lucene/spatial3d/build.gradle +++ b/lucene/spatial3d/build.gradle @@ -16,10 +16,13 @@ */ apply plugin: 'java-library' +apply plugin: 'java-test-fixtures' description = '3D spatial planar geometry APIs' dependencies { api project(':lucene:core') + + testFixturesApi project(':lucene:test-framework') testImplementation project(':lucene:test-framework') -} \ No newline at end of file +} diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DDocValues.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DDocValues.java index 185fd9e0f41..9a56c3e64a9 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DDocValues.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/TestGeo3DDocValues.java @@ -24,7 +24,7 @@ import org.apache.lucene.util.TestUtil; public class TestGeo3DDocValues extends LuceneTestCase { - public void testBasic() throws Exception { + public void testBasic() { checkPointEncoding(0.0, 0.0); checkPointEncoding(45.0, 72.0); checkPointEncoding(-45.0, -100.0); diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestCompositeGeoPolygonRelationships.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestCompositeGeoPolygonRelationships.java index 37d71dee283..ca0b3b95664 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestCompositeGeoPolygonRelationships.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestCompositeGeoPolygonRelationships.java @@ -17,18 +17,17 @@ package org.apache.lucene.spatial3d.geom; -import static org.junit.Assert.assertEquals; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** * Check relationship between polygon and GeoShapes of composite polygons. Normally we construct the * composite polygon (when possible) and the complex one. */ -public class TestCompositeGeoPolygonRelationships { +public class TestCompositeGeoPolygonRelationships extends LuceneTestCase { @Test public void testGeoCompositePolygon1() { diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoBBox.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoBBox.java index 5cb74fc274c..f32bbc3f242 100755 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoBBox.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoBBox.java @@ -16,15 +16,12 @@ */ package org.apache.lucene.spatial3d.geom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.List; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; -public class TestGeoBBox { +public class TestGeoBBox extends LuceneTestCase { protected static final double DEGREES_TO_RADIANS = Math.PI / 180.0; @@ -32,7 +29,7 @@ public class TestGeoBBox { public void testBBoxDegenerate() { GeoBBox box; int relationship; - List points = new ArrayList(); + List points = new ArrayList<>(); points.add( new GeoPoint(PlanetModel.SPHERE, -49 * DEGREES_TO_RADIANS, -176 * DEGREES_TO_RADIANS)); points.add( diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoConvexPolygon.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoConvexPolygon.java index 831cffa5eaa..9f8a0e4228a 100755 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoConvexPolygon.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoConvexPolygon.java @@ -16,13 +16,10 @@ */ package org.apache.lucene.spatial3d.geom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; -public class TestGeoConvexPolygon { +public class TestGeoConvexPolygon extends LuceneTestCase { @Test public void testPolygonPointWithin() { diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoExactCircle.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoExactCircle.java index 1ab6261740a..23b0c1bc8da 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoExactCircle.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoExactCircle.java @@ -17,11 +17,14 @@ package org.apache.lucene.spatial3d.geom; +import static org.apache.lucene.spatial3d.geom.RandomGeo3dShapeGenerator.*; + import com.carrotsearch.randomizedtesting.annotations.Repeat; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** Tests for GeoExactCircle. */ -public class TestGeoExactCircle extends RandomGeo3dShapeGenerator { +public class TestGeoExactCircle extends LuceneTestCase { @Test public void testExactCircle() { @@ -78,8 +81,7 @@ public class TestGeoExactCircle extends RandomGeo3dShapeGenerator { @Repeat(iterations = 100) public void RandomPointBearingWGS84Test() { PlanetModel planetModel = PlanetModel.WGS84; - RandomGeo3dShapeGenerator generator = new RandomGeo3dShapeGenerator(); - GeoPoint center = generator.randomGeoPoint(planetModel); + GeoPoint center = randomGeoPoint(planetModel); double radius = random().nextDouble() * Math.PI; checkBearingPoint(planetModel, center, radius, 0); checkBearingPoint(planetModel, center, radius, 0.5 * Math.PI); @@ -197,7 +199,8 @@ public class TestGeoExactCircle extends RandomGeo3dShapeGenerator { @Repeat(iterations = 100) public void testRandomLUCENE8054() { PlanetModel planetModel = randomPlanetModel(); - GeoCircle circle1 = (GeoCircle) randomGeoAreaShape(EXACT_CIRCLE, planetModel); + GeoCircle circle1 = + (GeoCircle) randomGeoAreaShape(RandomGeo3dShapeGenerator.EXACT_CIRCLE, planetModel); // new radius, a bit smaller than the generated one! double radius = circle1.getRadius() * (1 - 0.01 * random().nextDouble()); // circle with same center and new radius diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoModel.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoModel.java index 72a04ac4ce9..b32dec53d3c 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoModel.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestGeoModel.java @@ -16,14 +16,11 @@ */ package org.apache.lucene.spatial3d.geom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** Test basic plane functionality. */ -public class TestGeoModel { +public class TestGeoModel extends LuceneTestCase { protected static final PlanetModel scaledModel = new PlanetModel(1.2, 1.5); diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestPlane.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestPlane.java index 93d518404c2..da690cbce3d 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestPlane.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestPlane.java @@ -16,14 +16,11 @@ */ package org.apache.lucene.spatial3d.geom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** Test basic plane functionality. */ -public class TestPlane { +public class TestPlane extends LuceneTestCase { @Test public void testIdenticalPlanes() { diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomBinaryCodec.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomBinaryCodec.java index 0bb14c5866f..4cde05f00ad 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomBinaryCodec.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomBinaryCodec.java @@ -17,15 +17,17 @@ package org.apache.lucene.spatial3d.geom; +import static org.apache.lucene.spatial3d.geom.RandomGeo3dShapeGenerator.*; + import com.carrotsearch.randomizedtesting.annotations.Repeat; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** Test to check Serialization */ -public class TestRandomBinaryCodec extends RandomGeo3dShapeGenerator { - +public class TestRandomBinaryCodec extends LuceneTestCase { @Test @Repeat(iterations = 10) public void testRandomPointCodec() throws IOException { diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoPolygon.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoPolygon.java index ac5fd701f6a..e262561e41d 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoPolygon.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoPolygon.java @@ -16,15 +16,17 @@ */ package org.apache.lucene.spatial3d.geom; +import static org.apache.lucene.spatial3d.geom.RandomGeo3dShapeGenerator.*; + import com.carrotsearch.randomizedtesting.generators.BiasedNumbers; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** Random test for polygons. */ -public class TestRandomGeoPolygon extends RandomGeo3dShapeGenerator { - +public class TestRandomGeoPolygon extends LuceneTestCase { @Test public void testRandomLUCENE8157() { final PlanetModel planetModel = randomPlanetModel(); diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoShapeRelationship.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoShapeRelationship.java index 2698a875021..ccc807889ed 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoShapeRelationship.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomGeoShapeRelationship.java @@ -17,11 +17,13 @@ package org.apache.lucene.spatial3d.geom; +import static org.apache.lucene.spatial3d.geom.RandomGeo3dShapeGenerator.*; + +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** Random test to check relationship between GeoAreaShapes and GeoShapes. */ -public class TestRandomGeoShapeRelationship extends RandomGeo3dShapeGenerator { - +public class TestRandomGeoShapeRelationship extends LuceneTestCase { /** * Test for WITHIN points. We build a WITHIN shape with respect the geoAreaShape and create a * point WITHIN the shape. The resulting shape should be WITHIN the original shape. diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomPlane.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomPlane.java index 87ff11e2686..c4cb115aa70 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomPlane.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestRandomPlane.java @@ -17,13 +17,16 @@ package org.apache.lucene.spatial3d.geom; +import static org.apache.lucene.spatial3d.geom.RandomGeo3dShapeGenerator.*; + import com.carrotsearch.randomizedtesting.annotations.Repeat; import java.util.ArrayList; import java.util.List; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** Random test for planes. */ -public class TestRandomPlane extends RandomGeo3dShapeGenerator { +public class TestRandomPlane extends LuceneTestCase { @Test @Repeat(iterations = 10) diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestSimpleGeoPolygonRelationships.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestSimpleGeoPolygonRelationships.java index ad2c0ac29d2..095925cf56f 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestSimpleGeoPolygonRelationships.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/TestSimpleGeoPolygonRelationships.java @@ -17,19 +17,17 @@ package org.apache.lucene.spatial3d.geom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; /** * Check relationship between polygon and GeoShapes of basic polygons. Normally we construct the * convex, concave counterpart and the convex polygon as a complex polygon. */ -public class TestSimpleGeoPolygonRelationships { +public class TestSimpleGeoPolygonRelationships extends LuceneTestCase { /** Test with two shapes with no crossing edges and no points in common in convex case. */ @Test diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomGeo3dShapeGenerator.java b/lucene/spatial3d/src/testFixtures/java/org/apache/lucene/spatial3d/geom/RandomGeo3dShapeGenerator.java similarity index 91% rename from lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomGeo3dShapeGenerator.java rename to lucene/spatial3d/src/testFixtures/java/org/apache/lucene/spatial3d/geom/RandomGeo3dShapeGenerator.java index ca89e1b9057..61f83a619e2 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomGeo3dShapeGenerator.java +++ b/lucene/spatial3d/src/testFixtures/java/org/apache/lucene/spatial3d/geom/RandomGeo3dShapeGenerator.java @@ -17,14 +17,14 @@ package org.apache.lucene.spatial3d.geom; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomDouble; - +import com.carrotsearch.randomizedtesting.RandomizedContext; +import com.carrotsearch.randomizedtesting.RandomizedTest; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.lucene.util.LuceneTestCase; +import java.util.Random; /** * Class for generating random Geo3dShapes. They can be generated under given constraints which are @@ -34,7 +34,7 @@ import org.apache.lucene.util.LuceneTestCase; * otherwise they are convex. Internally they can be created using GeoConvexPolygons and * GeoConcavePolygons. */ -public class RandomGeo3dShapeGenerator extends LuceneTestCase { +public final class RandomGeo3dShapeGenerator { /* Max num of iterations to find right shape under given constrains */ private static final int MAX_SHAPE_ITERATIONS = 20; @@ -59,13 +59,21 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { protected static final int CONVEX_SIMPLE_POLYGON = 500; protected static final int CONCAVE_SIMPLE_POLYGON = 501; + /** Static methods only. */ + private RandomGeo3dShapeGenerator() {} + + /** @return Returns a private-use random forked from the current {@link RandomizedContext}. */ + private static Random random() { + return new Random(RandomizedContext.current().getRandom().nextLong()); + } + /** * Method that returns a random generated Planet model from the supported Planet models. currently * SPHERE and WGS84 * * @return a random generated Planet model */ - public PlanetModel randomPlanetModel() { + public static PlanetModel randomPlanetModel() { final int shapeType = random().nextInt(2); switch (shapeType) { case 0: @@ -86,7 +94,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * * @return a random generated shape code */ - public int randomShapeType() { + public static int randomShapeType() { return random().nextInt(12); } @@ -98,7 +106,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * * @return a random generated polygon code */ - public int randomGeoAreaShapeType() { + public static int randomGeoAreaShapeType() { return random().nextInt(12); } @@ -107,7 +115,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * * @return a random generated convex shape code */ - public int randomConvexShapeType() { + public static int randomConvexShapeType() { int shapeType = randomShapeType(); while (isConcave(shapeType)) { shapeType = randomShapeType(); @@ -120,7 +128,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * * @return a random generated concave shape code */ - public int randomConcaveShapeType() { + public static int randomConcaveShapeType() { int shapeType = randomShapeType(); while (!isConcave(shapeType)) { shapeType = randomShapeType(); @@ -133,7 +141,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * * @return true if the shape represented by the code is concave */ - public boolean isConcave(int shapeType) { + public static boolean isConcave(int shapeType) { return (shapeType == CONCAVE_POLYGON); } @@ -142,7 +150,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * * @return an empty Constraints object */ - public Constraints getEmptyConstraint() { + public static Constraints getEmptyConstraint() { return new Constraints(); } @@ -152,7 +160,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param planetModel The planet model. * @return The random generated GeoPoint. */ - public GeoPoint randomGeoPoint(PlanetModel planetModel) { + public static GeoPoint randomGeoPoint(PlanetModel planetModel) { GeoPoint point = null; while (point == null) { point = randomGeoPoint(planetModel, getEmptyConstraint()); @@ -168,14 +176,14 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPoint. */ - public GeoPoint randomGeoPoint(PlanetModel planetModel, Constraints constraints) { + public static GeoPoint randomGeoPoint(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_POINT_ITERATIONS) { - double lat = randomDouble() * Math.PI / 2; + double lat = RandomizedTest.randomDouble() * Math.PI / 2; if (random().nextBoolean()) { lat = (-1) * lat; } - double lon = randomDouble() * Math.PI; + double lon = RandomizedTest.randomDouble() * Math.PI; if (random().nextBoolean()) { lon = (-1) * lon; } @@ -195,7 +203,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param planetModel The planet model. * @return The random generated GeoAreaShape. */ - public GeoAreaShape randomGeoAreaShape(int shapeType, PlanetModel planetModel) { + public static GeoAreaShape randomGeoAreaShape(int shapeType, PlanetModel planetModel) { GeoAreaShape geoAreaShape = null; while (geoAreaShape == null) { geoAreaShape = randomGeoAreaShape(shapeType, planetModel, new Constraints()); @@ -212,7 +220,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoAreaShape. */ - public GeoAreaShape randomGeoAreaShape( + public static GeoAreaShape randomGeoAreaShape( int shapeType, PlanetModel planetModel, Constraints constraints) { return (GeoAreaShape) randomGeoShape(shapeType, planetModel, constraints); } @@ -224,7 +232,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param planetModel The planet model. * @return The random generated GeoShape. */ - public GeoShape randomGeoShape(int shapeType, PlanetModel planetModel) { + public static GeoShape randomGeoShape(int shapeType, PlanetModel planetModel) { GeoShape geoShape = null; while (geoShape == null) { geoShape = randomGeoShape(shapeType, planetModel, new Constraints()); @@ -241,7 +249,8 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoShape. */ - public GeoShape randomGeoShape(int shapeType, PlanetModel planetModel, Constraints constraints) { + public static GeoShape randomGeoShape( + int shapeType, PlanetModel planetModel, Constraints constraints) { switch (shapeType) { case CONVEX_POLYGON: { @@ -312,7 +321,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPointShape. */ - private GeoPointShape point(PlanetModel planetModel, Constraints constraints) { + private static GeoPointShape point(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -344,7 +353,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoCircle. */ - private GeoCircle circle(PlanetModel planetModel, Constraints constraints) { + private static GeoCircle circle(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -377,7 +386,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoCircle. */ - private GeoCircle exactCircle(PlanetModel planetModel, Constraints constraints) { + private static GeoCircle exactCircle(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -411,7 +420,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoBBox. */ - private GeoBBox rectangle(PlanetModel planetModel, Constraints constraints) { + private static GeoBBox rectangle(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { @@ -451,7 +460,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated degenerated GeoPath. */ - private GeoPath line(PlanetModel planetModel, Constraints constraints) { + private static GeoPath line(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -483,7 +492,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPath. */ - private GeoPath path(PlanetModel planetModel, Constraints constraints) { + private static GeoPath path(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -516,7 +525,8 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoCompositeMembershipShape. */ - private GeoCompositeAreaShape collection(PlanetModel planetModel, Constraints constraints) { + private static GeoCompositeAreaShape collection( + PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -544,7 +554,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPolygon. */ - private GeoPolygon convexPolygon(PlanetModel planetModel, Constraints constraints) { + private static GeoPolygon convexPolygon(PlanetModel planetModel, Constraints constraints) { int vertexCount = random().nextInt(4) + 3; int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { @@ -575,7 +585,8 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPolygon. */ - private GeoPolygon convexPolygonWithHoles(PlanetModel planetModel, Constraints constraints) { + private static GeoPolygon convexPolygonWithHoles( + PlanetModel planetModel, Constraints constraints) { int vertexCount = random().nextInt(4) + 3; int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { @@ -633,7 +644,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param pointConstraints The given constraints that a point must comply. * @return The random generated GeoPolygon. */ - private List concavePolygonHoles( + private static List concavePolygonHoles( PlanetModel planetModel, GeoPolygon polygon, Constraints holeConstraints, @@ -681,7 +692,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPolygon. */ - private GeoPolygon concavePolygon(PlanetModel planetModel, Constraints constraints) { + private static GeoPolygon concavePolygon(PlanetModel planetModel, Constraints constraints) { int vertexCount = random().nextInt(4) + 3; int iterations = 0; @@ -715,7 +726,8 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPolygon. */ - private GeoPolygon concavePolygonWithHoles(PlanetModel planetModel, Constraints constraints) { + private static GeoPolygon concavePolygonWithHoles( + PlanetModel planetModel, Constraints constraints) { int vertexCount = random().nextInt(4) + 3; int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { @@ -770,7 +782,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPolygon. */ - private GeoPolygon complexPolygon(PlanetModel planetModel, Constraints constraints) { + private static GeoPolygon complexPolygon(PlanetModel planetModel, Constraints constraints) { int polygonsCount = random().nextInt(2) + 1; int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { @@ -807,7 +819,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPolygon. */ - private GeoPolygon simpleConvexPolygon(PlanetModel planetModel, Constraints constraints) { + private static GeoPolygon simpleConvexPolygon(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -838,7 +850,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated GeoPolygon. */ - private GeoPolygon concaveSimplePolygon(PlanetModel planetModel, Constraints constraints) { + private static GeoPolygon concaveSimplePolygon(PlanetModel planetModel, Constraints constraints) { int iterations = 0; while (iterations < MAX_SHAPE_ITERATIONS) { iterations++; @@ -870,7 +882,8 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param constraints The given constraints. * @return The random generated List of GeoPoints. */ - private List points(int count, PlanetModel planetModel, Constraints constraints) { + private static List points( + int count, PlanetModel planetModel, Constraints constraints) { List geoPoints = new ArrayList<>(count); for (int i = 0; i < count; i++) { GeoPoint point = randomGeoPoint(planetModel, constraints); @@ -889,7 +902,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param shape The polygon to check. * @return True if the polygon contains antipodal points. */ - private boolean isConcave(PlanetModel planetModel, GeoPolygon shape) { + private static boolean isConcave(PlanetModel planetModel, GeoPolygon shape) { return (shape.isWithin(planetModel.NORTH_POLE) && shape.isWithin(planetModel.SOUTH_POLE)) || (shape.isWithin(planetModel.MAX_X_POLE) && shape.isWithin(planetModel.MIN_X_POLE)) || (shape.isWithin(planetModel.MAX_Y_POLE) && shape.isWithin(planetModel.MIN_Y_POLE)); @@ -903,7 +916,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param shape The polygon to check. * @return True if the polygon dies not contains antipodal points. */ - private boolean isConvex(PlanetModel planetModel, GeoPolygon shape) { + private static boolean isConvex(PlanetModel planetModel, GeoPolygon shape) { return !isConcave(planetModel, shape); } @@ -912,8 +925,8 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * * @return the cutoff angle. */ - private double randomCutoffAngle() { - return randomDouble() * Math.PI; + private static double randomCutoffAngle() { + return RandomizedTest.randomDouble() * Math.PI; } /** @@ -922,7 +935,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * @param points The points to order. * @return The list of ordered points anti-clockwise. */ - protected List orderPoints(List points) { + protected static List orderPoints(List points) { double x = 0; double y = 0; double z = 0; @@ -964,7 +977,7 @@ public class RandomGeo3dShapeGenerator extends LuceneTestCase { * Class that holds the constraints that are given to build shapes. It consists in a list of * GeoAreaShapes and relationships the new shape needs to satisfy. */ - class Constraints extends HashMap { + static class Constraints extends HashMap { /** * Check if the shape is valid under the constraints.