Search in sources :

Example 56 with StringFullResponseHolder

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);
    }
}
Also used : Period(org.joda.time.Period) IntervalDropRule(org.apache.druid.server.coordinator.rules.IntervalDropRule) DruidLeaderClient(org.apache.druid.discovery.DruidLeaderClient) IOException(java.io.IOException) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) ForeverDropRule(org.apache.druid.server.coordinator.rules.ForeverDropRule) ForeverLoadRule(org.apache.druid.server.coordinator.rules.ForeverLoadRule) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PeriodLoadRule(org.apache.druid.server.coordinator.rules.PeriodLoadRule)

Example 57 with StringFullResponseHolder

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");
    }
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) ISE(org.apache.druid.java.util.common.ISE) ArrayList(java.util.ArrayList) List(java.util.List)

Example 58 with StringFullResponseHolder

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());
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) HashMap(java.util.HashMap) Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) Test(org.junit.Test)

Example 59 with StringFullResponseHolder

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"));
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) HashMap(java.util.HashMap) Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) Test(org.junit.Test)

Example 60 with StringFullResponseHolder

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);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) HashMap(java.util.HashMap) Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) Test(org.junit.Test)

Aggregations

StringFullResponseHolder (org.apache.druid.java.util.http.client.response.StringFullResponseHolder)86 Test (org.junit.Test)56 URL (java.net.URL)50 Request (org.apache.druid.java.util.http.client.Request)49 HashMap (java.util.HashMap)32 IOException (java.io.IOException)31 BigEndianHeapChannelBuffer (org.jboss.netty.buffer.BigEndianHeapChannelBuffer)18 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)18 ISE (org.apache.druid.java.util.common.ISE)16 HttpClient (org.apache.druid.java.util.http.client.HttpClient)12 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)12 ArrayList (java.util.ArrayList)8 List (java.util.List)8 ChannelException (org.jboss.netty.channel.ChannelException)8 MalformedURLException (java.net.MalformedURLException)7 ExecutionException (java.util.concurrent.ExecutionException)7 HttpResponseStatus (org.jboss.netty.handler.codec.http.HttpResponseStatus)6 Duration (org.joda.time.Duration)6 Interval (org.joda.time.Interval)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4