Search in sources :

Example 1 with SequenceInputStreamResponseHandler

use of com.metamx.http.client.response.SequenceInputStreamResponseHandler in project druid by druid-io.

the class LookupCoordinatorManagerTest method testUpdateAllOnHostException.

@Test
public void testUpdateAllOnHostException() throws Exception {
    final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
    final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
    final SettableFuture<InputStream> future = SettableFuture.create();
    future.set(new ByteArrayInputStream(new byte[0]));
    EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
    EasyMock.replay(client, responseHandler);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
            returnCode.set(500);
            reasonString.set("");
            return responseHandler;
        }
    };
    expectedException.expect(new BaseMatcher<Throwable>() {

        @Override
        public boolean matches(Object o) {
            return o instanceof IOException && ((IOException) o).getMessage().startsWith("Bad update request");
        }

        @Override
        public void describeTo(Description description) {
        }
    });
    try {
        manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
    } finally {
        EasyMock.verify(client, responseHandler);
    }
}
Also used : Description(org.hamcrest.Description) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) Duration(org.joda.time.Duration) AtomicReference(java.util.concurrent.atomic.AtomicReference) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) IOException(java.io.IOException) URL(java.net.URL) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 2 with SequenceInputStreamResponseHandler

use of com.metamx.http.client.response.SequenceInputStreamResponseHandler in project druid by druid-io.

the class LookupCoordinatorManagerTest method testUpdateAllOnHostFailsWithFailedThings.

@Test
public void testUpdateAllOnHostFailsWithFailedThings() throws Exception {
    final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
    final String failedLookup = "failedLookup";
    final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
    final SettableFuture<InputStream> future = SettableFuture.create();
    future.set(new ByteArrayInputStream(StringUtils.toUtf8(mapper.writeValueAsString(ImmutableMap.of("status", "accepted", LookupModule.FAILED_UPDATES_KEY, ImmutableMap.of(failedLookup, ImmutableMap.of()))))));
    EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
    EasyMock.replay(client, responseHandler);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
            returnCode.set(200);
            reasonString.set("");
            return responseHandler;
        }
    };
    expectedException.expectMessage("Lookups failed to update: [\"" + failedLookup + "\"]");
    try {
        manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
    } finally {
        EasyMock.verify(client, responseHandler);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) Duration(org.joda.time.Duration) AtomicReference(java.util.concurrent.atomic.AtomicReference) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Example 3 with SequenceInputStreamResponseHandler

use of com.metamx.http.client.response.SequenceInputStreamResponseHandler in project druid by druid-io.

the class LookupCoordinatorManagerTest method testDeleteAllTierMissing.

@Test
public void testDeleteAllTierMissing() throws Exception {
    final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
            returnCode.set(404);
            reasonString.set("");
            return responseHandler;
        }
    };
    final HostAndPort hostAndPort = HostAndPort.fromParts("someHost", 8080);
    final Collection<String> drop = ImmutableList.of("lookup1");
    EasyMock.expect(discoverer.getNodes(LookupModule.getTierListenerPath(LOOKUP_TIER))).andReturn(ImmutableList.of(hostAndPort)).once();
    final SettableFuture<InputStream> future = SettableFuture.create();
    future.set(new ByteArrayInputStream(new byte[0]));
    EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
    EasyMock.replay(client, discoverer, responseHandler);
    manager.deleteAllOnTier(LOOKUP_TIER, drop);
    EasyMock.verify(client, discoverer, responseHandler);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(org.joda.time.Duration) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) HostAndPort(com.google.common.net.HostAndPort) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 4 with SequenceInputStreamResponseHandler

use of com.metamx.http.client.response.SequenceInputStreamResponseHandler in project druid by druid-io.

the class LookupCoordinatorManagerTest method testDeleteAllTierContinuesOnMissing.

@Test
public void testDeleteAllTierContinuesOnMissing() throws Exception {
    final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
    final AtomicInteger responseHandlerCalls = new AtomicInteger(0);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
            if (responseHandlerCalls.getAndIncrement() == 0) {
                returnCode.set(404);
                reasonString.set("Not Found");
            } else {
                returnCode.set(202);
                reasonString.set("");
            }
            return responseHandler;
        }
    };
    final HostAndPort hostAndPort = HostAndPort.fromParts("someHost", 8080);
    final Collection<String> drop = ImmutableList.of("lookup1");
    EasyMock.expect(discoverer.getNodes(LookupModule.getTierListenerPath(LOOKUP_TIER))).andReturn(ImmutableList.of(hostAndPort, hostAndPort)).once();
    final SettableFuture<InputStream> future = SettableFuture.create();
    future.set(new ByteArrayInputStream(new byte[0]));
    EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).times(2);
    EasyMock.replay(client, discoverer, responseHandler);
    manager.deleteAllOnTier(LOOKUP_TIER, drop);
    EasyMock.verify(client, discoverer, responseHandler);
    Assert.assertEquals(2, responseHandlerCalls.get());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(org.joda.time.Duration) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) HostAndPort(com.google.common.net.HostAndPort) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 5 with SequenceInputStreamResponseHandler

use of com.metamx.http.client.response.SequenceInputStreamResponseHandler in project druid by druid-io.

the class LookupCoordinatorManagerTest method testUpdateAllOnHost.

@Test
public void testUpdateAllOnHost() throws Exception {
    final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
    final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
    final SettableFuture<InputStream> future = SettableFuture.create();
    future.set(new ByteArrayInputStream(StringUtils.toUtf8(mapper.writeValueAsString(ImmutableMap.of("status", "accepted", LookupModule.FAILED_UPDATES_KEY, ImmutableMap.of())))));
    EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
    EasyMock.replay(client, responseHandler);
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
            returnCode.set(200);
            reasonString.set("");
            return responseHandler;
        }
    };
    manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
    EasyMock.verify(client, responseHandler);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) Duration(org.joda.time.Duration) AtomicReference(java.util.concurrent.atomic.AtomicReference) SequenceInputStreamResponseHandler(com.metamx.http.client.response.SequenceInputStreamResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Request (com.metamx.http.client.Request)7 SequenceInputStreamResponseHandler (com.metamx.http.client.response.SequenceInputStreamResponseHandler)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Duration (org.joda.time.Duration)7 Test (org.junit.Test)7 URL (java.net.URL)4 HostAndPort (com.google.common.net.HostAndPort)3 IOException (java.io.IOException)1 Description (org.hamcrest.Description)1