use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class IndexTaskClientTest method dontRetryIfNotFoundWithCorrectTaskId.
@Test
public void dontRetryIfNotFoundWithCorrectTaskId() {
final String taskId = "taskId";
final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
response.headers().add(ChatHandlerResource.TASK_ID_HEADER, taskId);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(response, StandardCharsets.UTF_8).addChunk("Error")))).times(1);
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final IOException e = Assert.assertThrows(IOException.class, () -> indexTaskClient.submitRequestWithEmptyContent(taskId, HttpMethod.GET, "test", null, false));
Assert.assertEquals("Received server error with status [404 Not Found]; first 1KB of body: Error", e.getMessage());
}
EasyMock.verify(httpClient);
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class IndexTaskClientTest method retryOnChannelException.
@Test
public void retryOnChannelException() throws IOException {
final HttpClient httpClient = EasyMock.createNiceMock(HttpClient.class);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFailedFuture(new ChannelException("IndexTaskClientTest"))).times(2);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.value(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK), StandardCharsets.UTF_8)))).once();
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final StringFullResponseHolder response = indexTaskClient.submitRequestWithEmptyContent("taskId", HttpMethod.GET, "test", null, true);
Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
}
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class IndexTaskClientTest method retryOnServerError.
@Test
public void retryOnServerError() throws IOException {
final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR), StandardCharsets.UTF_8).addChunk("Error")))).times(2);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.value(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK), StandardCharsets.UTF_8)))).once();
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final StringFullResponseHolder response = indexTaskClient.submitRequestWithEmptyContent("taskId", HttpMethod.GET, "test", null, true);
Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
}
EasyMock.verify(httpClient);
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class IndexTaskClientTest method dontRetryIfRetryFalse.
@Test
public void dontRetryIfRetryFalse() {
final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR), StandardCharsets.UTF_8).addChunk("Error")))).times(1);
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final IOException e = Assert.assertThrows(IOException.class, () -> indexTaskClient.submitRequestWithEmptyContent("taskId", HttpMethod.GET, "test", null, false));
Assert.assertEquals("Received server error with status [500 Internal Server Error]; first 1KB of body: Error", e.getMessage());
}
EasyMock.verify(httpClient);
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class LookupReferencesManagerTest method testUpdateWithLowerVersion.
@Test
public void testUpdateWithLowerVersion() throws Exception {
LookupExtractorFactory lookupExtractorFactory1 = EasyMock.createNiceMock(LookupExtractorFactory.class);
EasyMock.expect(lookupExtractorFactory1.start()).andReturn(true).once();
LookupExtractorFactory lookupExtractorFactory2 = EasyMock.createNiceMock(LookupExtractorFactory.class);
EasyMock.replay(lookupExtractorFactory1, lookupExtractorFactory2);
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForUpdateWithLowerVersion", container);
String strResult = mapper.writeValueAsString(lookupMap);
Request request = new Request(HttpMethod.GET, new URL("http://localhost:1234/xx"));
EasyMock.expect(config.getLookupTier()).andReturn(LOOKUP_TIER).anyTimes();
EasyMock.replay(config);
EasyMock.expect(druidLeaderClient.makeRequest(HttpMethod.GET, "/druid/coordinator/v1/lookups/config/lookupTier?detailed=true")).andReturn(request);
StringFullResponseHolder responseHolder = new StringFullResponseHolder(newEmptyResponse(HttpResponseStatus.OK), StandardCharsets.UTF_8).addChunk(strResult);
EasyMock.expect(druidLeaderClient.go(request)).andReturn(responseHolder);
EasyMock.replay(druidLeaderClient);
lookupReferencesManager.start();
lookupReferencesManager.add("testName", new LookupExtractorFactoryContainer("1", lookupExtractorFactory1));
lookupReferencesManager.handlePendingNotices();
lookupReferencesManager.add("testName", new LookupExtractorFactoryContainer("0", lookupExtractorFactory2));
lookupReferencesManager.handlePendingNotices();
EasyMock.verify(lookupExtractorFactory1, lookupExtractorFactory2);
}
Aggregations