From e09ba12220c2cbbe9d91514da4d0f8fd8543b239 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 13 Apr 2010 18:02:47 -0700 Subject: [PATCH] Fixing PipedInputStreamTest to fill the buffer before dying on a dead reader. Change-Id: Ie34a8bec7b2a34d2933225d6d4e04e0643dbcf99 --- .../test/java/tests/api/java/io/PipedInputStreamTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libcore/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java b/libcore/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java index 671bfe919..c6dd60f64 100644 --- a/libcore/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java +++ b/libcore/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java @@ -27,6 +27,8 @@ import dalvik.annotation.TestTargetNew; @TestTargetClass(PipedInputStream.class) public class PipedInputStreamTest extends junit.framework.TestCase { + private final int BUFFER_SIZE = 1024; + static class PWriter implements Runnable { PipedOutputStream pos; @@ -150,13 +152,12 @@ public class PipedInputStreamTest extends junit.framework.TestCase { PipedInputStream pin = new PipedInputStream(); PipedOutputStream pout = new PipedOutputStream(pin); - // We know the PipedInputStream buffer size is 1024. // Writing another byte would cause the write to wait // for a read before returning - for (int i = 0; i < 1024; i++) + for (int i = 0; i < BUFFER_SIZE; i++) pout.write(i); assertEquals("Test 2: Incorrect number of bytes available. ", - 1024 , pin.available()); + BUFFER_SIZE, pin.available()); } /** @@ -433,8 +434,9 @@ public class PipedInputStreamTest extends junit.framework.TestCase { Thread.sleep(100); } try { - // should throw exception since reader thread - // is now dead + pos.write(new byte[BUFFER_SIZE]); + // should throw exception since buffer is full and + // reader thread is now dead pos.write(1); } catch (IOException e) { pass = true; -- 2.11.0