use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class LookupReferencesManagerTest method testGetAllLookupNames.
@Test
public void testGetAllLookupNames() throws Exception {
LookupExtractorFactoryContainer container1 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key1", "value1"), true));
LookupExtractorFactoryContainer container2 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key2", "value2"), true));
Map<String, Object> lookupMap = new HashMap<>();
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("one", container1);
lookupReferencesManager.add("two", container2);
lookupReferencesManager.handlePendingNotices();
Assert.assertEquals(ImmutableSet.of("one", "two"), lookupReferencesManager.getAllLookupNames());
Assert.assertEquals(ImmutableSet.of("one", "two"), ((LookupExtractorFactoryContainerProvider) lookupReferencesManager).getAllLookupNames());
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
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 apache.
the class LookupReferencesManagerTest method testRealModeWithMainThread.
@Test(timeout = 60_000L)
public void testRealModeWithMainThread() throws Exception {
LookupReferencesManager lookupReferencesManager = new LookupReferencesManager(new LookupConfig(temporaryFolder.newFolder().getAbsolutePath()), mapper, druidLeaderClient, config);
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForRealModeWithMainThread", 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();
Assert.assertTrue(lookupReferencesManager.mainThread.isAlive());
LookupExtractorFactory lookupExtractorFactory = EasyMock.createMock(LookupExtractorFactory.class);
EasyMock.expect(lookupExtractorFactory.start()).andReturn(true).once();
EasyMock.expect(lookupExtractorFactory.destroy()).andReturn(true).once();
EasyMock.replay(lookupExtractorFactory);
Assert.assertEquals(Optional.empty(), lookupReferencesManager.get("test"));
LookupExtractorFactoryContainer testContainer = new LookupExtractorFactoryContainer("0", lookupExtractorFactory);
lookupReferencesManager.add("test", testContainer);
while (!Optional.of(testContainer).equals(lookupReferencesManager.get("test"))) {
Thread.sleep(100);
}
Assert.assertEquals(ImmutableSet.of("test", "testMockForRealModeWithMainThread"), lookupReferencesManager.getAllLookupNames());
lookupReferencesManager.remove("test");
while (lookupReferencesManager.get("test").isPresent()) {
Thread.sleep(100);
}
Assert.assertEquals(ImmutableSet.of("testMockForRealModeWithMainThread"), lookupReferencesManager.getAllLookupNames());
lookupReferencesManager.stop();
Assert.assertFalse(lookupReferencesManager.mainThread.isAlive());
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class LookupReferencesManagerTest method testGetAllLookupsState.
@Test
public void testGetAllLookupsState() throws Exception {
LookupExtractorFactoryContainer container1 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key1", "value1"), true));
LookupExtractorFactoryContainer container2 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key2", "value2"), true));
LookupExtractorFactoryContainer container3 = new LookupExtractorFactoryContainer("0", new MapLookupExtractorFactory(ImmutableMap.of("key3", "value3"), true));
Map<String, Object> lookupMap = new HashMap<>();
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("one", container1);
lookupReferencesManager.add("two", container2);
lookupReferencesManager.handlePendingNotices();
lookupReferencesManager.remove("one");
lookupReferencesManager.add("three", container3);
LookupsState state = lookupReferencesManager.getAllLookupsState();
Assert.assertEquals(2, state.getCurrent().size());
Assert.assertEquals(container1, state.getCurrent().get("one"));
Assert.assertEquals(container2, state.getCurrent().get("two"));
Assert.assertEquals(1, state.getToLoad().size());
Assert.assertEquals(container3, state.getToLoad().get("three"));
Assert.assertEquals(1, state.getToDrop().size());
Assert.assertTrue(state.getToDrop().contains("one"));
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.
the class RemoteTaskActionClient method submit.
@Override
public <RetType> RetType submit(TaskAction<RetType> taskAction) throws IOException {
log.debug("Performing action for task[%s]: %s", task.getId(), taskAction);
byte[] dataToSend = jsonMapper.writeValueAsBytes(new TaskActionHolder(task, taskAction));
final RetryPolicy retryPolicy = retryPolicyFactory.makeRetryPolicy();
while (true) {
try {
final StringFullResponseHolder fullResponseHolder;
log.debug("Submitting action for task[%s] to Overlord: %s", task.getId(), jsonMapper.writeValueAsString(taskAction));
fullResponseHolder = druidLeaderClient.go(druidLeaderClient.makeRequest(HttpMethod.POST, "/druid/indexer/v1/action").setContent(MediaType.APPLICATION_JSON, dataToSend));
if (fullResponseHolder.getStatus().getCode() / 100 == 2) {
final Map<String, Object> responseDict = jsonMapper.readValue(fullResponseHolder.getContent(), JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT);
return jsonMapper.convertValue(responseDict.get("result"), taskAction.getReturnTypeReference());
} else {
// Want to retry, so throw an IOException.
throw new IOE("Error with status[%s] and message[%s]. Check overlord logs for details.", fullResponseHolder.getStatus(), fullResponseHolder.getContent());
}
} catch (IOException | ChannelException e) {
log.noStackTrace().warn(e, "Exception submitting action for task[%s]: %s", task.getId(), jsonMapper.writeValueAsString(taskAction));
final Duration delay = retryPolicy.getAndIncrementRetryDelay();
if (delay == null) {
throw e;
} else {
try {
final long sleepTime = jitter(delay.getMillis());
log.warn("Will try again in [%s].", new Duration(sleepTime).toString());
Thread.sleep(sleepTime);
} catch (InterruptedException e2) {
throw new RuntimeException(e2);
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
Aggregations