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 1c81e3ce85623ce445f564bc95d98e8b5cf29447 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Feb 20 13:25:04 2024 +0100 Fix some synchronization holes in parallel execution of tests. --- .../org/apache/sis/util/iso/NameMarshallingTest.java | 19 ++++++++++++++----- .../org/apache/sis/xml/bind/gco/MultiplicityTest.java | 2 +- .../test/org/apache/sis/xml/test/TestCase.java | 3 +++ .../apache/sis/referencing/AuthorityFactories.java | 2 ++ .../sis/referencing/EPSGFactoryFallbackTest.java | 5 +++++ .../operation/CoordinateOperationFinderTest.java | 3 +++ .../operation/CoordinateOperationRegistryTest.java | 5 ++++- .../DefaultCoordinateOperationFactoryTest.java | 3 +++ .../transform/CoordinateSystemTransformTest.java | 3 +++ .../org/apache/sis/storage/netcdf/base/TestCase.java | 3 +++ .../sis/storage/test/CoverageReadConsistency.java | 3 +++ .../main/org/apache/sis/system/Configuration.java | 3 ++- .../sis/util/collection/TreeTableFormatTest.java | 3 +++ .../apache/sis/util/logging/PerformanceLevelTest.java | 2 ++ 14 files changed, 51 insertions(+), 8 deletions(-) diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/NameMarshallingTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/NameMarshallingTest.java index 37bb603ecb..d361648071 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/NameMarshallingTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/util/iso/NameMarshallingTest.java @@ -50,8 +50,6 @@ import static org.apache.sis.metadata.Assertions.assertXmlEquals; public final class NameMarshallingTest extends TestCase { /** * A poll of configured {@link Marshaller} and {@link Unmarshaller}, created when first needed. - * - * @see #disposeMarshallerPool() */ private MarshallerPool pool; @@ -62,14 +60,23 @@ public final class NameMarshallingTest extends TestCase { } /** - * Returns the XML representation of the given name, wrapped - * in a mock {@code <gml:IO_IdentifiedObject>} element. + * Returns the marshaller pool, created when first needed. */ - private String marshal(final GenericName name) throws JAXBException { + private synchronized MarshallerPool pool() throws JAXBException { if (pool == null) { pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class), Map.of(XML.LENIENT_UNMARSHAL, Boolean.TRUE)); } + return pool; + } + + /** + * Returns the XML representation of the given name, wrapped + * in a mock {@code <gml:IO_IdentifiedObject>} element. + */ + private String marshal(final GenericName name) throws JAXBException { + @SuppressWarnings("LocalVariableHidesMemberVariable") + final MarshallerPool pool = pool(); final Marshaller marshaller = pool.acquireMarshaller(); marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007); final String xml = marshal(marshaller, new IdentifiedObjectMock(null, name)); @@ -81,6 +88,8 @@ public final class NameMarshallingTest extends TestCase { * Converse of {@link #marshal(GenericName)}. */ private GenericName unmarshal(final String xml) throws JAXBException { + @SuppressWarnings("LocalVariableHidesMemberVariable") + final MarshallerPool pool = pool(); final Unmarshaller unmarshaller = pool.acquireUnmarshaller(); final Object value = unmarshal(unmarshaller, xml); pool.recycle(unmarshaller); diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gco/MultiplicityTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gco/MultiplicityTest.java index 0c6e89083a..695bead899 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gco/MultiplicityTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/bind/gco/MultiplicityTest.java @@ -70,7 +70,7 @@ public final class MultiplicityTest extends TestUsingFile { * @throws JAXBException if an error occurred while creating the pool. */ @Override - protected MarshallerPool getMarshallerPool() throws JAXBException { + protected synchronized MarshallerPool getMarshallerPool() throws JAXBException { if (pool == null) { pool = new MarshallerPool(JAXBContext.newInstance(FeatureAttributeMock.class), Map.of(XML.LENIENT_UNMARSHAL, Boolean.TRUE)); diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java index c9b35ee213..10f1546c27 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/TestCase.java @@ -45,6 +45,8 @@ import org.junit.jupiter.api.AfterEach; import static org.junit.jupiter.api.Assertions.*; import static org.apache.sis.metadata.Assertions.assertXmlEquals; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.junit.jupiter.api.parallel.ResourceAccessMode; import org.junit.jupiter.api.parallel.ResourceLock; import org.apache.sis.test.LoggingWatcher; @@ -67,6 +69,7 @@ import org.apache.sis.test.LoggingWatcher; * * @see DocumentComparator */ +@Execution(ExecutionMode.SAME_THREAD) public abstract class TestCase extends org.apache.sis.test.TestCase { /** * Base class of (un)marshalling tests that may emit logs. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/AuthorityFactories.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/AuthorityFactories.java index aabc203bbb..ffcb67404c 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/AuthorityFactories.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/AuthorityFactories.java @@ -32,6 +32,7 @@ import org.apache.sis.referencing.util.LazySet; import org.apache.sis.system.Reflect; import org.apache.sis.system.Loggers; import org.apache.sis.system.Modules; +import org.apache.sis.system.Configuration; import org.apache.sis.system.SystemListener; import org.apache.sis.referencing.internal.EPSGFactoryProxy; import org.apache.sis.referencing.factory.MultiAuthoritiesFactory; @@ -117,6 +118,7 @@ final class AuthorityFactories<T extends AuthorityFactory> extends LazySet<T> { /** * Sets the EPSG factory to the given value. */ + @Configuration static void EPSG(final GeodeticAuthorityFactory factory) { synchronized (EPSG) { EPSG[0] = factory; diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/EPSGFactoryFallbackTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/EPSGFactoryFallbackTest.java index ca1bca5988..e045f53a60 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/EPSGFactoryFallbackTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/EPSGFactoryFallbackTest.java @@ -35,12 +35,14 @@ import org.opengis.referencing.datum.Datum; import org.opengis.referencing.datum.Ellipsoid; import org.opengis.referencing.datum.PrimeMeridian; import org.apache.sis.referencing.factory.GeodeticAuthorityFactory; +import org.apache.sis.system.Configuration; import org.apache.sis.util.ComparisonMode; import org.apache.sis.util.Utilities; // Test dependencies import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.parallel.Isolated; import org.apache.sis.test.TestCase; import org.apache.sis.test.TestUtilities; import static org.apache.sis.test.Assertions.assertEqualsIgnoreMetadata; @@ -52,6 +54,7 @@ import static org.apache.sis.test.Assertions.assertSetEquals; * * @author Martin Desruisseaux (Geomatys) */ +@Isolated("Temporarily modifies the system-wide EPSG factory.") public final class EPSGFactoryFallbackTest extends TestCase { /** * Creates a new test case. @@ -222,6 +225,7 @@ public final class EPSGFactoryFallbackTest extends TestCase { /** * Sets the EPSG factory to the given instance and clears the cache of all {@link CommonCRS} enumeration values. */ + @Configuration private static void setEPSGFactory(final GeodeticAuthorityFactory factory) { AuthorityFactories.EPSG(factory); for (final CommonCRS crs : CommonCRS .values()) crs.clear(); @@ -231,6 +235,7 @@ public final class EPSGFactoryFallbackTest extends TestCase { /** * Compares all CRS created by {@link EPSGFactoryFallback} with CRS created by the real EPSG database. + * This test must be run in a class annotated with {@link Isolated}. * * @throws FactoryException if a CRS cannot be constructed. */ diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java index 5e2dd7e319..45cbf87e62 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationFinderTest.java @@ -63,6 +63,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.apache.sis.test.TestUtilities; import org.apache.sis.referencing.cs.HardCodedCS; import org.apache.sis.referencing.crs.HardCodedCRS; @@ -80,6 +82,7 @@ import org.opengis.test.Assertions; * * @author Martin Desruisseaux (Geomatys) */ +@Execution(ExecutionMode.SAME_THREAD) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public final class CoordinateOperationFinderTest extends MathTransformTestCase { /** diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java index 3fa8e71b87..d1351677a0 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/CoordinateOperationRegistryTest.java @@ -40,8 +40,10 @@ import org.apache.sis.referencing.operation.transform.MathTransformTestCase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; -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.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import static org.apache.sis.referencing.Assertions.assertEpsgNameAndIdentifierEqual; // Specific to the geoapi-3.1 and geoapi-4.0 branches: @@ -67,6 +69,7 @@ import org.opengis.metadata.Identifier; * * @author Martin Desruisseaux (Geomatys) */ +@Execution(ExecutionMode.SAME_THREAD) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public final class CoordinateOperationRegistryTest extends MathTransformTestCase { /** diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java index d43ed1e1fd..ed1dbf765e 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactoryTest.java @@ -41,6 +41,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import static org.apache.sis.test.Assertions.assertMessageContains; import static org.apache.sis.referencing.Assertions.assertEpsgNameAndIdentifierEqual; @@ -57,6 +59,7 @@ import static org.apache.sis.referencing.Assertions.assertEpsgNameAndIdentifierE * * @author Martin Desruisseaux (Geomatys) */ +@Execution(ExecutionMode.SAME_THREAD) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public final class DefaultCoordinateOperationFactoryTest extends MathTransformTestCase { /** diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java index 8323fdd2f6..e0d6c5e211 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/CoordinateSystemTransformTest.java @@ -34,6 +34,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.junit.jupiter.api.extension.ExtendWith; import org.apache.sis.test.FailureDetailsReporter; import org.apache.sis.referencing.cs.HardCodedCS; @@ -45,6 +47,7 @@ import org.opengis.test.referencing.TransformTestCase; * * @author Martin Desruisseaux (Geomatys) */ +@Execution(ExecutionMode.SAME_THREAD) @ExtendWith(FailureDetailsReporter.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public final class CoordinateSystemTransformTest extends TransformTestCase { diff --git a/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java b/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java index 3b7e9af51a..856a5242b1 100644 --- a/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java +++ b/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java @@ -37,6 +37,8 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.TestInstance; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; // Specific to the geoapi-3.1 and geoapi-4.0 branches: import org.opengis.test.dataset.TestData; @@ -50,6 +52,7 @@ import org.opengis.test.dataset.TestData; * * @author Martin Desruisseaux (Geomatys) */ +@Execution(ExecutionMode.SAME_THREAD) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public abstract class TestCase extends org.apache.sis.test.TestCase { /** 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 93fb274bc1..b3d94e842a 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 @@ -44,6 +44,8 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import static org.junit.jupiter.api.Assertions.*; +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; @@ -66,6 +68,7 @@ import org.apache.sis.test.TestCase; * * @author Martin Desruisseaux (Geomatys) */ +@Execution(ExecutionMode.SAME_THREAD) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public abstract class CoverageReadConsistency<S extends DataStore> extends TestCase { /** diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/Configuration.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/Configuration.java index 8b67f31648..6def89a975 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/Configuration.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/system/Configuration.java @@ -25,7 +25,8 @@ import java.lang.annotation.RetentionPolicy; /** * Annotates methods having a system-wide impact on the configuration of the Apache SIS library. * Also used for some static final constants fixed to arbitrary values that could be customized. - * This annotation should not be used on test classes for avoiding to pollute usage searches. + * When applied to test classes, this annotation helps to identify which tests cannot be executed + * in parallel. * * <h2>Application to static final constants</h2> * We do not annotate all static constants having arbitrary values because there is too many of them. diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/TreeTableFormatTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/TreeTableFormatTest.java index 0940167d0f..040f3f63a7 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/TreeTableFormatTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/collection/TreeTableFormatTest.java @@ -26,6 +26,8 @@ import static org.apache.sis.util.collection.TableColumn.*; // Test dependencies import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.parallel.Resources; +import org.junit.jupiter.api.parallel.ResourceLock; import org.apache.sis.test.TestCase; import static org.apache.sis.test.Assertions.assertMultilinesEquals; @@ -201,6 +203,7 @@ public final class TreeTableFormatTest extends TestCase { * Those types shall be handled in a special way. */ @Test + @ResourceLock(Resources.LOCALE) public void testLocalizedFormat() { final Locale locale = Locale.getDefault(); try { diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/logging/PerformanceLevelTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/logging/PerformanceLevelTest.java index 67b4fe8ef0..42c217e23c 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/logging/PerformanceLevelTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/util/logging/PerformanceLevelTest.java @@ -23,6 +23,7 @@ import static org.apache.sis.util.logging.PerformanceLevel.*; // Test dependencies import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.parallel.ResourceLock; import org.apache.sis.test.TestCase; @@ -51,6 +52,7 @@ public final class PerformanceLevelTest extends TestCase { * Tests modifying the configuration. */ @Test + @ResourceLock("Logging") public void testSetMinDuration() { final long t1 = SLOWNESS.getMinDuration(TimeUnit.SECONDS); final long t2 = SLOWER .getMinDuration(TimeUnit.SECONDS);