use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class SequenceInputStreamResponseHandlerTest method testExceptionalChunkedStream.
@Test(expected = TesterException.class)
public void testExceptionalChunkedStream() 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);
final int failAt = RANDOM.nextInt(allBytes.length);
long chunkNum = 0;
while (it.hasNext()) {
final DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer(it.next()) {
@Override
public void getBytes(int index, byte[] dst, int dstIndex, int length) {
if (dstIndex + length >= failAt) {
throw new TesterException();
}
super.getBytes(index, dst, dstIndex, length);
}
});
clientResponse = responseHandler.handleChunk(clientResponse, chunk, ++chunkNum);
}
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 simpleSingleStreamTest.
@Test
public void simpleSingleStreamTest() 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));
ClientResponse<InputStream> clientResponse = responseHandler.handleResponse(response, null);
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());
}
use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class ObjectOrErrorResponseHandlerTest method testExceptionAfterOk.
@Test
public void testExceptionAfterOk() throws Exception {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
response.setChunked(false);
response.setContent(new BigEndianHeapChannelBuffer("abcd".getBytes(StringUtils.UTF8_STRING)));
final ObjectOrErrorResponseHandler<InputStreamFullResponseHolder, InputStreamFullResponseHolder> responseHandler = new ObjectOrErrorResponseHandler<>(new InputStreamFullResponseHandler());
ClientResponse<Either<StringFullResponseHolder, InputStreamFullResponseHolder>> clientResp = responseHandler.handleResponse(response, null);
Exception ex = new RuntimeException("dummy!");
responseHandler.exceptionCaught(clientResp, ex);
// Exception after HTTP OK still is handled by the "OK handler"
// (The handler that starts the request gets to finish it.)
Assert.assertTrue(clientResp.isFinished());
Assert.assertTrue(clientResp.getObj().isValue());
final InputStream responseStream = clientResp.getObj().valueOrThrow().getContent();
final IOException e = Assert.assertThrows(IOException.class, () -> IOUtils.toString(responseStream, StandardCharsets.UTF_8));
Assert.assertEquals("java.lang.RuntimeException: dummy!", e.getMessage());
}
use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class HttpIndexingServiceClientTest method testGetTotalWorkerCapacityWithAutoScale.
@Test
public void testGetTotalWorkerCapacityWithAutoScale() throws Exception {
int currentClusterCapacity = 5;
int maximumCapacityWithAutoScale = 10;
// Mock response for /druid/indexer/v1/totalWorkerCapacity
HttpResponse totalWorkerCapacityResponse = EasyMock.createMock(HttpResponse.class);
EasyMock.expect(totalWorkerCapacityResponse.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
EasyMock.expect(totalWorkerCapacityResponse.getContent()).andReturn(new BigEndianHeapChannelBuffer(0));
EasyMock.replay(totalWorkerCapacityResponse);
IndexingTotalWorkerCapacityInfo indexingTotalWorkerCapacityInfo = new IndexingTotalWorkerCapacityInfo(currentClusterCapacity, maximumCapacityWithAutoScale);
StringFullResponseHolder autoScaleResponseHolder = new StringFullResponseHolder(totalWorkerCapacityResponse, StandardCharsets.UTF_8).addChunk(jsonMapper.writeValueAsString(indexingTotalWorkerCapacityInfo));
EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class))).andReturn(autoScaleResponseHolder).once();
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/indexer/v1/totalWorkerCapacity")).andReturn(new Request(HttpMethod.GET, new URL("http://localhost:8090/druid/indexer/v1/totalWorkerCapacity"))).once();
EasyMock.replay(druidLeaderClient);
final int actualResponse = httpIndexingServiceClient.getTotalWorkerCapacityWithAutoScale();
Assert.assertEquals(maximumCapacityWithAutoScale, actualResponse);
EasyMock.verify(druidLeaderClient);
}
use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class HttpIndexingServiceClientTest method testCompact.
@Test
public void testCompact() throws Exception {
DataSegment segment = new DataSegment("test", Intervals.of("2015-04-12/2015-04-13"), "1", ImmutableMap.of("bucket", "bucket", "path", "test/2015-04-12T00:00:00.000Z_2015-04-13T00:00:00.000Z/1/0/index.zip"), null, null, NoneShardSpec.instance(), 0, 1);
Capture captureTask = EasyMock.newCapture();
HttpResponse response = EasyMock.createMock(HttpResponse.class);
EasyMock.expect(response.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
EasyMock.expect(response.getContent()).andReturn(new BigEndianHeapChannelBuffer(0));
EasyMock.replay(response);
StringFullResponseHolder responseHolder = new StringFullResponseHolder(response, StandardCharsets.UTF_8).addChunk(jsonMapper.writeValueAsString(ImmutableMap.of("task", "aaa")));
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.POST, "/druid/indexer/v1/task")).andReturn(new Request(HttpMethod.POST, new URL("http://localhost:8090/druid/indexer/v1/task"))).anyTimes();
EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class))).andReturn(responseHolder).anyTimes();
EasyMock.expect(mockMapper.writeValueAsBytes(EasyMock.capture(captureTask))).andReturn(new byte[] { 1, 2, 3 }).anyTimes();
EasyMock.expect(mockMapper.readValue(EasyMock.anyString(), EasyMock.eq(JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT))).andReturn(ImmutableMap.of()).anyTimes();
EasyMock.replay(druidLeaderClient, mockMapper);
HttpIndexingServiceClient httpIndexingServiceClient = new HttpIndexingServiceClient(mockMapper, druidLeaderClient);
try {
httpIndexingServiceClient.compactSegments("test-compact", ImmutableList.of(segment), 50, null, null, null, null, null, null, null);
} catch (Exception e) {
// Ignore IllegalStateException as taskId is internally generated and returned task id will failed check
Assert.assertEquals(IllegalStateException.class.getName(), e.getCause().getClass().getName());
}
ClientCompactionTaskQuery taskQuery = (ClientCompactionTaskQuery) captureTask.getValue();
Assert.assertNull(taskQuery.getIoConfig().getInputSpec().getSha256OfSortedSegmentIds());
}
Aggregations