Search in sources :

Example 1 with IOControl

use of org.apache.http.nio.IOControl in project elasticsearch by elastic.

the class HeapBufferedAsyncResponseConsumerTests method testResponseProcessing.

public void testResponseProcessing() throws Exception {
    ContentDecoder contentDecoder = mock(ContentDecoder.class);
    IOControl ioControl = mock(IOControl.class);
    HttpContext httpContext = mock(HttpContext.class);
    HeapBufferedAsyncResponseConsumer consumer = spy(new HeapBufferedAsyncResponseConsumer(TEST_BUFFER_LIMIT));
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    httpResponse.setEntity(new StringEntity("test", ContentType.TEXT_PLAIN));
    //everything goes well
    consumer.responseReceived(httpResponse);
    consumer.consumeContent(contentDecoder, ioControl);
    consumer.responseCompleted(httpContext);
    verify(consumer).releaseResources();
    verify(consumer).buildResult(httpContext);
    assertTrue(consumer.isDone());
    assertSame(httpResponse, consumer.getResult());
    consumer.responseCompleted(httpContext);
    verify(consumer, times(1)).releaseResources();
    verify(consumer, times(1)).buildResult(httpContext);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) IOControl(org.apache.http.nio.IOControl) ContentDecoder(org.apache.http.nio.ContentDecoder) HttpContext(org.apache.http.protocol.HttpContext) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Aggregations

HttpResponse (org.apache.http.HttpResponse)1 ProtocolVersion (org.apache.http.ProtocolVersion)1 StatusLine (org.apache.http.StatusLine)1 StringEntity (org.apache.http.entity.StringEntity)1 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)1 BasicStatusLine (org.apache.http.message.BasicStatusLine)1 ContentDecoder (org.apache.http.nio.ContentDecoder)1 IOControl (org.apache.http.nio.IOControl)1 HttpContext (org.apache.http.protocol.HttpContext)1