gnodet-bot commented on code in PR #2306:
URL: https://github.com/apache/maven-resolver/pull/2306#discussion_r4518601996


##########
maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultInstallerTest.java:
##########
@@ -461,6 +465,65 @@ void testHardLinkDisabledFallsThroughToCopy() throws 
InstallationException, IOEx
                 1, countingProcessor.copyWithTimestampCount, 
"copyWithTimestamp must be called when hardLink=false");
     }
 
+    @Test
+    void testHardLinkFallbackLoggedOncePerSession() throws Exception {
+        // This test verifies that when hard-link creation fails 
(cross-device), the INFO log message
+        // is emitted exactly once per session even if install is called 
multiple times.
+        // The test is only meaningful when the environment is cross-device 
(copy fallback is triggered);
+        // it skips on same-device filesystems where hard links succeed and no 
message is emitted.
+        CountingPathProcessor countingProcessor = new CountingPathProcessor();
+        installer = new DefaultInstaller(
+                countingProcessor,
+                new StubRepositoryEventDispatcher(),
+                Collections.emptyMap(),
+                Collections.emptyMap(),
+                Collections.emptyMap(),
+                new StubSyncContextFactory());
+
+        // First install — detect if we're on a cross-device filesystem (copy 
fallback triggered)
+        request.addArtifact(artifact);
+        installer.install(session, request);
+        assumeTrue(
+                countingProcessor.copyWithTimestampCount == 1,
+                "skipped: same-device filesystem — hard link succeeded, no 
fallback log to deduplicate");
+
+        // We're on a cross-device filesystem. Capture stderr (slf4j-simple 
logs there) and
+        // install a second artifact in the same session — the dedup set must 
suppress the 2nd log.
+        Artifact artifact2 = new DefaultArtifact("gid", "aid2", "jar", "ver");
+        artifact2 = 
artifact2.setFile(TestFileUtils.createTempFile("artifact2".getBytes(), 1));
+
+        final Artifact artifact2Final = artifact2;
+        InstallRequest request2 = new InstallRequest();
+        request2.addArtifact(artifact2Final);
+        String log = captureStdErr(() -> installer.install(session, request2));
+
+        // The second install triggered another copy (cross-device), but the 
log must be suppressed
+        assertEquals(2, countingProcessor.copyWithTimestampCount, "second 
install should also copy (cross-device)");
+        assertFalse(
+                log.contains("Hard link not supported"),
+                "hard-link warning must NOT fire a second time in the same 
session; captured log:\n" + log);
+    }

Review Comment:
   🧹 **Nit: test only asserts the dedup negative, not the positive.** The 
`assertFalse` verifies the message is suppressed on the second install, but 
nothing verifies it was actually emitted on the first install — a completely 
broken logger would still pass this test. Consider wrapping the first 
`installer.install(session, request)` call in `captureStdErr` and asserting 
`log.contains("Hard link not supported")` to make the test self-contained.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to