Skip to content

Commit fb702a4

Browse files
committed
HADOOP-18410. TestSDKStreamDrainer fake stream emulates InputStream.read(buf) better.
Any IOE in read() is only thrown if it is when reading the first byte of the buffer. Change-Id: I53fba27bfacd105f4c3ea4128202a3215456c001
1 parent 9e6cdd5 commit fb702a4

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/impl/TestSDKStreamDrainer.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public int read() throws IOException {
293293
return -1;
294294
}
295295
bytesRead++;
296-
if (bytesRead == readToRaiseIOE) {
296+
if (readToRaiseIOE > 0 && bytesRead >= readToRaiseIOE) {
297297
throw new IOException("IOE triggered on reading byte " + bytesRead);
298298
}
299299
return (int) '0' + (bytesRead % 10);
@@ -304,13 +304,21 @@ public int read(final byte[] bytes, final int off, final int len)
304304
throws IOException {
305305
int count = 0;
306306

307-
while (count < len) {
308-
int r = read();
309-
if (r < 0) {
310-
break;
307+
try {
308+
while (count < len) {
309+
int r = read();
310+
if (r < 0) {
311+
break;
312+
}
313+
bytes[off + count] = (byte) r;
314+
count++;
311315
}
312-
bytes[off + count] = (byte) r;
313-
count++;
316+
} catch (IOException e) {
317+
if (count == 0) {
318+
// first byte
319+
throw e;
320+
}
321+
// otherwise break loop
314322
}
315323
return count;
316324
}

0 commit comments

Comments
 (0)