You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sis.apache.org by "alexismanin (via GitHub)" <gi...@apache.org> on 2026/05/21 09:26:46 UTC

[PR] Fix an instability in Geotiff unit test [sis]

alexismanin opened a new pull request, #44:
URL: https://github.com/apache/sis/pull/44

   I stumbled upon an error while building SIS with a specific JDK: 23.0.2 Liberica (installed using sdkman -> sdk install java 23.0.2.fx-librca).
   
   The test was failing because it tested the size of a written Geotiff file. The problem is, as the written file uses Deflate compression, there's no guarantee that the produced file will always have the same size, depending on user build environment. The stack trace of the  error is : 
   
   ```log
   GeoTiffStoreTest > testWriteTiled() FAILED
       org.opentest4j.AssertionFailedError: array lengths differ, expected: <2334> but was: <2336>
           at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
           at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
           at app//org.junit.jupiter.api.AssertArrayEquals.assertArraysHaveSameLength(AssertArrayEquals.java:428)
           at app//org.junit.jupiter.api.AssertArrayEquals.assertArrayEquals(AssertArrayEquals.java:205)
           at app//org.junit.jupiter.api.AssertArrayEquals.assertArrayEquals(AssertArrayEquals.java:63)
           at app//org.junit.jupiter.api.AssertArrayEquals.assertArrayEquals(AssertArrayEquals.java:59)
           at app//org.junit.jupiter.api.Assertions.assertArrayEquals(Assertions.java:1229)
           at app/org.apache.sis.storage.geotiff/org.apache.sis.storage.geotiff.GeoTiffStoreTest.testWrite(GeoTiffStoreTest.java:190)
           at app/org.apache.sis.storage.geotiff/org.apache.sis.storage.geotiff.GeoTiffStoreTest.testWriteTiled(GeoTiffStoreTest.java:152)
   ```
   
   This PR refactors the test to stop comparing file size. Instead, we read back the written file, and check that the decoded coverage is equivalent to the original coverage that was written.
   
   A few side notes about this PR: 
   
    - It contains a commit from another PR I opened [here](#43 ). The commit is the one that upgrades Gradle, to make it compatible with JDK 23. Depending on which PR is merged first, I will rebase the other one to get rid of the duplicated commit.
    - It also add another test for ImageProcessor, to verify that reformat operation is capable of retiling image according to user request.
    - It makes SampleDimension object implement "LenientComparable", which is useful for coverage comparison (which is required by the refactored Geotiff test).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on code in PR #44:
URL: https://github.com/apache/sis/pull/44#discussion_r3304015535


##########
endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/SampleDimension.java:
##########


Review Comment:
   Need to be changed to 1.7.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on code in PR #44:
URL: https://github.com/apache/sis/pull/44#discussion_r3304155960


##########
endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/SampleDimension.java:
##########
@@ -498,6 +501,18 @@ public boolean equals(final Object object) {
         return false;
     }
 
+    @Override
+    public boolean equals(Object other, ComparisonMode mode) {
+        if (other == this) return true;
+        if (mode.isApproximate() && other instanceof SampleDimension) {
+            final var otherDim = (SampleDimension) other;
+            return Utilities.deepEquals(this.transferFunction, otherDim.transferFunction, mode)

Review Comment:
   The transfer function was not compared in `equals(Object)` because it was derived from `categories`. Therefore, comparing `transferFunction` was considered redundant with comparing `categories`. If we want the comparison to be tolerant to slight difference in transfer functions, then we need to make `Category` implements `LenientComparable` too, otherwise this method will actually behave as if a strict comparison was performed regardless the flexibility of `Utilities.deepEquals(this.transferFunction, otherDim.transferFunction, mode)`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on code in PR #44:
URL: https://github.com/apache/sis/pull/44#discussion_r3304206946


##########
endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/SampleDimension.java:
##########
@@ -498,6 +501,18 @@ public boolean equals(final Object object) {
         return false;
     }
 
+    @Override
+    public boolean equals(Object other, ComparisonMode mode) {
+        if (other == this) return true;
+        if (mode.isApproximate() && other instanceof SampleDimension) {

Review Comment:
   We should only test if the mode is `STRICT`, in which case the test should be done as in the current implementation of `equals(Object)`, and unconditionally uses `Utilities.deepEquals` in all other cases. The reason is that since we need to make `Category` implements `LenientComparable` too, `Category` could apply whether policy it wants. In particular, it may compare the category name in `ComparisonMode.BY_CONTRACT` and ignore that name in `ComparisonMode.IGNORE_METADATA`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "asf-gitbox-commits (via GitHub)" <gi...@apache.org>.
asf-gitbox-commits merged PR #44:
URL: https://github.com/apache/sis/pull/44


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on code in PR #44:
URL: https://github.com/apache/sis/pull/44#discussion_r3304088821


##########
endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/SampleDimension.java:
##########


Review Comment:
   The pattern in other classes is to rewrite this method as a final method which redirects to `equals(object, ComparisonMode.STRIC)`. The current implementation would move to the latter method. The intent is to have only one method to override in subclasses (if any), for making sure that users do not override `equals(Object)` and forget to override `equals(Object, ComparisonMode)`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on PR #44:
URL: https://github.com/apache/sis/pull/44#issuecomment-4762692671

   Changes in the merge compared to the original pull request:
   
   * The comparison of `Number` objects, which was added to `Utilities.deepEquals(…)` in the original pull request, has been moved to `Range.equals(…)`. The reason is because before the pull request, the `Utilities` class was making no special cases for any type other than `LenientComparable`, arrays and collections. Introducing a special case for `Number` would have introduced the first departure to this conceptual simplicity.
   * Keep `CategoryList` mostly unchanged (but keep all the new tests). When I suggested that `CategoryList` should implement `LenientComparable`, I forgot that it was not necessary because of above point. The test case added by this pull request in `CategoryListTest` verifies that claim.
   * The comment in `Range.equals(…)` about allowing (0 … 256) to be considered as equivalent to [1 … 255] has been implemented. This flexibility is enabled by `ComparisonMode.ALLOWS_VARIANT`.
   * Modified `GeoTiffStoreTest` for writing an uncompressed image instead of an image compressed with the deflate algorithm. It avoids the variability observed between different JVM. The tests added by this pull request are executed after.
   * Reduce the expectations of `assertTileSize(…)` because if the image has been reformatted, there is no guarantee about the tile size (except to be a multiple of 16). The new size does not need to be the multiple of 16 immediately before or after the original tile size.
   * Javadoc.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on code in PR #44:
URL: https://github.com/apache/sis/pull/44#discussion_r3304094864


##########
endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/SampleDimension.java:
##########


Review Comment:
   Not an issue of this pull request, but I just realized that this line should be `if (object.getClass() == getClass())` (for `ComparisonMode.EXACT` only).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix an instability in Geotiff unit test [sis]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on code in PR #44:
URL: https://github.com/apache/sis/pull/44#discussion_r3304252625


##########
endorsed/src/org.apache.sis.storage.geotiff/test/org/apache/sis/storage/geotiff/GeoTiffStoreTest.java:
##########
@@ -177,17 +193,99 @@ private static void testWrite(final String filename, final Rectangle bounds, fin
                 .flipGridAxis(1)
                 .build();
 
-        final var buffer = new ByteArrayOutputStream(length);
+        final var buffer = new ByteArrayOutputStream();
         try (DataStore ds = DataStores.openWritable(buffer, "geotiff")) {
             assertInstanceOf(GeoTiffStore.class, ds).append(coverage, null);
         }
+
         final byte[] actual = buffer.toByteArray();
-        final byte[] expected;
-        try (InputStream in = GeoTiffStoreTest.class.getResourceAsStream(filename)) {
-            assertNotNull(in, filename);
-            expected = in.readAllBytes();
+        try (var store = new GeoTiffStore(new GeoTiffStoreProvider(), new StorageConnector(ByteBuffer.wrap(actual)))) {
+            var coverageToValidate = store.components().get(0).read(null);
+            final var expectedGridGeom = coverage.getGridGeometry();
+            final var actualGridGeom = coverageToValidate.getGridGeometry();
+            assertTrue(
+                    Utilities.equalsApproximately(expectedGridGeom, actualGridGeom),
+                    () -> String.format(
+                            "Written grid geometry differs from original one.%nOriginal:%n%s%nWritten:%n%s%n",
+                            expectedGridGeom, actualGridGeom
+                    )
+            );
+
+            assertTrue(
+                    Utilities.equalsApproximately(expectedGridGeom, actualGridGeom),
+                    () -> String.format(
+                            "Written grid geometry differs from original one.%nOriginal:%n%s%nWritten:%n%s%n",
+                            expectedGridGeom, actualGridGeom
+                    )
+            );
+
+            final var expectedSampleDims = coverage.getSampleDimensions();
+            final var actualSampleDims = coverageToValidate.getSampleDimensions();
+            assertTrue(
+                    Utilities.equalsApproximately(expectedSampleDims, actualSampleDims),
+                    () -> String.format(
+                            "Written Sample dimensions differ from original one.%nOriginal:%n%s%nWritten:%n%s%n",
+                            expectedSampleDims, actualSampleDims
+                    )
+            );
+
+            final var actualRendering = coverageToValidate.render(null);
+            assertPixelsEqual(coverage.render(null), null, actualRendering, null);
+            // If user requested a tiled dataset, we must ensure the written Geotiff file has been tiled
+            if (tileSize != null && (tileSize.getWidth() < bounds.getWidth() || tileSize.getHeight() < bounds.getHeight())) {
+                assertTiling(actualRendering, tileSize, 16);
+            }
+        }
+    }
+
+    /**
+     * Represent the side of the tile being evaluated. Either width (X) or height (Y).
+     */
+    private enum TileAxis { width, height }
+
+    /**
+     * Verify that given image tiling respects user tiling request, modulo a given restriction.
+     * The restriction maps Tiff standard requirement for tile size to be multiple of a given factor.
+     * </br>

Review Comment:
   It is a small detail, but the rest of SIS rather uses `<p>...</p>` instead of `<br/>` (the slash also appears to be in the wrong side in this line). This is for semantic reason (the same reason why we use `<i>`, `<em>`, `<var>` or `<dfn>` in different contexts, even if they all appear in italic in the browser): the semantic is that we want to start a new paragraph.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@sis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org