use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class LookupReferencesManagerTest method newEmptyResponse.
private static HttpResponse newEmptyResponse(final HttpResponseStatus status) {
final HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
EasyMock.expect(response.getStatus()).andReturn(status).anyTimes();
EasyMock.expect(response.getContent()).andReturn(new BigEndianHeapChannelBuffer(0));
EasyMock.replay(response);
return response;
}
use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class ObjectOrErrorResponseHandlerTest method testOk.
@Test
public void testOk() 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);
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().valueOrThrow().getContent(), StandardCharsets.UTF_8));
}
use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class ObjectOrErrorResponseHandlerTest method testServerError.
@Test
public void testServerError() throws Exception {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
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);
DefaultHttpChunk chunk = new DefaultHttpChunk(new BigEndianHeapChannelBuffer("efg".getBytes(StringUtils.UTF8_STRING)));
clientResp = responseHandler.handleChunk(clientResp, chunk, 0);
clientResp = responseHandler.done(clientResp);
// 5xx HTTP code is handled by the error handler.
Assert.assertTrue(clientResp.isFinished());
Assert.assertTrue(clientResp.getObj().isError());
Assert.assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode(), clientResp.getObj().error().getResponse().getStatus().getCode());
Assert.assertEquals("abcdefg", clientResp.getObj().error().getContent());
}
use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class HttpIndexingServiceClientTest method testSample.
@Test
public void testSample() throws Exception {
final SamplerResponse samplerResponse = new SamplerResponse(2, 2, ImmutableList.of(new SamplerResponse.SamplerResponseRow(ImmutableMap.of("time", "2020-01-01", "x", "123", "y", "456"), ImmutableMap.of("time", "2020-01-01", "x", "123", "y", "456"), false, null)));
final SamplerSpec samplerSpec = new SamplerSpec() {
@Override
public SamplerResponse sample() {
return samplerResponse;
}
};
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(samplerResponse));
EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class))).andReturn(responseHolder).anyTimes();
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.POST, "/druid/indexer/v1/sampler")).andReturn(new Request(HttpMethod.POST, new URL("http://localhost:8090/druid/indexer/v1/sampler"))).anyTimes();
EasyMock.replay(druidLeaderClient);
final SamplerResponse actualResponse = httpIndexingServiceClient.sample(samplerSpec);
Assert.assertEquals(samplerResponse, actualResponse);
EasyMock.verify(druidLeaderClient, response);
}
use of org.jboss.netty.buffer.BigEndianHeapChannelBuffer in project druid by druid-io.
the class HttpIndexingServiceClientTest method testGetTaskReportEmpty.
@Test
public void testGetTaskReportEmpty() throws Exception {
String taskId = "testTaskId";
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("");
EasyMock.expect(druidLeaderClient.go(EasyMock.anyObject(Request.class))).andReturn(responseHolder).anyTimes();
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/indexer/v1/task/testTaskId/reports")).andReturn(new Request(HttpMethod.GET, new URL("http://localhost:8090/druid/indexer/v1/task/testTaskId/reports"))).anyTimes();
EasyMock.replay(druidLeaderClient);
final Map<String, Object> actualResponse = httpIndexingServiceClient.getTaskReport(taskId);
Assert.assertNull(actualResponse);
EasyMock.verify(druidLeaderClient, response);
}
Aggregations