use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class CoordinatorRuleManagerTest method mockClient.
private DruidLeaderClient mockClient() {
final Map<String, List<Rule>> rules = ImmutableMap.of(DATASOURCE1, ImmutableList.of(new ForeverLoadRule(null)), DATASOURCE2, ImmutableList.of(new ForeverLoadRule(null), new IntervalDropRule(Intervals.of("2020-01-01/2020-01-02"))), "datasource3", ImmutableList.of(new PeriodLoadRule(new Period("P1M"), true, null), new ForeverDropRule()), TieredBrokerConfig.DEFAULT_RULE_NAME, ImmutableList.of(new ForeverLoadRule(ImmutableMap.of("__default", 2))));
final StringFullResponseHolder holder = EasyMock.niceMock(StringFullResponseHolder.class);
EasyMock.expect(holder.getStatus()).andReturn(HttpResponseStatus.OK);
try {
EasyMock.expect(holder.getContent()).andReturn(objectMapper.writeValueAsString(rules));
final DruidLeaderClient client = EasyMock.niceMock(DruidLeaderClient.class);
EasyMock.expect(client.go(EasyMock.anyObject())).andReturn(holder);
EasyMock.replay(holder, client);
return client;
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class CoordinatorRuleManager method poll.
public void poll() {
try {
StringFullResponseHolder response = druidLeaderClient.go(druidLeaderClient.makeRequest(HttpMethod.GET, RulesResource.RULES_ENDPOINT));
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while polling rules, status[%s] content[%s]", response.getStatus(), response.getContent());
}
final Map<String, List<Rule>> map = jsonMapper.readValue(response.getContent(), TYPE_REFERENCE);
final Map<String, List<Rule>> immutableMapBuilder = Maps.newHashMapWithExpectedSize(map.size());
map.forEach((k, list) -> immutableMapBuilder.put(k, Collections.unmodifiableList(list)));
rules.set(Collections.unmodifiableMap(immutableMapBuilder));
} catch (Exception e) {
LOG.error(e, "Exception while polling for rules");
}
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class LookupReferencesManagerTest method testStartStop.
@Test
public void testStartStop() throws InterruptedException, IOException {
lookupReferencesManager = new LookupReferencesManager(new LookupConfig(null), mapper, druidLeaderClient, config);
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForStartStop", 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);
Assert.assertFalse(lookupReferencesManager.lifecycleLock.awaitStarted(1, TimeUnit.MICROSECONDS));
Assert.assertNull(lookupReferencesManager.mainThread);
Assert.assertNull(lookupReferencesManager.stateRef.get());
lookupReferencesManager.start();
Assert.assertTrue(lookupReferencesManager.lifecycleLock.awaitStarted(1, TimeUnit.MICROSECONDS));
Assert.assertTrue(lookupReferencesManager.mainThread.isAlive());
Assert.assertNotNull(lookupReferencesManager.stateRef.get());
lookupReferencesManager.stop();
Assert.assertFalse(lookupReferencesManager.lifecycleLock.awaitStarted(1, TimeUnit.MICROSECONDS));
Assert.assertFalse(lookupReferencesManager.mainThread.isAlive());
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class LookupReferencesManagerTest method testAddGetRemove.
@Test
public void testAddGetRemove() throws Exception {
LookupExtractorFactory lookupExtractorFactory = EasyMock.createMock(LookupExtractorFactory.class);
EasyMock.expect(lookupExtractorFactory.start()).andReturn(true).once();
EasyMock.expect(lookupExtractorFactory.destroy()).andReturn(true).once();
EasyMock.replay(lookupExtractorFactory);
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForAddGetRemove", 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.assertEquals(Optional.empty(), lookupReferencesManager.get("test"));
LookupExtractorFactoryContainer testContainer = new LookupExtractorFactoryContainer("0", lookupExtractorFactory);
lookupReferencesManager.add("test", testContainer);
lookupReferencesManager.handlePendingNotices();
Assert.assertEquals(Optional.of(testContainer), lookupReferencesManager.get("test"));
lookupReferencesManager.remove("test");
lookupReferencesManager.handlePendingNotices();
Assert.assertEquals(Optional.empty(), lookupReferencesManager.get("test"));
}
use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by druid-io.
the class LookupReferencesManagerTest method testDestroyIsCalledAfterRemove.
@Test
public void testDestroyIsCalledAfterRemove() throws Exception {
LookupExtractorFactory lookupExtractorFactory = EasyMock.createStrictMock(LookupExtractorFactory.class);
EasyMock.expect(lookupExtractorFactory.start()).andReturn(true).once();
EasyMock.expect(lookupExtractorFactory.destroy()).andReturn(true).once();
EasyMock.replay(lookupExtractorFactory);
Map<String, Object> lookupMap = new HashMap<>();
lookupMap.put("testMockForDestroyIsCalledAfterRemove", 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.remove("testMock");
lookupReferencesManager.handlePendingNotices();
EasyMock.verify(lookupExtractorFactory);
}
Aggregations