Search in sources :

Example 31 with StringFullResponseHolder

use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.

the class LookupReferencesManagerTest method testUpdateWithHigherVersion.

@Test
public void testUpdateWithHigherVersion() throws Exception {
    LookupExtractorFactory lookupExtractorFactory1 = EasyMock.createNiceMock(LookupExtractorFactory.class);
    EasyMock.expect(lookupExtractorFactory1.start()).andReturn(true).once();
    EasyMock.expect(lookupExtractorFactory1.destroy()).andReturn(true).once();
    LookupExtractorFactory lookupExtractorFactory2 = EasyMock.createNiceMock(LookupExtractorFactory.class);
    EasyMock.expect(lookupExtractorFactory2.start()).andReturn(true).once();
    EasyMock.replay(lookupExtractorFactory1, lookupExtractorFactory2);
    Map<String, Object> lookupMap = new HashMap<>();
    lookupMap.put("testMockForUpdateWithHigherVersion", 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("2", lookupExtractorFactory2));
    lookupReferencesManager.handlePendingNotices();
    EasyMock.verify(lookupExtractorFactory1, lookupExtractorFactory2);
}
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 32 with StringFullResponseHolder

use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.

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"));
}
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 33 with StringFullResponseHolder

use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.

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 34 with StringFullResponseHolder

use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.

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();
}
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 35 with StringFullResponseHolder

use of org.apache.druid.java.util.http.client.response.StringFullResponseHolder in project druid by apache.

the class LookupReferencesManagerTest method testCoordinatorLookupSync.

@Test
public void testCoordinatorLookupSync() 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<>();
    lookupMap.put("testLookup1", container1);
    lookupMap.put("testLookup2", container2);
    lookupMap.put("testLookup3", container3);
    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.of(container1), lookupReferencesManager.get("testLookup1"));
    Assert.assertEquals(Optional.of(container2), lookupReferencesManager.get("testLookup2"));
    Assert.assertEquals(Optional.of(container3), lookupReferencesManager.get("testLookup3"));
}
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