Search in sources :

Example 1 with Request

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

the class KafkaIndexTaskClientTest method testResume.

@Test
public void testResume() 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.resume(TEST_ID);
    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/resume"), 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 2 with Request

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

the class KafkaIndexTaskClientTest method testGetEndOffsets.

@Test
public void testGetEndOffsets() 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.getEndOffsets(TEST_ID);
    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/end"), 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 3 with Request

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

the class KafkaIndexTaskClientTest method testPause.

@Test
public void testPause() throws Exception {
    Capture<Request> captured = Capture.newInstance();
    expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).times(2);
    expect(responseHolder.getContent()).andReturn("{\"0\":1, \"1\":10}").anyTimes();
    expect(httpClient.go(capture(captured), anyObject(FullResponseHandler.class), eq(TEST_HTTP_TIMEOUT))).andReturn(Futures.immediateFuture(responseHolder));
    replayAll();
    Map<Integer, Long> results = client.pause(TEST_ID);
    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/pause"), 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 4 with Request

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

the class KafkaIndexTaskClientTest method testPauseWithTimeout.

@Test
public void testPauseWithTimeout() throws Exception {
    Capture<Request> captured = Capture.newInstance();
    expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).times(2);
    expect(responseHolder.getContent()).andReturn("{\"0\":1, \"1\":10}").anyTimes();
    expect(httpClient.go(capture(captured), anyObject(FullResponseHandler.class), eq(TEST_HTTP_TIMEOUT))).andReturn(Futures.immediateFuture(responseHolder));
    replayAll();
    Map<Integer, Long> results = client.pause(TEST_ID, 101);
    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/pause?timeout=101"), 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 5 with Request

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

the class KafkaIndexTaskClientTest method testSetEndOffsetsAndResume.

@Test
public void testSetEndOffsetsAndResume() throws Exception {
    Map<Integer, Long> endOffsets = ImmutableMap.of(0, 15L, 1, 120L);
    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.setEndOffsets(TEST_ID, endOffsets, 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/offsets/end?resume=true"), request.getUrl());
    Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
    Assert.assertEquals("{\"0\":15,\"1\":120}", new String(request.getContent().array()));
}
Also used : Request(com.metamx.http.client.Request) FullResponseHandler(com.metamx.http.client.response.FullResponseHandler) 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