Skip to content
Merged
Changes from all commits
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 @@ -313,7 +313,10 @@ void blockingOperationsDoNotSerializeCalls() throws Exception {
}
}

/** A streaming payload starts reaching the client before the operation's stream ends. */
/**
* A streaming payload starts reaching the client before the operation's stream ends: the host
* copies it without flushing, and the connector sends each full buffer (issue #1632).
*/
@Test
void streamingOutputIsNotBufferedWhole() throws Exception {
CountDownLatch firstChunkRead = new CountDownLatch(1);
Expand Down Expand Up @@ -510,30 +513,14 @@ private static void write(HttpJob job, Response response) {
: body.contentLength()) {
@Override
public void write(java.io.OutputStream out) throws IOException {
copy(body.asInputStream(), out);
try (InputStream in = body.asInputStream()) {
in.transferTo(out);
}
}
};
response.setEntity(entity);
}
}

/**
* Copies a payload, flushing whenever the source has nothing more available: the connector
* only flushes full buffers once it holds more than its high water mark, so a producer
* pausing mid-stream would otherwise hold back what it already produced.
*/
private static void copy(InputStream in, java.io.OutputStream out) throws IOException {
try (in) {
byte[] buffer = new byte[16 * 1024];
int count;
while ((count = in.read(buffer)) > 0) {
out.write(buffer, 0, count);
if (in.available() == 0) {
out.flush();
}
}
}
}
}

/** A server service built from the model, like smithy-java's ProxyService, without codegen. */
Expand Down
Loading