This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit caf0bb37276c54fb9f4bfe69d753bf8f9352ee19 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Feb 20 18:27:43 2024 +0100 Cleanup the identification of slow tests. --- .../apache/sis/feature/FeatureMemoryBenchmark.java | 6 +++++- .../org.apache.sis.metadata/main/module-info.java | 1 + .../org/apache/sis/metadata/sql/TestDatabase.java | 6 +----- .../referencing/factory/sql/EPSGFactoryTest.java | 3 +++ .../referencing/factory/sql/EPSGInstallerTest.java | 3 +++ .../projection/MercatorMethodComparison.java | 4 ++++ .../{Benchmark.java => ProjectionBenchmark.java} | 14 ++++++++++---- .../referencing/operation/provider/NTv2Test.java | 6 ++++-- .../sis/test/integration/ConsistencyTest.java | 6 +++--- .../sis/storage/test/CoverageReadConsistency.java | 3 +++ .../sis/test/{Performance.java => Benchmark.java} | 21 +++++++++++++++------ .../test/org/apache/sis/test/TestCase.java | 10 ++++++++++ .../org/apache/sis/util/collection/CacheTest.java | 6 ++++-- .../apache/sis/util/collection/RangeSetTest.java | 4 ++-- 14 files changed, 68 insertions(+), 25 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureMemoryBenchmark.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureMemoryBenchmark.java index 6c50ee2cbf..3c9e34dc48 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureMemoryBenchmark.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureMemoryBenchmark.java @@ -23,6 +23,9 @@ import java.util.Map; import java.util.Random; import org.apache.sis.util.internal.StandardDateFormat; +// Test dependencies +import org.apache.sis.test.Benchmark; + /** * Compares {@link org.apache.sis.feature} memory usage with a plain {@link HashMap}. @@ -34,6 +37,7 @@ import org.apache.sis.util.internal.StandardDateFormat; * <li>{@code "latitude"} : {@link Float}</li> * </ul> */ +@Benchmark public final class FeatureMemoryBenchmark { /** * Features created by the benchmark. We need to keep reference to all of them @@ -174,7 +178,7 @@ public final class FeatureMemoryBenchmark { final boolean useSIS = arg.equalsIgnoreCase("sis"); boolean isSimple = false; if (useSIS || (isSimple = arg.equalsIgnoreCase("simple")) || arg.equalsIgnoreCase("complex")) { - final FeatureMemoryBenchmark b = new FeatureMemoryBenchmark(useSIS, isSimple); + final var b = new FeatureMemoryBenchmark(useSIS, isSimple); long time = System.nanoTime(); b.run(); time = System.nanoTime() - time; diff --git a/endorsed/src/org.apache.sis.metadata/main/module-info.java b/endorsed/src/org.apache.sis.metadata/main/module-info.java index 40f5fd8033..f87ce7e2bc 100644 --- a/endorsed/src/org.apache.sis.metadata/main/module-info.java +++ b/endorsed/src/org.apache.sis.metadata/main/module-info.java @@ -34,6 +34,7 @@ module org.apache.sis.metadata { requires transitive java.sql; requires transitive jakarta.xml.bind; requires transitive org.apache.sis.util; + requires static org.postgresql.jdbc; /* * Services needed or implemented by this module. diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java index 8b0ba0dbea..6e4a998542 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java @@ -35,8 +35,6 @@ import org.apache.sis.util.Debug; // Test dependencies import static org.junit.jupiter.api.Assumptions.assumeFalse; -import static org.junit.jupiter.api.Assumptions.assumeTrue; -import org.apache.sis.test.TestCase; /** @@ -230,7 +228,6 @@ public class TestDatabase implements AutoCloseable { * This method returns only if all the following conditions are true: * * <ol> - * <li>{@link TestCase#RUN_EXTENSIVE_TESTS} is {@code true} (for reducing the risk of messing with user installation).</li> * <li>A PostgreSQL server is running on the local host and listening to the default port.</li> * <li>A database named {@value #NAME} exists.</li> * <li>A role with Unix user name exists and can connect to the database without password.</li> @@ -252,8 +249,7 @@ public class TestDatabase implements AutoCloseable { * @see <a href="https://sis.apache.org/source.html#postgres">Configuring PostgreSQL for Apache SIS tests</a> */ public static TestDatabase createOnPostgreSQL(final String schema, final boolean create) throws SQLException { - assumeTrue(TestCase.RUN_EXTENSIVE_TESTS, "Extensive tests not enabled."); - final PGSimpleDataSource ds = new PGSimpleDataSource(); + final var ds = new PGSimpleDataSource(); // Server default to "localhost". ds.setDatabaseName(NAME); ds.setApplicationName("Apache SIS test database"); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java index 2612992e7b..ab740f9b77 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java @@ -56,6 +56,7 @@ import org.apache.sis.referencing.operation.AbstractCoordinateOperation; import org.apache.sis.referencing.factory.IdentifiedObjectFinder; // Test dependencies +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.Disabled; @@ -68,6 +69,7 @@ import org.apache.sis.referencing.factory.TestFactorySource; import static org.apache.sis.test.Assertions.assertNotDeepEquals; import static org.apache.sis.referencing.Assertions.assertEpsgNameAndIdentifierEqual; import static org.apache.sis.referencing.Assertions.assertAliasTipEquals; +import static org.apache.sis.test.TestCase.TAG_SLOW; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import static org.opengis.test.Assertions.assertAxisDirectionsEqual; @@ -547,6 +549,7 @@ public final class EPSGFactoryTest extends TestCaseWithLogs { * @throws FactoryException if an error occurred while querying the factory. */ @Test + @Tag(TAG_SLOW) public void testAuthorityCodes() throws FactoryException { final EPSGFactory factory = dataEPSG.factory(); /* diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java index d1357580ac..5efbbe76f9 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java @@ -38,6 +38,7 @@ import org.apache.sis.util.internal.Constants; import org.apache.sis.metadata.sql.util.Reflection; // Test dependencies +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -118,7 +119,9 @@ public final class EPSGInstallerTest extends TestCaseWithLogs { * @throws Exception if an error occurred while creating the database. */ @Test + @Tag(TAG_SLOW) public void testCreationOnDerby() throws Exception { + assumeTrue(RUN_EXTENSIVE_TESTS, "Extensive tests not enabled."); final InstallationScriptProvider scripts = getScripts(); // Needs to be invoked first. try (TestDatabase db = TestDatabase.create("EPSGInstaller")) { createAndTest(db.source, scripts); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java index 57c289d346..3ad13097d8 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MercatorMethodComparison.java @@ -28,6 +28,9 @@ import org.apache.sis.referencing.internal.Resources; import org.apache.sis.metadata.internal.ReferencingServices; import static org.apache.sis.util.internal.StandardDateFormat.NANOS_PER_SECOND; +// Test dependencies +import org.apache.sis.test.Benchmark; + /** * Implements two alternative methods to compute φ in Mercator projection. @@ -54,6 +57,7 @@ import static org.apache.sis.util.internal.StandardDateFormat.NANOS_PER_SECOND; * * @author Martin Desruisseaux (Geomatys) */ +@Benchmark public final class MercatorMethodComparison { /** * Where to print the outputs of this class. diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/Benchmark.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/ProjectionBenchmark.java similarity index 96% rename from endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/Benchmark.java rename to endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/ProjectionBenchmark.java index af28ff093a..5bcf8d38af 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/Benchmark.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/ProjectionBenchmark.java @@ -34,6 +34,9 @@ import org.apache.sis.referencing.operation.transform.LinearTransform; import org.apache.sis.referencing.operation.transform.MathTransforms; import org.apache.sis.referencing.operation.transform.MathTransformFactoryMock; +// Test dependencies +import org.apache.sis.test.Benchmark; + /** * Measures the performance of a given map projection implementation. @@ -46,8 +49,8 @@ import org.apache.sis.referencing.operation.transform.MathTransformFactoryMock; * * @author Martin Desruisseaux (Geomatys) */ -@SuppressWarnings("UseOfSystemOutOrSystemErr") -public final class Benchmark { +@Benchmark +public final class ProjectionBenchmark { /** * Runs the benchmark and prints the time result to the standard output. * Edit this method for measuring the performance of a different map projection implementation. @@ -56,7 +59,7 @@ public final class Benchmark { * @throws Exception if an error occurred while creating the map projection, projecting a point, <i>etc.</i> */ public static void main(String[] args) throws Exception { - final Benchmark benchmark = new Benchmark( // Put on next line the provider of the projection to benchmark. + final var benchmark = new ProjectionBenchmark( // Put on next line the provider of the projection to benchmark. new org.apache.sis.referencing.operation.provider.LambertConformal2SP(), 8, // Central meridian 25, // Standard parallel 1 @@ -113,7 +116,7 @@ public final class Benchmark { /** * Prepares benchmarking for the map projection created by the given provider. */ - private Benchmark(final AbstractProvider provider, + private ProjectionBenchmark(final AbstractProvider provider, final double centralMeridian, final double standardParallel1, final double standardParallel2) throws FactoryException, NoninvertibleTransformException @@ -211,6 +214,7 @@ public final class Benchmark { /** * Runs the benchmark on the complete map projection, including the linear parts. */ + @SuppressWarnings("UseOfSystemOutOrSystemErr") final void runComplete(final double[] sources, final double[] targets) throws TransformException { long time = System.nanoTime(); projection.transform(sources, 0, targets, 0, NUM_POINTS); @@ -224,6 +228,7 @@ public final class Benchmark { * Runs the benchmark only on the non-linear part of the map projection, * ignoring the linear parts. */ + @SuppressWarnings("UseOfSystemOutOrSystemErr") final void runKernel(final double[] sources, final double[] targets) throws TransformException { normalize.transform(sources, 0, targets, 0, NUM_POINTS); long time = System.nanoTime(); @@ -266,6 +271,7 @@ public final class Benchmark { /** * Prints statistics about measured time. */ + @SuppressWarnings("UseOfSystemOutOrSystemErr") private void printStatistics() throws IOException { System.out.println(); StatisticsFormat.getInstance().format(new Statistics[] {forward.performance, inverse.performance}, System.out); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/NTv2Test.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/NTv2Test.java index 33798e6b2c..fec3ece77d 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/NTv2Test.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/NTv2Test.java @@ -41,10 +41,11 @@ import org.apache.sis.parameter.Parameters; import org.apache.sis.system.DataDirectory; // Test dependencies +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assertions.*; -import org.apache.sis.referencing.operation.gridded.LoadedGridTest; +import static org.apache.sis.test.TestCase.TAG_SLOW; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import static org.opengis.test.Assertions.assertMatrixEquals; @@ -183,8 +184,9 @@ public final class NTv2Test extends DatumShiftTestCase { * @throws Exception if an error occurred while loading or computing the grid, or while testing transformations. */ @Test + @Tag(TAG_SLOW) public void testMultiGrids() throws Exception { - assumeTrue(RUN_EXTENSIVE_TESTS); + assumeTrue(RUN_EXTENSIVE_TESTS, "Extensive tests not enabled."); assumeTrue(DataDirectory.getenv() != null); final Parameters pg = Parameters.castOrWrap(new NTv2().getParameters().createValue()); pg.getOrCreate(NTv2.FILE).setValue(new URI(MULTIGRID_TEST_FILE)); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java index 009481ae9e..1209abd486 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java @@ -41,9 +41,10 @@ import org.apache.sis.io.wkt.UnformattableObjectException; import org.apache.sis.util.iso.DefaultNameSpace; // Test dependencies +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.apache.sis.test.TestCase; @@ -55,8 +56,6 @@ import org.apache.sis.test.TestCase; * <li>Format in WKT, parse, reformat again and verify that we get the same WKT string.</li> * </ul> * - * This test is executed only if {@link #RUN_EXTENSIVE_TESTS} is {@code true}. - * * @author Martin Desruisseaux (Geomatys) */ public final class ConsistencyTest extends TestCase { @@ -108,6 +107,7 @@ public final class ConsistencyTest extends TestCase { * @throws FactoryException if an error other than "unsupported operation method" occurred. */ @Test + @Tag(TAG_SLOW) public void testCoordinateReferenceSystems() throws FactoryException { assumeTrue(RUN_EXTENSIVE_TESTS, "Extensive tests not enabled."); final WKTFormat v1 = new WKTFormat(); diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/CoverageReadConsistency.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/CoverageReadConsistency.java index b3d94e842a..d4ac138cfa 100644 --- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/CoverageReadConsistency.java +++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/CoverageReadConsistency.java @@ -48,6 +48,7 @@ import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import org.apache.sis.test.TestUtilities; import org.apache.sis.test.TestCase; +import org.apache.sis.test.Benchmark; /** @@ -132,6 +133,7 @@ public abstract class CoverageReadConsistency<S extends DataStore> extends TestC * Statistics about execution time. * Created only in benchmark mode. */ + @Benchmark private List<Statistics> statistics; /** @@ -478,6 +480,7 @@ nextSlice: for (;;) { * Prints statistics about execution time (in milliseconds) after all tests completed. */ @AfterAll + @Benchmark @SuppressWarnings("UseOfSystemOutOrSystemErr") public void printDurations() { if (statistics != null) { diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Performance.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Benchmark.java similarity index 60% rename from endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Performance.java rename to endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Benchmark.java index 1dfccb7d10..bfb77f9066 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Performance.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/Benchmark.java @@ -24,15 +24,24 @@ import java.lang.annotation.Target; /** - * Annotates methods that can be used for testing the performance of a class. - * The annotated methods may or may not be executed in normal SIS builds. - * Some methods may be executed only manually before and after an implementation change, - * in order to test the impact on performance. + * Annotates classes, methods or fields that can be used for benchmarking. + * The annotated methods may also be JUnit tests, but not necessarily. + * If the method is also a test, then it should also be annotated with {@code @Tag(Benchmark.TAG)}. + * + * <p>This annotation is for documentation purposes only. Some annotated methods may be executed manually + * before and after an implementation change, in order to test the impact on performance.</p> * * @author Martin Desruisseaux (Geomatys) */ @Documented -@Target(ElementType.METHOD) @Retention(RetentionPolicy.SOURCE) -public @interface Performance { +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) +public @interface Benchmark { + /** + * The value to use in {@link org.junit.jupiter.api.Tag} annotations + * for tests that are also benchmarks. + * + * @see TestCase#TAG_SLOW + */ + String TAG = "Benchmark"; } diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java index 4bd6e7c8b7..42190f05e0 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java @@ -97,10 +97,20 @@ public abstract class TestCase { */ public static final boolean VERBOSE; + /** + * Tag for tests that are slow. + * All tests annotated with this tag should check for the {@link #RUN_EXTENSIVE_TESTS} flag. + * + * @see Benchmark#TAG + */ + public static final String TAG_SLOW = "Slow"; + /** * {@code true} if the {@value org.apache.sis.test.TestConfiguration#EXTENSIVE_TESTS_KEY} * system property is set to {@code true}. * If {@code true}, then Apache SIS will run some tests which were normally skipped because they are slow. + * + * <p>All tests using this condition should be annotated with {@code @Tag(TAG_SLOW)}.</p> */ public static final boolean RUN_EXTENSIVE_TESTS; diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/CacheTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/CacheTest.java index 3335ad6953..6c8d631772 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/CacheTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/CacheTest.java @@ -32,11 +32,12 @@ import org.apache.sis.util.CharSequences; import org.apache.sis.util.internal.StandardDateFormat; // Test dependencies +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.test.TestUtilities; -import org.apache.sis.test.Performance; import static org.apache.sis.test.Assertions.assertMapEquals; +import org.apache.sis.test.Benchmark; /** @@ -204,7 +205,8 @@ public final class CacheTest extends TestCaseWithGC { * @throws InterruptedException if the test has been interrupted. */ @Test - @Performance + @Benchmark + @Tag(Benchmark.TAG) public void stress() throws InterruptedException { final int count = 5000; final Cache<Integer,IntObject> cache = new Cache<>(); diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/RangeSetTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/RangeSetTest.java index 08a006d0f8..69e7c2b88c 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/RangeSetTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/RangeSetTest.java @@ -32,9 +32,9 @@ import static org.apache.sis.util.internal.StandardDateFormat.NANOS_PER_SECOND; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.test.TestCase; -import org.apache.sis.test.Performance; import org.apache.sis.test.TestUtilities; import static org.apache.sis.test.Assertions.assertSerializedEquals; +import org.apache.sis.test.Benchmark; /** @@ -572,7 +572,7 @@ public final class RangeSetTest extends TestCase { * * @throws InterruptedException if the test has been interrupted. */ - @Performance + @Benchmark public void stress() throws InterruptedException { final Random r = TestUtilities.createRandomNumberGenerator(); for (int p=0; p<10; p++) {