Search in sources :

Example 11 with BigEndianHeapChannelBuffer

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;
}
Also used : HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer)

Example 12 with BigEndianHeapChannelBuffer

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));
}
Also used : DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Either(org.apache.druid.java.util.common.Either) Test(org.junit.Test)

Example 13 with BigEndianHeapChannelBuffer

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());
}
Also used : DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) Either(org.apache.druid.java.util.common.Either) Test(org.junit.Test)

Example 14 with BigEndianHeapChannelBuffer

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);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) URL(java.net.URL) Test(org.junit.Test)

Example 15 with BigEndianHeapChannelBuffer

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);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BigEndianHeapChannelBuffer(org.jboss.netty.buffer.BigEndianHeapChannelBuffer) URL(java.net.URL) 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