Search in sources :

Example 96 with LastHttpContent

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);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 97 with LastHttpContent

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;
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) LastHttpContent(io.netty.handler.codec.http.LastHttpContent)

Example 98 with LastHttpContent

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);
}
Also used : HttpObject(io.netty.handler.codec.http.HttpObject) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent)

Example 99 with LastHttpContent

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);
}
Also used : HttpObject(io.netty.handler.codec.http.HttpObject) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent)

Example 100 with LastHttpContent

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;
}
Also used : HttpObject(io.netty.handler.codec.http.HttpObject) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) ByteBuffer(java.nio.ByteBuffer) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent)

Aggregations

LastHttpContent (io.netty.handler.codec.http.LastHttpContent)137 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)63 HttpContent (io.netty.handler.codec.http.HttpContent)55 ByteBuf (io.netty.buffer.ByteBuf)49 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)43 HttpResponse (io.netty.handler.codec.http.HttpResponse)42 HttpRequest (io.netty.handler.codec.http.HttpRequest)34 Test (org.junit.Test)27 Test (org.junit.jupiter.api.Test)24 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)23 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)20 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)18 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)13 IOException (java.io.IOException)12 ChannelFuture (io.netty.channel.ChannelFuture)11 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)10 HttpObject (io.netty.handler.codec.http.HttpObject)10 JsonObjectDecoder (io.netty.handler.codec.json.JsonObjectDecoder)10 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)9 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9