use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testSetEndOffsetsAndResume.
@Test
public void testSetEndOffsetsAndResume() throws Exception {
Map<String, String> endOffsets = ImmutableMap.of("0", "15", "1", "120");
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 KinesisIndexTaskClientTest method testStopAndPublish.
@Test
public void testStopAndPublish() throws Exception {
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.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"));
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testSetEndOffsetsAsync.
@Test
public void testSetEndOffsetsAsync() throws Exception {
Map<String, String> endOffsets = ImmutableMap.of("0", "15L", "1", "120L");
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, StringUtils.format("offsets/end?finish=%s", true))));
futures.add(client.setEndOffsetsAsync(testId, endOffsets, true));
}
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 KinesisIndexTaskClientTest method testGetStartTimeAsync.
@Test
public void testGetStartTimeAsync() throws Exception {
final DateTime now = DateTimes.nowUtc();
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(String.valueOf(now.getMillis())).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<DateTime>> futures = new ArrayList<>();
for (String testId : TEST_IDS) {
expectedUrls.add(new URL(StringUtils.format(URL_FORMATTER, TEST_HOST, TEST_PORT, testId, "time/start")));
futures.add(client.getStartTimeAsync(testId));
}
List<DateTime> 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(now, responses.get(i));
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testSetEndOffsetsAsyncWithResume.
@Test
public void testSetEndOffsetsAsyncWithResume() throws Exception {
Map<String, String> endOffsets = ImmutableMap.of("0", "15L", "1", "120L");
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, "offsets/end?finish=true")));
futures.add(client.setEndOffsetsAsync(testId, endOffsets, true));
}
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));
}
}
Aggregations