This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch fix/streampollfeeder-volatile in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git
commit 01ce767d82875f4a2285bea28b9201c281e97a07 Author: Elliotte Rusty Harold <[email protected]> AuthorDate: Wed Jul 1 08:42:09 2026 -0400 Add test: StreamPollFeeder with continuous data input --- .../shared/utils/cli/StreamPollFeederTest.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java b/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java index e1c2475..d2b4f3f 100644 --- a/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java +++ b/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java @@ -20,14 +20,45 @@ package org.apache.maven.shared.utils.cli; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.time.Duration; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; public class StreamPollFeederTest { + @Test + public void waitUntilFeederDoneWithContinuousData() { + // Simulates a stream with continuous data where the feeder thread + // never enters the synchronized(lock) wait block, so the done + // flag must be visible without relying on lock's happens-before. + InputStream continuousInput = new InputStream() { + @Override + public int available() { + return 1; + } + + @Override + public int read() throws IOException { + return 0; + } + }; + + assertTimeoutPreemptively( + Duration.ofSeconds(5), + () -> { + StreamPollFeeder feeder = new StreamPollFeeder(continuousInput, new ByteArrayOutputStream()); + feeder.start(); + feeder.waitUntilDone(); + assertNull(feeder.getException()); + }); + } + @Test public void waitUntilFeederDoneOnInputStream() throws Exception {
