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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new 0d9f40a5a4 Try to reduce the amount of warnings by checking if the EPSG database is present before to execute tests that may require it. The same messages was sometime logged many times because of race conditions when many tests are executed in parallel. It was causing not only log pollution, but also random test failures for some tests that verify the logs. 0d9f40a5a4 is described below commit 0d9f40a5a494153be5647527689b3899eec97465 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Thu Oct 10 10:57:37 2024 +0200 Try to reduce the amount of warnings by checking if the EPSG database is present before to execute tests that may require it. The same messages was sometime logged many times because of race conditions when many tests are executed in parallel. It was causing not only log pollution, but also random test failures for some tests that verify the logs. This commit does not add EPSG check for all tests, but only for the tests that seem to cause redundant logs more often. --- .../apache/sis/geometry/AbstractEnvelopeTest.java | 4 +- .../apache/sis/geometry/CoordinateFormatTest.java | 52 +++++++++++----------- .../org/apache/sis/geometry/EnvelopesTest.java | 11 +++++ .../sis/geometry/GeneralDirectPositionTest.java | 4 +- .../apache/sis/geometry/GeneralEnvelopeTest.java | 4 +- .../apache/sis/geometry/ImmutableEnvelopeTest.java | 6 +-- .../org/apache/sis/geometry/TransformTestCase.java | 4 +- .../test/org/apache/sis/io/wkt/CRSParserTest.java | 11 +++++ .../org/apache/sis/io/wkt/ComparisonWithEPSG.java | 4 +- .../sis/io/wkt/GeodeticObjectParserTest.java | 4 +- .../org/apache/sis/io/wkt/WKTDictionaryTest.java | 4 +- .../test/org/apache/sis/io/wkt/WKTFormatTest.java | 4 +- .../sis/referencing/AuthorityFactoriesTest.java | 10 +++++ .../test/org/apache/sis/referencing/CRSTest.java | 10 +++++ .../org/apache/sis/referencing/CommonCRSTest.java | 3 +- .../sis/referencing/EPSGDependentTestCase.java | 52 ++++++++++++++++++++++ .../sis/referencing/StandardDefinitionsTest.java | 3 +- 17 files changed, 141 insertions(+), 49 deletions(-) diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java index cf7cd35615..5049ee08d5 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java @@ -25,7 +25,7 @@ import org.opengis.geometry.DirectPosition; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import static org.opengis.test.Validators.validate; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import static org.apache.sis.referencing.Assertions.assertContains; import static org.apache.sis.referencing.Assertions.assertDisjoint; import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84; @@ -37,7 +37,7 @@ import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84; * * @author Martin Desruisseaux (IRD, Geomatys) */ -public final class AbstractEnvelopeTest extends TestCase { +public final class AbstractEnvelopeTest extends EPSGDependentTestCase { /** * Creates a new test case. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/CoordinateFormatTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/CoordinateFormatTest.java index 3fcb565d69..373939fa55 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/CoordinateFormatTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/CoordinateFormatTest.java @@ -30,7 +30,7 @@ import org.apache.sis.measure.Units; // Test dependencies import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import org.apache.sis.test.mock.VerticalCRSMock; import org.apache.sis.referencing.crs.HardCodedCRS; import org.apache.sis.referencing.operation.HardCodedConversions; @@ -44,7 +44,7 @@ import org.apache.sis.referencing.operation.HardCodedConversions; * * @see org.apache.sis.measure.AngleFormatTest */ -public final class CoordinateFormatTest extends TestCase { +public final class CoordinateFormatTest extends EPSGDependentTestCase { /** * Creates a new test case. */ @@ -65,8 +65,8 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testFormatUnknownCRS() { - final CoordinateFormat format = new CoordinateFormat(null, null); - GeneralDirectPosition position = new GeneralDirectPosition(23.78, -12.74, 127.9, 3.25); + final var format = new CoordinateFormat(null, null); + var position = new GeneralDirectPosition(23.78, -12.74, 127.9, 3.25); assertEquals("23.78 -12.74 127.9 3.25", format.format(position)); /* * Try another point having a different number of position @@ -90,8 +90,8 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testParseUnknownCRS() throws ParseException { - final CoordinateFormat format = new CoordinateFormat(null, null); - final ParsePosition charPos = new ParsePosition(0); + final var format = new CoordinateFormat(null, null); + final var charPos = new ParsePosition(0); DirectPosition position = format.parse("23.78 -12.74 127.9 3.25", charPos); assertArrayEquals(new double[] {23.78, -12.74, 127.9, 3.25}, position.getCoordinates()); assertEquals(-1, charPos.getErrorIndex()); @@ -123,9 +123,9 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testFormatVertical() { - final CoordinateFormat format = new CoordinateFormat(Locale.US, null); + final var format = new CoordinateFormat(Locale.US, null); format.setDefaultCRS(VerticalCRSMock.HEIGHT); - DirectPosition1D position = new DirectPosition1D(100); + var position = new DirectPosition1D(100); assertEquals("100 m", format.format(position)); position.setCoordinateReferenceSystem(VerticalCRSMock.HEIGHT_ft); @@ -140,7 +140,7 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testFormatProjected() { - final CoordinateFormat format = new CoordinateFormat(Locale.US, null); + final var format = new CoordinateFormat(Locale.US, null); format.setDefaultCRS(HardCodedConversions.mercator()); assertEquals("100 m W 300 m N", format.format(new DirectPosition2D(-100, 300))); assertEquals("200 m E 100 m S", format.format(new DirectPosition2D(200, -100))); @@ -154,7 +154,7 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testParseProjected() throws ParseException { - final CoordinateFormat format = new CoordinateFormat(Locale.US, null); + final var format = new CoordinateFormat(Locale.US, null); format.setDefaultCRS(HardCodedConversions.mercator()); DirectPosition pos = format.parse("100 m W 300 m N", new ParsePosition(0)); assertArrayEquals(new double[] {-100, 300}, pos.getCoordinates()); @@ -172,14 +172,14 @@ public final class CoordinateFormatTest extends TestCase { * Use a fixed timezone and date pattern for portability. * Epoch is November 17, 1858 at 00:00 UTC. */ - final CoordinateFormat format = new CoordinateFormat(Locale.FRANCE, TimeZone.getTimeZone("GMT+01:00")); + final var format = new CoordinateFormat(Locale.FRANCE, TimeZone.getTimeZone("GMT+01:00")); final String anglePattern = "DD°MM.m′"; final String datePattern = "dd-MM-yyyy HH:mm"; format.applyPattern(Angle.class, anglePattern); format.applyPattern(Date.class, datePattern); assertEquals(anglePattern, format.getPattern(Angle.class)); assertEquals( datePattern, format.getPattern(Date .class)); - final GeneralDirectPosition position = new GeneralDirectPosition(23.78, -12.74, 127.9, 54000.25); + final var position = new GeneralDirectPosition(23.78, -12.74, 127.9, 54000.25); position.setCoordinateReferenceSystem(HardCodedCRS.GEOID_4D); assertEquals("23°46,8′E 12°44,4′S 127,9 m 22-09-2006 07:00", format.format(position)); /* @@ -208,7 +208,7 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testParseGeographic4D() throws ParseException { - final CoordinateFormat format = new CoordinateFormat(Locale.FRANCE, TimeZone.getTimeZone("GMT+01:00")); + final var format = new CoordinateFormat(Locale.FRANCE, TimeZone.getTimeZone("GMT+01:00")); format.applyPattern(Date.class, "dd-MM-yyyy HH:mm"); format.setDefaultCRS(HardCodedCRS.GEOID_4D); final ParsePosition charPos = new ParsePosition(11); @@ -240,8 +240,8 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testParseInDefaultLocale() throws IOException, ParseException { - CoordinateFormat format = new CoordinateFormat(); - StringBuffer buffer = new StringBuffer(); + var format = new CoordinateFormat(); + var buffer = new StringBuffer(); format.format(new DirectPosition2D(-3, 4), buffer); ParsePosition charPos = new ParsePosition(0); @@ -258,7 +258,7 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testParseFromOffset() throws ParseException { - CoordinateFormat coordinateFormat = new CoordinateFormat(Locale.CANADA, null); + var coordinateFormat = new CoordinateFormat(Locale.CANADA, null); coordinateFormat.setDefaultCRS(VerticalCRSMock.BAROMETRIC_HEIGHT); ParsePosition charPos = new ParsePosition(7); DirectPosition position = coordinateFormat.parse("[skip] 12", charPos); @@ -273,7 +273,7 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testGetPattern() { - CoordinateFormat coordinateFormat = new CoordinateFormat(Locale.UK, null); + var coordinateFormat = new CoordinateFormat(Locale.UK, null); assertEquals("#,##0.###", coordinateFormat.getPattern(Float.class)); assertNull(coordinateFormat.getPattern(Object.class)); assertNull(coordinateFormat.getPattern(Class.class)); @@ -285,7 +285,7 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testApplyPattern() { - CoordinateFormat format = new CoordinateFormat(); + var format = new CoordinateFormat(); assertFalse(format.applyPattern(Object.class, "A dummy pattern")); assertFalse(format.applyPattern(Class.class, "A dummy pattern")); } @@ -295,8 +295,8 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testSetGroundPrecision() { - final CoordinateFormat format = new CoordinateFormat(Locale.FRANCE, null); - final DirectPosition2D pos = new DirectPosition2D(40.123456789, 9.87654321); + final var format = new CoordinateFormat(Locale.FRANCE, null); + final var pos = new DirectPosition2D(40.123456789, 9.87654321); format.setDefaultCRS(HardCodedCRS.WGS84_LATITUDE_FIRST); format.setGroundPrecision(Quantities.create(0.01, Units.GRAD)); assertEquals("40°07,4′N 9°52,6′E", format.format(pos)); @@ -310,8 +310,8 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testSetPrecisions() { - final CoordinateFormat format = new CoordinateFormat(Locale.FRANCE, null); - final DirectPosition2D pos = new DirectPosition2D(40.123456789, 9.87654321); + final var format = new CoordinateFormat(Locale.FRANCE, null); + final var pos = new DirectPosition2D(40.123456789, 9.87654321); format.setDefaultCRS(HardCodedCRS.WGS84_LATITUDE_FIRST); format.setPrecisions(0.05, 0.0001); assertEquals("40°07′N 9°52′35,6″E", format.format(pos)); @@ -329,8 +329,8 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testSetGroundAccuracy() throws ParseException { - final CoordinateFormat format = new CoordinateFormat(Locale.FRANCE, null); - final DirectPosition2D pos = new DirectPosition2D(40.123456789, 9.87654321); + final var format = new CoordinateFormat(Locale.FRANCE, null); + final var pos = new DirectPosition2D(40.123456789, 9.87654321); format.setDefaultCRS(HardCodedCRS.WGS84_LATITUDE_FIRST); format.setPrecisions(0.05, 0.0001); format.setGroundAccuracy(Quantities.create(3, Units.KILOMETRE)); @@ -347,8 +347,8 @@ public final class CoordinateFormatTest extends TestCase { */ @Test public void testAutomaticChangeOfUnits() throws ParseException { - final CoordinateFormat format = new CoordinateFormat(Locale.CANADA, null); - final DirectPosition2D pos = new DirectPosition2D(400000, -600000); + final var format = new CoordinateFormat(Locale.CANADA, null); + final var pos = new DirectPosition2D(400000, -600000); format.setDefaultCRS(HardCodedConversions.mercator()); /* * Test with a precision larger than 1 km, which instruct diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/EnvelopesTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/EnvelopesTest.java index 51dc3cee76..23624aec8d 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/EnvelopesTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/EnvelopesTest.java @@ -41,8 +41,10 @@ import org.apache.sis.referencing.privy.AffineTransform2D; // Test dependencies import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeAll; import static org.junit.jupiter.api.Assertions.*; import static org.opengis.test.Validators.validate; +import org.apache.sis.referencing.EPSGDependentTestCase; import org.apache.sis.referencing.operation.HardCodedConversions; import org.apache.sis.referencing.crs.HardCodedCRS; import static org.apache.sis.referencing.Assertions.assertEnvelopeEquals; @@ -62,6 +64,15 @@ public final class EnvelopesTest extends TransformTestCase<GeneralEnvelope> { public EnvelopesTest() { } + /** + * Forces the check of whether of EPSG database exists before to start any tests. + * This is done for avoiding race conditions logging the same message many times. + */ + @BeforeAll + public static void forceCheckForEPSG() { + EPSGDependentTestCase.forceCheckForEPSG(); + } + /** * Creates an envelope for the given CRS and coordinate values. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralDirectPositionTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralDirectPositionTest.java index 7fcd46c1da..56c07e61fb 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralDirectPositionTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralDirectPositionTest.java @@ -22,7 +22,7 @@ import org.apache.sis.io.wkt.Formatter; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import static org.opengis.test.Validators.validate; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import static org.apache.sis.test.Assertions.assertSerializedEquals; import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84; @@ -32,7 +32,7 @@ import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84; * * @author Martin Desruisseaux (IRD, Geomatys) */ -public final class GeneralDirectPositionTest extends TestCase { +public final class GeneralDirectPositionTest extends EPSGDependentTestCase { /** * Creates a new test case. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java index 5ecf0ba1bd..91ecdf53cd 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java @@ -28,7 +28,7 @@ import org.apache.sis.math.MathFunctions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import static org.opengis.test.Validators.validate; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import org.apache.sis.referencing.crs.HardCodedCRS; import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84; import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84_LATITUDE_FIRST; @@ -46,7 +46,7 @@ import static org.apache.sis.referencing.Assertions.assertWktEquals; * @author Martin Desruisseaux (IRD, Geomatys) * @author Johann Sorel (Geomatys) */ -public class GeneralEnvelopeTest extends TestCase { +public class GeneralEnvelopeTest extends EPSGDependentTestCase { /** * Tolerance threshold for floating point comparisons. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/ImmutableEnvelopeTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/ImmutableEnvelopeTest.java index 8f3a229e7f..194a5ac40f 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/ImmutableEnvelopeTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/ImmutableEnvelopeTest.java @@ -20,7 +20,7 @@ package org.apache.sis.geometry; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import static org.opengis.test.Validators.validate; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import static org.apache.sis.test.Assertions.assertSerializedEquals; import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84; @@ -32,7 +32,7 @@ import static org.apache.sis.referencing.crs.HardCodedCRS.WGS84; * * @author Martin Desruisseaux (Geomatys) */ -public final class ImmutableEnvelopeTest extends TestCase { +public final class ImmutableEnvelopeTest extends EPSGDependentTestCase { /** * Creates a new test case. */ @@ -44,7 +44,7 @@ public final class ImmutableEnvelopeTest extends TestCase { */ @Test public void testSerialization() { - final ImmutableEnvelope e1 = new ImmutableEnvelope( + final var e1 = new ImmutableEnvelope( new double[] {-20, -10}, new double[] { 20, 10}, WGS84); final ImmutableEnvelope e2 = assertSerializedEquals(e1); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/TransformTestCase.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/TransformTestCase.java index 3909c420be..4eeabc0c6a 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/TransformTestCase.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/TransformTestCase.java @@ -37,7 +37,7 @@ import static org.apache.sis.referencing.privy.Formulas.LINEAR_TOLERANCE; // Test dependencies import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import org.apache.sis.referencing.crs.HardCodedCRS; import org.apache.sis.referencing.operation.HardCodedConversions; @@ -51,7 +51,7 @@ import org.apache.sis.referencing.operation.HardCodedConversions; * * @param <G> the type of geometric objects, either {@link GeneralEnvelope} or {@link java.awt.geom.Rectangle2D}. */ -public abstract class TransformTestCase<G> extends TestCase { +public abstract class TransformTestCase<G> extends EPSGDependentTestCase { /** * Creates an envelope or rectangle for the given CRS and coordinate values. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/CRSParserTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/CRSParserTest.java index 70d4ed59c9..07f34b9542 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/CRSParserTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/CRSParserTest.java @@ -26,6 +26,7 @@ import org.apache.sis.system.Loggers; // Test dependencies import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.extension.ExtendWith; @@ -33,6 +34,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.opengis.test.referencing.WKTParserTest; import org.apache.sis.test.LoggingWatcher; import org.apache.sis.test.FailureDetailsReporter; +import org.apache.sis.referencing.EPSGDependentTestCase; /** @@ -64,6 +66,15 @@ public final class CRSParserTest extends WKTParserTest { loggings = new LoggingWatcher(Loggers.WKT); } + /** + * Forces the check of whether of EPSG database exists before to start any tests. + * This is done for avoiding race conditions logging the same message many times. + */ + @BeforeAll + public static void forceCheckForEPSG() { + EPSGDependentTestCase.forceCheckForEPSG(); + } + /** * Pre-process the WKT string before parsing. This method may replace curly quotation marks * ({@code “} and {@code ”}) by straight quotation marks ({@code "}). diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java index 82ab3a4824..1839bdd9ae 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/ComparisonWithEPSG.java @@ -31,7 +31,7 @@ import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import org.apache.sis.referencing.factory.TestFactorySource; import static org.apache.sis.test.Assertions.assertEqualsIgnoreMetadata; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; /** @@ -41,7 +41,7 @@ import org.apache.sis.test.TestCase; */ @Execution(ExecutionMode.CONCURRENT) @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public final class ComparisonWithEPSG extends TestCase { +public final class ComparisonWithEPSG extends EPSGDependentTestCase { /** * The source of the EPSG factory. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java index 4610b54611..73faa32290 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/GeodeticObjectParserTest.java @@ -48,7 +48,7 @@ import static org.apache.sis.util.privy.Constants.SECONDS_PER_DAY; // Test dependencies import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import static org.apache.sis.test.Assertions.assertMessageContains; import static org.apache.sis.test.Assertions.assertMultilinesEquals; import static org.apache.sis.referencing.Assertions.assertAxisEquals; @@ -61,7 +61,7 @@ import static org.apache.sis.test.TestUtilities.getSingleton; * * @author Martin Desruisseaux (IRD, Geomatys) */ -public final class GeodeticObjectParserTest extends TestCase { +public final class GeodeticObjectParserTest extends EPSGDependentTestCase { /** * The parser to use for the test. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java index 1d9e70c197..8d7e4eb39d 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java @@ -42,7 +42,7 @@ import org.apache.sis.util.collection.BackingStoreException; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.test.TestUtilities; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import static org.apache.sis.test.Assertions.assertSetEquals; import static org.apache.sis.test.Assertions.assertMessageContains; @@ -56,7 +56,7 @@ import static org.opengis.test.Assertions.assertAxisDirectionsEqual; * * @author Martin Desruisseaux (Geomatys) */ -public final class WKTDictionaryTest extends TestCase { +public final class WKTDictionaryTest extends EPSGDependentTestCase { /** * Creates a new test case. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java index c7903baafe..602e56be19 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTFormatTest.java @@ -34,7 +34,7 @@ import org.apache.sis.parameter.Parameterized; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.referencing.operation.transform.MathTransformFactoryMock; -import org.apache.sis.test.TestCase; +import org.apache.sis.referencing.EPSGDependentTestCase; import static org.apache.sis.test.Assertions.assertEqualsIgnoreMetadata; import static org.apache.sis.test.Assertions.assertMessageContains; import static org.apache.sis.test.Assertions.assertMultilinesEquals; @@ -45,7 +45,7 @@ import static org.apache.sis.test.Assertions.assertMultilinesEquals; * * @author Martin Desruisseaux (Geomatys) */ -public final class WKTFormatTest extends TestCase { +public final class WKTFormatTest extends EPSGDependentTestCase { /** * The instance to use for the test, or {@code null} if none. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java index e10e95df20..6f7773c557 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/AuthorityFactoriesTest.java @@ -35,6 +35,7 @@ import org.apache.sis.referencing.factory.GeodeticAuthorityFactory; // Test dependencies import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeAll; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.test.TestCaseWithLogs; import org.apache.sis.referencing.crs.HardCodedCRS; @@ -55,6 +56,15 @@ public final class AuthorityFactoriesTest extends TestCaseWithLogs { super(Loggers.CRS_FACTORY); } + /** + * Forces the check of whether of EPSG database exists before to start any tests. + * This is done for avoiding race conditions logging the same message many times. + */ + @BeforeAll + public static void forceCheckForEPSG() { + EPSGDependentTestCase.forceCheckForEPSG(); + } + /** * Ensures that {@link EPSGFactoryProxy} is declared before {@link CommonAuthorityFactory}. * This is preferable (but not mandatory) because of the way we implemented {@link AuthorityFactories}. diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java index 57725b19c5..72fc601c50 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CRSTest.java @@ -39,6 +39,7 @@ import org.apache.sis.util.Utilities; // Test dependencies import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeAll; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.test.TestCaseWithLogs; import org.apache.sis.referencing.cs.HardCodedCS; @@ -65,6 +66,15 @@ public final class CRSTest extends TestCaseWithLogs { super(Loggers.CRS_FACTORY); } + /** + * Forces the check of whether of EPSG database exists before to start any tests. + * This is done for avoiding race conditions logging the same message many times. + */ + @BeforeAll + public static void forceCheckForEPSG() { + EPSGDependentTestCase.forceCheckForEPSG(); + } + /** * Asserts that the result of {@link CRS#forCode(String)} is the given CRS. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java index 028a9d1cb7..f457ff1b51 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/CommonCRSTest.java @@ -46,7 +46,6 @@ import static org.apache.sis.util.privy.Constants.UTC; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.opengis.test.Validators; -import org.apache.sis.test.TestCase; import static org.apache.sis.test.Assertions.assertEqualsIgnoreMetadata; import static org.apache.sis.test.Assertions.assertMessageContains; import static org.apache.sis.test.TestUtilities.*; @@ -61,7 +60,7 @@ import static org.opengis.test.Assertions.assertAxisDirectionsEqual; * * @author Martin Desruisseaux (IRD, Geomatys) */ -public final class CommonCRSTest extends TestCase { +public final class CommonCRSTest extends EPSGDependentTestCase { /** * Creates a new test case. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/EPSGDependentTestCase.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/EPSGDependentTestCase.java new file mode 100644 index 0000000000..fba8b60bd1 --- /dev/null +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/EPSGDependentTestCase.java @@ -0,0 +1,52 @@ +/* + * 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. + */ +package org.apache.sis.referencing; + +// Test dependencies +import org.junit.jupiter.api.BeforeAll; +import org.apache.sis.test.TestCase; + + +/** + * Base class of Apache SIS tests that may depend on the EPSG database (except GeoAPI tests). + * This base class is used for checking in a single place whether the EPSG database exists on + * the local machine. Note that this is not necessarily for tests that <em>require</em> EPSG. + * This base class is also for tests that <em>may</em> use EPSG if present, sometime indirectly. + * For example, even when the test is using {@link org.apache.sis.referencing.crs.HardCodedCRS} + * constants, SIS may still look for EPSG data for validation or for searching coordinate operations. + * + * @author Martin Desruisseaux (Geomatys) + */ +public class EPSGDependentTestCase extends TestCase { + /** + * Creates a new test case. + */ + protected EPSGDependentTestCase() { + } + + /** + * Performs an arbitrary operation which will force Apache SIS to check whether the EPSG database exists. + * This is done before any test is started in order to avoid race conditions causing the same message to + * be logged many times when tests are run in parallel. Note that those race conditions do not break the + * tests (results are still correct). It only pollutes the logs, and may cause random test failures when + * the test verifies the logs. + */ + @BeforeAll + public static void forceCheckForEPSG() { + CommonCRS.defaultGeographic(); + } +} diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/StandardDefinitionsTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/StandardDefinitionsTest.java index 062644db92..2c15a96290 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/StandardDefinitionsTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/StandardDefinitionsTest.java @@ -37,7 +37,6 @@ import org.apache.sis.measure.Units; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; import org.opengis.test.Validators; -import org.apache.sis.test.TestCase; import org.apache.sis.referencing.datum.GeodeticDatumMock; import org.apache.sis.referencing.datum.HardCodedDatum; import org.apache.sis.referencing.crs.HardCodedCRS; @@ -50,7 +49,7 @@ import org.apache.sis.referencing.cs.HardCodedCS; * * @author Martin Desruisseaux (Geomatys) */ -public final class StandardDefinitionsTest extends TestCase { +public final class StandardDefinitionsTest extends EPSGDependentTestCase { /** * Creates a new test case. */