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));
}
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());
}
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());
}
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);
}
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());
}
Aggregations