Skip to content

Commit

Permalink
Read after close
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Jan 30, 2025
1 parent 40d52d8 commit 76c5685
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ public int read() throws IOException {

@Override
public int read(byte b[], final int off, int len) throws IOException {
log.tracef("Ready to read up to %d bytes", len);
log.tracef(new RuntimeException(), "Ready to read up to %d bytes", len);
Buffer rb = takeBuffer(true);
if (rb == null) {
log.trace("Nothing more to read");
Expand Down Expand Up @@ -1636,8 +1636,8 @@ private void freeReadBufferIfNeeded() {
@Override
public void close() {
// log.trace("Closing reader");
log.tracef("Closing reader: got %d bytes in %d reads", bytesRead, readCounter);
readBuffer = null;
log.tracef(new RuntimeException(), "Closing reader: got %d bytes in %d reads", bytesRead, readCounter);
freeReadBufferIfNeeded();
// assert queueEmpty() : "Queue still has " + queue.size() + " items";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ void twoBuffers() throws IOException {
}
}

@Test
void readAfterClose() throws IOException {
ContextInternal ctx = (ContextInternal) Vertx.vertx().getOrCreateContext();
InputStreamWriteStream ws = new InputStreamWriteStream(ctx, 2);
final String INPUT1 = "abcd";
final String INPUT2 = "efgh";
final String INPUT3 = "ijkl";
ws.write(Buffer.buffer(INPUT1));
ws.write(Buffer.buffer(INPUT2));
ws.write(Buffer.buffer(INPUT3));
ws.end();
byte[] arr = new byte[12];
Assertions.assertThat(ws.read(arr)).isEqualTo(12);
Assertions.assertThat(arr).isEqualTo((INPUT1 + INPUT2 + INPUT3).getBytes(StandardCharsets.UTF_8));
Assertions.assertThat(ws.read(arr)).isEqualTo(-1);
ws.close();
Assertions.assertThat(ws.read(arr)).isEqualTo(-1);
ws.close();
}

@Test
void threeBuffers() throws IOException {

Expand Down

0 comments on commit 76c5685

Please sign in to comment.