aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2016-11-21 12:37:46 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-11-21 19:40:54 +0000
commit480a2cf4d3684ad9171077a279f1743192096d7b (patch)
tree46c080bdc320ecf6166a800e9602a8c9f1b32bde /src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java
parentaf25a98a7af734926f6d29187818ce4140b4f3e8 (diff)
Make LineBufferedOutputStream resistant to exceptions thrown while flushing its buffer.
-- MOS_MIGRATED_REVID=139771073
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java b/src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java
index bc136b41fb..8cf7c155d7 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/LineBufferedOutputStreamTest.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.runtime;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.fail;
import com.google.common.base.Strings;
import com.google.devtools.build.lib.testutil.Suite;
@@ -35,6 +36,7 @@ import org.junit.runners.JUnit4;
public class LineBufferedOutputStreamTest {
private static class MockOutputStream extends OutputStream {
private final List<String> writes = new ArrayList<>();
+ private boolean throwException = false;
@Override
public void write(int byteAsInt) throws IOException {
@@ -45,6 +47,10 @@ public class LineBufferedOutputStreamTest {
@Override
public synchronized void write(byte[] b, int off, int inlen) throws IOException {
writes.add(new String(b, off, inlen, StandardCharsets.UTF_8));
+ if (throwException) {
+ throwException = false;
+ throw new IOException("thrown");
+ }
}
}
@@ -73,6 +79,21 @@ public class LineBufferedOutputStreamTest {
assertThat(lineBuffer("a", "a", large, large, "a")).containsExactly(
"aa", large, large, "a");
+ }
+ @Test
+ public void testIOErrorOnWrappedStream() throws Exception {
+ MockOutputStream mos = new MockOutputStream();
+ LineBufferedOutputStream cut = new LineBufferedOutputStream(mos, 4);
+ mos.throwException = true;
+ try {
+ cut.write("aaaa".getBytes(StandardCharsets.UTF_8));
+ fail("IOException expected");
+ } catch (IOException e) {
+ // Expected.
+ }
+ cut.write("a".getBytes(StandardCharsets.UTF_8));
+ cut.close();
+ assertThat(mos.writes).containsExactly("aaaa", "a");
}
}