use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class LookupReferencesManagerTest method testRemoveNonExisting.
@Test
public void testRemoveNonExisting() throws Exception {
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForRemoveNonExisting", 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.remove("test");
lookupReferencesManager.handlePendingNotices();
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class LookupReferencesManagerTest method testCloseIsCalledAfterStopping.
@Test
public void testCloseIsCalledAfterStopping() throws Exception {
LookupExtractorFactory lookupExtractorFactory = EasyMock.createStrictMock(LookupExtractorFactory.class);
EasyMock.expect(lookupExtractorFactory.start()).andReturn(true).once();
EasyMock.expect(lookupExtractorFactory.close()).andReturn(true).once();
EasyMock.replay(lookupExtractorFactory);
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForCloseIsCalledAfterStopping", 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("testMock", new LookupExtractorFactoryContainer("0", lookupExtractorFactory));
lookupReferencesManager.handlePendingNotices();
lookupReferencesManager.stop();
EasyMock.verify(lookupExtractorFactory);
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class LookupReferencesManagerTest method testDisableLookupSync.
@Test
public void testDisableLookupSync() throws Exception {
LookupConfig lookupConfig = new LookupConfig(null) {
@Override
public boolean getEnableLookupSyncOnStartup() {
return false;
}
};
LookupReferencesManager lookupReferencesManager = new LookupReferencesManager(lookupConfig, mapper, druidLeaderClient, config);
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForDisableLookupSync", 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);
lookupReferencesManager.start();
Assert.assertEquals(Optional.empty(), lookupReferencesManager.get("testMockForDisableLookupSync"));
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class IndexTaskClientTest method dontRetryOnBadRequest.
@Test
public void dontRetryOnBadRequest() {
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.BAD_REQUEST), StandardCharsets.UTF_8).addChunk("Error")))).times(1);
EasyMock.replay(httpClient);
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
final IllegalArgumentException e = Assert.assertThrows(IllegalArgumentException.class, () -> indexTaskClient.submitRequestWithEmptyContent("taskId", HttpMethod.GET, "test", null, true));
Assert.assertEquals("Received server error with status [400 Bad Request]; 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 retryIfNotFoundWithIncorrectTaskId.
@Test
public void retryIfNotFoundWithIncorrectTaskId() throws IOException {
final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
final String taskId = "taskId";
final String incorrectTaskId = "incorrectTaskId";
final DefaultHttpResponse incorrectResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
incorrectResponse.headers().add(ChatHandlerResource.TASK_ID_HEADER, incorrectTaskId);
final DefaultHttpResponse correctResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
correctResponse.headers().add(ChatHandlerResource.TASK_ID_HEADER, taskId);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(incorrectResponse, StandardCharsets.UTF_8)))).times(2);
EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.value(new StringFullResponseHolder(correctResponse, 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);
}
Aggregations