use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project riposte by Nike-Inc.
the class StreamingAsyncHttpClientTest method StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_is_empty_last_chunk.
@Test
public void StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_is_empty_last_chunk() {
// given
streamingChannelSpy.downstreamLastChunkSentHolder.heldObject = true;
LastHttpContent contentChunkMock = mock(LastHttpContent.class);
ByteBuf contentByteBufMock = mock(ByteBuf.class);
doReturn(contentByteBufMock).when(contentChunkMock).content();
doReturn(0).when(contentByteBufMock).readableBytes();
ChannelFuture successFutureMock = mock(ChannelFuture.class);
doReturn(successFutureMock).when(channelMock).newSucceededFuture();
// when
ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock);
// then
verify(channelMock, never()).writeAndFlush(any(Object.class));
verify(contentChunkMock).release();
verify(channelMock).newSucceededFuture();
assertThat(result).isSameAs(successFutureMock);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project riposte by Nike-Inc.
the class RequestInfoImpl method addContentChunk.
/**
* {@inheritDoc}
*/
@Override
public int addContentChunk(@NotNull HttpContent chunk) {
if (isCompleteRequestWithAllChunks) {
throw new IllegalStateException("Cannot add new content chunk - this RequestInfo is already marked as " + "representing the complete request with all chunks");
}
chunk.retain();
rawContentLengthInBytes += chunk.content().readableBytes();
// If content chunks will be released externally then there's no point in us holding on to them
if (!contentChunksWillBeReleasedExternally)
contentChunks.add(chunk);
if (chunk instanceof LastHttpContent) {
// to be set to true if content chunks are released externally.
if (!contentChunksWillBeReleasedExternally)
isCompleteRequestWithAllChunks = true;
HttpHeaders chunkTrailingHeaders = ((LastHttpContent) chunk).trailingHeaders();
// noinspection StatementWithEmptyBody
if (trailingHeaders == chunkTrailingHeaders) {
// Can happen during the constructor. We've already set the trailing headers to the chunk's trailing headers, so nothing to do here.
} else {
if (!trailingHeaders.isEmpty()) {
throw new IllegalStateException("Received the final chunk, but trailingHeaders was already " + "populated. This should not be possible.");
}
trailingHeaders.add(chunkTrailingHeaders);
}
}
return rawContentLengthInBytes;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project ambry by linkedin.
the class FrontendIntegrationTest method assertNoContent.
// helpers
// general
/**
* Discards all the content in {@code contents} and checks none of the chunks have actual content
* @param contents the content to discard.
* @param expectedDiscardCount the number of {@link HttpObject}s that are expected to discarded.
*/
void assertNoContent(Queue<HttpObject> contents, int expectedDiscardCount) {
assertEquals("Objects that will be discarded differ from expected", expectedDiscardCount, contents.size());
boolean endMarkerFound = false;
for (HttpObject object : contents) {
assertFalse("There should have been no more data after the end marker was found", endMarkerFound);
HttpContent content = (HttpContent) object;
assertEquals("No content expected ", 0, content.content().readableBytes());
endMarkerFound = object instanceof LastHttpContent;
ReferenceCountUtil.release(object);
}
assertTrue("There should have been an end marker", endMarkerFound);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project ambry by linkedin.
the class FrontendIntegrationTestBase method assertNoContent.
// BeforeClass helpers
/**
* Discards all the content in {@code contents} and checks none of the chunks have actual content
* @param contents the content to discard.
* @param expectedDiscardCount the number of {@link HttpObject}s that are expected to discarded.
*/
void assertNoContent(Queue<HttpObject> contents, int expectedDiscardCount) {
assertEquals("Objects that will be discarded differ from expected", expectedDiscardCount, contents.size());
boolean endMarkerFound = false;
for (HttpObject object : contents) {
assertFalse("There should have been no more data after the end marker was found", endMarkerFound);
HttpContent content = (HttpContent) object;
assertEquals("No content expected ", 0, content.content().readableBytes());
endMarkerFound = object instanceof LastHttpContent;
ReferenceCountUtil.release(object);
}
assertTrue("There should have been an end marker", endMarkerFound);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpContent in project ambry by linkedin.
the class FrontendIntegrationTestBase method getContent.
/**
* Combines all the parts in {@code contents} into one {@link ByteBuffer}.
* @param contents the content of the response.
* @param expectedContentLength the length of the contents in bytes.
* @return a {@link ByteBuffer} that contains all the data in {@code contents}.
*/
ByteBuffer getContent(Queue<HttpObject> contents, long expectedContentLength) {
ByteBuffer buffer = ByteBuffer.allocate((int) expectedContentLength);
boolean endMarkerFound = false;
for (HttpObject object : contents) {
assertFalse("There should have been no more data after the end marker was found", endMarkerFound);
HttpContent content = (HttpContent) object;
buffer.put(content.content().nioBuffer());
endMarkerFound = object instanceof LastHttpContent;
content.release();
}
assertEquals("Content length did not match expected", expectedContentLength, buffer.position());
assertTrue("End marker was not found", endMarkerFound);
buffer.flip();
return buffer;
}
Aggregations