use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testResumeAsync.
@Test
public void testResumeAsync() 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, "resume")));
futures.add(client.resumeAsync(testId));
}
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 testGetStartTime.
@Test
public void testGetStartTime() throws Exception {
client = new TestableKinesisIndexTaskClient(httpClient, OBJECT_MAPPER, taskInfoProvider, 2);
DateTime now = DateTimes.nowUtc();
Capture<Request> captured = Capture.newInstance();
EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.NOT_FOUND).times(2);
EasyMock.expect(responseHolder.getResponse()).andReturn(response);
EasyMock.expect(response.headers()).andReturn(headers);
EasyMock.expect(headers.get("X-Druid-Task-Id")).andReturn(null);
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(errorResponseHolder()).once().andReturn(okResponseHolder());
replayAll();
DateTime results = client.getStartTime(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/time/start"), request.getUrl());
Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
Assert.assertEquals(now, results);
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testGetCurrentOffsets.
@Test
public void testGetCurrentOffsets() 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<String, String> 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", results.get("0"));
Assert.assertEquals("10", results.get("1"));
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testGetCurrentOffsetsWithRetry.
@Test
public void testGetCurrentOffsetsWithRetry() throws Exception {
client = new TestableKinesisIndexTaskClient(httpClient, OBJECT_MAPPER, taskInfoProvider, 3);
Capture<Request> captured = Capture.newInstance(CaptureType.ALL);
EasyMock.expect(responseHolder.getStatus()).andReturn(HttpResponseStatus.NOT_FOUND).times(4);
EasyMock.expect(responseHolder.getContent()).andReturn("").times(2).andReturn("{\"0\":1, \"1\":10}");
EasyMock.expect(responseHolder.getResponse()).andReturn(response).times(2);
EasyMock.expect(response.headers()).andReturn(headers).times(2);
EasyMock.expect(headers.get("X-Druid-Task-Id")).andReturn(TEST_ID).times(2);
EasyMock.expect(httpClient.go(EasyMock.capture(captured), EasyMock.anyObject(ObjectOrErrorResponseHandler.class), EasyMock.eq(TEST_HTTP_TIMEOUT))).andReturn(errorResponseHolder()).times(2).andReturn(okResponseHolder());
replayAll();
Map<String, String> results = client.getCurrentOffsets(TEST_ID, true);
verifyAll();
Assert.assertEquals(3, captured.getValues().size());
for (Request request : captured.getValues()) {
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", results.get("0"));
Assert.assertEquals("10", results.get("1"));
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class KinesisIndexTaskClientTest method testStop.
@Test
public void testStop() 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, false);
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"), request.getUrl());
Assert.assertTrue(request.getHeaders().get("X-Druid-Task-Id").contains("test-id"));
}
Aggregations