Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] AsyncPositionOutputStream should not flush after close. #3967

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class AsyncPositionOutputStream extends PositionOutputStream {

private int totalBuffers;
private long position;
private boolean closed = false;

public AsyncPositionOutputStream(PositionOutputStream out) {
this.out = out;
Expand Down Expand Up @@ -172,6 +173,9 @@ public void write(byte[] b, int off, int len) throws IOException {

@Override
public void flush() throws IOException {
if (closed) {
throw new RuntimeException("Already closed");
leaves12138 marked this conversation as resolved.
Show resolved Hide resolved
}
checkException();
flushBuffer();
FlushEvent event = new FlushEvent();
Expand Down Expand Up @@ -204,6 +208,7 @@ public void close() throws IOException {
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
this.closed = true;
leaves12138 marked this conversation as resolved.
Show resolved Hide resolved
}

private void sendEndEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.ThreadLocalRandom;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class AsyncPositionOutputStreamTest {
Expand Down Expand Up @@ -173,6 +174,14 @@ public void write(byte[] b, int off, int len) {
assertThat(out.closed).isTrue();
}

@Test
public void testCloseFlushThrowsException() throws Exception {
AsyncPositionOutputStream asyncPositionOutputStream =
new AsyncPositionOutputStream(new ByteArrayPositionOutputStream());
asyncPositionOutputStream.close();
assertThatCode(asyncPositionOutputStream::flush).hasMessage("Already closed");
}

private static class ByteArrayPositionOutputStream extends PositionOutputStream {

private final ByteArrayOutputStream out;
Expand Down
Loading