use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KafkaIndexTaskClientTest method testStopAsync.
@Test
public void testStopAsync() throws Exception {
final int numRequests = TEST_IDS.size();
Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder()).times(numRequests);
replayAll();
List<URL> expectedUrls = new ArrayList<>();
List<ListenableFuture<Boolean>> futures = new ArrayList<>();
for (String testId : TEST_IDS) {
expectedUrls.add(new URL(StringUtils.format(URL_FORMATTER, TEST_HOST, TEST_PORT, testId, "stop")));
futures.add(client.stopAsync(testId, false));
}
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));
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KafkaIndexTaskClientTest method testSetEndOffsets.
@Test
public void testSetEndOffsets() throws Exception {
Map<Integer, Long> endOffsets = ImmutableMap.of(0, 15L, 1, 120L);
Capture<Request> captured = Capture.newInstance();
EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder());
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?finish=true"), request.getUrl());
Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
Assert.assertEquals("{\"0\":15,\"1\":120}", StringUtils.fromUtf8(request.getContent().array()));
}
use of org.apache.druid.java.util.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();
EasyMock.expect(responseHolder.getContent()).andReturn("{\"0\":1, \"1\":10}");
EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder());
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));
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testPauseAsync.
@Test
public void testPauseAsync() throws Exception {
final int numRequests = TEST_IDS.size();
Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
EasyMock.expect(responseHolder.getContent()).andReturn("{\"0\":\"1\"}").anyTimes();
EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder()).times(numRequests);
replayAll();
List<URL> expectedUrls = new ArrayList<>();
List<ListenableFuture<Map<String, String>>> futures = new ArrayList<>();
for (String testId : TEST_IDS) {
expectedUrls.add(new URL(StringUtils.format(URL_FORMATTER, TEST_HOST, TEST_PORT, testId, "pause")));
futures.add(client.pauseAsync(testId));
}
List<Map<String, String>> 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", "1")), responses.get(i));
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testGetStatusAsync.
@Test
public void testGetStatusAsync() throws Exception {
final int numRequests = TEST_IDS.size();
Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.OK).anyTimes();
EasyMock.expect(responseHolder.getContent()).andReturn("\"READING\"").anyTimes();
EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(okResponseHolder()).times(numRequests);
replayAll();
List<URL> expectedUrls = new ArrayList<>();
List<ListenableFuture<Status>> futures = new ArrayList<>();
for (String testId : TEST_IDS) {
expectedUrls.add(new URL(StringUtils.format(URL_FORMATTER, TEST_HOST, TEST_PORT, testId, "status")));
futures.add(client.getStatusAsync(testId));
}
List<Status> 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.GET, requests.get(i).getMethod());
Assert.assertTrue("unexpectedURL", expectedUrls.contains(requests.get(i).getUrl()));
Assert.assertEquals(Status.READING, responses.get(i));
}
}
Aggregations