diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-14 15:01:14 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-14 15:05:18 +0200 |
commit | 0721ad6bc737df2ffa06e0818700610629601a5d (patch) | |
tree | 50024c53c8e12c046b9734554bab141ea24887b7 /jdisc_core/src/test/java/com/yahoo | |
parent | 439da54cb6068d6097fc65bdd8e5d0e6d108d81a (diff) |
Fix bug in UnsafeContentInputStream where read() corrupts "marked" content
Diffstat (limited to 'jdisc_core/src/test/java/com/yahoo')
-rw-r--r-- | jdisc_core/src/test/java/com/yahoo/jdisc/handler/UnsafeContentInputStreamTestCase.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/UnsafeContentInputStreamTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/UnsafeContentInputStreamTestCase.java index 134c34641a5..0c3670dd56e 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/handler/UnsafeContentInputStreamTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/handler/UnsafeContentInputStreamTestCase.java @@ -10,9 +10,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.ByteBuffer; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -70,6 +71,21 @@ public class UnsafeContentInputStreamTestCase { } @Test + public void requireThatReadAfterResetIncludesDataAfterMark() throws IOException { + ReadableContentChannel content = new ReadableContentChannel(); + UnsafeContentInputStream in = new UnsafeContentInputStream(content); + byte[] outBuf = new byte[] {1, 2, 3}; + content.write(ByteBuffer.wrap(outBuf), null); + in.mark(4); + assertEquals(3, in.read(new byte[] {101, 102, 103, 104})); + in.reset(); + byte[] inBuf = new byte[4]; + int read = in.read(inBuf); + assertEquals(3, read); + assertArrayEquals(new byte[]{1, 2, 3, 0}, inBuf); + } + + @Test public void requireThatCompletionsAreCalledWithDeprecatedContentWriter() throws IOException { BufferedContentChannel channel = new BufferedContentChannel(); FastContentWriter writer = new FastContentWriter(channel); |