Search in sources :

Example 1 with BigEndianHeapChannelBuffer

use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.

the class InputStreamFullResponseHandlerTest method testSimple.

@Test
public void testSimple() throws Exception {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.setChunked(false);
    response.setContent(new BigEndianHeapChannelBuffer("abcd".getBytes(StringUtils.UTF8_STRING)));
    InputStreamFullResponseHandler responseHandler = new InputStreamFullResponseHandler();
    ClientResponse<InputStreamFullResponseHolder> clientResp = responseHandler.handleResponse(response, null);
    DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer("efg".getBytes(StringUtils.UTF8_STRING)));
    clientResp = responseHandler.handleChunk(clientResp, chunk, 0);
    clientResp = responseHandler.done(clientResp);
    Assert.assertTrue(clientResp.isFinished());
    Assert.assertEquals("abcdefg", IOUtils.toString(clientResp.getObj().getContent(), StandardCharsets.UTF_8));
}
Also used : DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Test(org.junit.Test)

Example 2 with BigEndianHeapChannelBuffer

use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.

the class InputStreamFullResponseHandlerTest method testException.

@Test
public void testException() throws Exception {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.setChunked(false);
    response.setContent(new BigEndianHeapChannelBuffer("abcd".getBytes(StringUtils.UTF8_STRING)));
    InputStreamFullResponseHandler responseHandler = new InputStreamFullResponseHandler();
    ClientResponse<InputStreamFullResponseHolder> clientResp = responseHandler.handleResponse(response, null);
    Exception ex = new RuntimeException("dummy!");
    responseHandler.exceptionCaught(clientResp, ex);
    Assert.assertTrue(clientResp.isFinished());
}
Also used : DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Test(org.junit.Test)

Example 3 with BigEndianHeapChannelBuffer

use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.

the class SequenceInputStreamResponseHandlerTest method alignedMultiStreamTest.

@Test
public void alignedMultiStreamTest() throws IOException {
    Iterator<byte[]> it = BYTE_LIST.iterator();
    SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
    final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.setChunked(true);
    ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
    long chunkNum = 0;
    while (it.hasNext()) {
        final DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer(it.next()));
        clientResponse = responseHandler.handleChunk(clientResponse, chunk, ++chunkNum);
    }
    clientResponse = responseHandler.done(clientResponse);
    final InputStream stream = clientResponse.getObj();
    final InputStream expectedStream = new ByteArrayInputStream(allBytes);
    for (byte[] bytes : BYTE_LIST) {
        final byte[] expectedBytes = new byte[bytes.length];
        final byte[] actualBytes = new byte[expectedBytes.length];
        fillBuff(stream, actualBytes);
        fillBuff(expectedStream, expectedBytes);
        Assert.assertArrayEquals(expectedBytes, actualBytes);
        Assert.assertArrayEquals(expectedBytes, bytes);
    }
    Assert.assertEquals(allBytes.length, responseHandler.getByteCount());
}
Also used : DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Test(org.junit.Test)

Example 4 with BigEndianHeapChannelBuffer

use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.

the class SequenceInputStreamResponseHandlerTest method testExceptionalSingleStream.

@Test(expected = TesterException.class)
public void testExceptionalSingleStream() throws IOException {
    SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
    final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.setChunked(false);
    response.setContent(new BigEndianHeapChannelBuffer(allBytes) {

        @Override
        public void getBytes(int index, byte[] dst, int dstIndex, int length) {
            if (dstIndex + length >= allBytes.length) {
                throw new TesterException();
            }
            super.getBytes(index, dst, dstIndex, length);
        }
    });
    ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
    clientResponse = responseHandler.done(clientResponse);
    final InputStream stream = clientResponse.getObj();
    final byte[] buff = new byte[allBytes.length];
    fillBuff(stream, buff);
}
Also used : DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Test(org.junit.Test)

Example 5 with BigEndianHeapChannelBuffer

use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.

the class SequenceInputStreamResponseHandlerTest method simpleMultiStreamTest.

@Test
public void simpleMultiStreamTest() throws IOException {
    Iterator<byte[]> it = BYTE_LIST.iterator();
    SequenceInputStreamResponseHandler responseHandler = new SequenceInputStreamResponseHandler();
    final HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.setChunked(true);
    ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
    long chunkNum = 0;
    while (it.hasNext()) {
        final DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer(it.next()));
        clientResponse = responseHandler.handleChunk(clientResponse, chunk, ++chunkNum);
    }
    clientResponse = responseHandler.done(clientResponse);
    final InputStream stream = clientResponse.getObj();
    final InputStream expectedStream = new ByteArrayInputStream(allBytes);
    int read = 0;
    while (read < allBytes.length) {
        final byte[] expectedBytes = new byte[Math.min(RANDOM.nextInt(128), allBytes.length - read)];
        final byte[] actualBytes = new byte[expectedBytes.length];
        fillBuff(stream, actualBytes);
        fillBuff(expectedStream, expectedBytes);
        Assert.assertArrayEquals(expectedBytes, actualBytes);
        read += expectedBytes.length;
    }
    Assert.assertEquals(allBytes.length, responseHandler.getByteCount());
}
Also used : DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Test(org.junit.Test)

Aggregations

BigEndianHeapChannelBuffer (org.jboss.netty.buffer.BigEndianHeapChannelBuffer)19 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)19 Test (org.junit.Test)18 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)10 URL (java.net.URL)8 Request (org.apache.druid.java.util.http.client.Request)8 StringFullResponseHolder (org.apache.druid.java.util.http.client.response.StringFullResponseHolder)8 InputStream (java.io.InputStream)6 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Either (org.apache.druid.java.util.common.Either)3 RetryPolicyFactory (org.apache.druid.indexing.common.RetryPolicyFactory)2 NoopTask (org.apache.druid.indexing.common.task.NoopTask)2 Task (org.apache.druid.indexing.common.task.Task)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 RetryPolicyConfig (org.apache.druid.indexing.common.RetryPolicyConfig)1 TaskLock (org.apache.druid.indexing.common.TaskLock)1 TimeChunkLock (org.apache.druid.indexing.common.TimeChunkLock)1 DataSegment (org.apache.druid.timeline.DataSegment)1