Search in sources :

Example 31 with Request

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

the class KafkaIndexTaskClientTest method testSetEndOffsetsAsync.

@Test
public void testSetEndOffsetsAsync() throws Exception {
    final Map<Integer, Long> endOffsets = ImmutableMap.of(0, 15L, 1, 120L);
    final int numRequests = TEST_IDS.size();
    Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
    expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    expect(httpClient.go(capture(captured), anyObject(FullResponseHandler.class), eq(TEST_HTTP_TIMEOUT))).andReturn(Futures.immediateFuture(responseHolder)).times(numRequests);
    replayAll();
    List<URL> expectedUrls = Lists.newArrayList();
    List<ListenableFuture<Boolean>> futures = Lists.newArrayList();
    for (int i = 0; i < numRequests; i++) {
        expectedUrls.add(new URL(String.format(URL_FORMATTER, TEST_HOST, TEST_PORT, TEST_IDS.get(i), "offsets/end")));
        futures.add(client.setEndOffsetsAsync(TEST_IDS.get(i), endOffsets));
    }
    List<Boolean> responses = Futures.allAsList(futures).get();
    verifyAll();
    List<Request> requests = captured.getValues();
    Assert.assertEquals(numRequests, requests.size());
    Assert.assertEquals(numRequests, responses.size());
    for (int i = 0; i < numRequests; i++) {
        Assert.assertEquals(HttpMethod.POST, requests.get(i).getMethod());
        Assert.assertTrue("unexpectedURL", expectedUrls.contains(requests.get(i).getUrl()));
        Assert.assertTrue(responses.get(i));
    }
}
Also used : Request(com.metamx.http.client.Request) URL(java.net.URL) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Test(org.junit.Test)

Example 32 with Request

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

the class KafkaIndexTaskClientTest method testPauseAsyncWithTimeout.

@Test
public void testPauseAsyncWithTimeout() throws Exception {
    final int numRequests = TEST_IDS.size();
    Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
    expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    expect(responseHolder.getContent()).andReturn("{\"0\":\"1\"}").anyTimes();
    expect(httpClient.go(capture(captured), anyObject(FullResponseHandler.class), eq(TEST_HTTP_TIMEOUT))).andReturn(Futures.immediateFuture(responseHolder)).times(numRequests);
    replayAll();
    List<URL> expectedUrls = Lists.newArrayList();
    List<ListenableFuture<Map<Integer, Long>>> futures = Lists.newArrayList();
    for (int i = 0; i < numRequests; i++) {
        expectedUrls.add(new URL(String.format(URL_FORMATTER, TEST_HOST, TEST_PORT, TEST_IDS.get(i), "pause?timeout=9")));
        futures.add(client.pauseAsync(TEST_IDS.get(i), 9));
    }
    List<Map<Integer, Long>> responses = Futures.allAsList(futures).get();
    verifyAll();
    List<Request> requests = captured.getValues();
    Assert.assertEquals(numRequests, requests.size());
    Assert.assertEquals(numRequests, responses.size());
    for (int i = 0; i < numRequests; i++) {
        Assert.assertEquals(HttpMethod.POST, requests.get(i).getMethod());
        Assert.assertTrue("unexpectedURL", expectedUrls.contains(requests.get(i).getUrl()));
        Assert.assertEquals(Maps.newLinkedHashMap(ImmutableMap.of(0, 1L)), responses.get(i));
    }
}
Also used : Request(com.metamx.http.client.Request) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) URL(java.net.URL) Test(org.junit.Test)

Example 33 with Request

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

the class KafkaIndexTaskClientTest method testGetCurrentOffsets.

@Test
public void testGetCurrentOffsets() throws Exception {
    Capture<Request> captured = Capture.newInstance();
    expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK);
    expect(responseHolder.getContent()).andReturn("{\"0\":1, \"1\":10}");
    expect(httpClient.go(capture(captured), anyObject(FullResponseHandler.class), eq(TEST_HTTP_TIMEOUT))).andReturn(Futures.immediateFuture(responseHolder));
    replayAll();
    Map<Integer, Long> results = client.getCurrentOffsets(TEST_ID, true);
    verifyAll();
    Request request = captured.getValue();
    Assert.assertEquals(HttpMethod.GET, request.getMethod());
    Assert.assertEquals(new URL("http://test-host:1234/druid/worker/v1/chat/test-id/offsets/current"), request.getUrl());
    Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
    Assert.assertEquals(2, results.size());
    Assert.assertEquals(1, (long) results.get(0));
    Assert.assertEquals(10, (long) results.get(1));
}
Also used : Request(com.metamx.http.client.Request) FullResponseHandler(com.metamx.http.client.response.FullResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Example 34 with Request

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

the class KafkaIndexTaskClientTest method testStopAndPublish.

@Test
public void testStopAndPublish() throws Exception {
    Capture<Request> captured = Capture.newInstance();
    expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    expect(httpClient.go(capture(captured), anyObject(FullResponseHandler.class), eq(TEST_HTTP_TIMEOUT))).andReturn(Futures.immediateFuture(responseHolder));
    replayAll();
    client.stop(TEST_ID, true);
    verifyAll();
    Request request = captured.getValue();
    Assert.assertEquals(HttpMethod.POST, request.getMethod());
    Assert.assertEquals(new URL("http://test-host:1234/druid/worker/v1/chat/test-id/stop?publish=true"), request.getUrl());
    Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
}
Also used : Request(com.metamx.http.client.Request) FullResponseHandler(com.metamx.http.client.response.FullResponseHandler) URL(java.net.URL) Test(org.junit.Test)

Example 35 with Request

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

the class KafkaIndexTaskClientTest method testResumeAsync.

@Test
public void testResumeAsync() throws Exception {
    final int numRequests = TEST_IDS.size();
    Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
    expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
    expect(httpClient.go(capture(captured), anyObject(FullResponseHandler.class), eq(TEST_HTTP_TIMEOUT))).andReturn(Futures.immediateFuture(responseHolder)).times(numRequests);
    replayAll();
    List<URL> expectedUrls = Lists.newArrayList();
    List<ListenableFuture<Boolean>> futures = Lists.newArrayList();
    for (int i = 0; i < numRequests; i++) {
        expectedUrls.add(new URL(String.format(URL_FORMATTER, TEST_HOST, TEST_PORT, TEST_IDS.get(i), "resume")));
        futures.add(client.resumeAsync(TEST_IDS.get(i)));
    }
    List<Boolean> responses = Futures.allAsList(futures).get();
    verifyAll();
    List<Request> requests = captured.getValues();
    Assert.assertEquals(numRequests, requests.size());
    Assert.assertEquals(numRequests, responses.size());
    for (int i = 0; i < numRequests; i++) {
        Assert.assertEquals(HttpMethod.POST, requests.get(i).getMethod());
        Assert.assertTrue("unexpectedURL", expectedUrls.contains(requests.get(i).getUrl()));
        Assert.assertTrue(responses.get(i));
    }
}
Also used : Request(com.metamx.http.client.Request) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Request (com.metamx.http.client.Request)47 URL (java.net.URL)38 Test (org.junit.Test)37 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)12 FullResponseHandler (com.metamx.http.client.response.FullResponseHandler)12 InputStream (java.io.InputStream)12 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Duration (org.joda.time.Duration)9 StatusResponseHolder (com.metamx.http.client.response.StatusResponseHolder)8 Map (java.util.Map)8 SequenceInputStreamResponseHandler (com.metamx.http.client.response.SequenceInputStreamResponseHandler)7 DateTime (org.joda.time.DateTime)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 HttpClient (com.metamx.http.client.HttpClient)4 HttpResponseHandler (com.metamx.http.client.response.HttpResponseHandler)4 StatusResponseHandler (com.metamx.http.client.response.StatusResponseHandler)4 List (java.util.List)4