use of com.facebook.airlift.http.client.Response in project presto by prestodb.
the class SqlCancelTests method cancelQuery.
private void cancelQuery(String sql) throws InterruptedException {
Stopwatch stopwatch = Stopwatch.createStarted();
while (stopwatch.elapsed(SECONDS) < 30) {
String findQuerySql = "SELECT query_id from system.runtime.queries WHERE query = '%s' and state = 'RUNNING' LIMIT 2";
QueryResult queryResult = query(format(findQuerySql, sql));
checkState(queryResult.getRowsCount() < 2, "Query is executed multiple times");
if (queryResult.getRowsCount() == 1) {
String queryId = (String) queryResult.row(0).get(0);
Response response = queryCanceller.cancel(queryId);
Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT.code());
return;
}
MILLISECONDS.sleep(100L);
}
throw new IllegalStateException("Query did not reach running state or maybe it was too quick.");
}
use of com.facebook.airlift.http.client.Response in project presto by prestodb.
the class TestExchangeClient method testInitialRequestLimit.
@Test
public void testInitialRequestLimit() {
DataSize bufferCapacity = new DataSize(16, MEGABYTE);
DataSize maxResponseSize = new DataSize(DEFAULT_MAX_PAGE_SIZE_IN_BYTES, BYTE);
CountDownLatch countDownLatch = new CountDownLatch(1);
MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize) {
@Override
public Response handle(Request request) {
if (!awaitUninterruptibly(countDownLatch, 10, SECONDS)) {
throw new UncheckedTimeoutException();
}
return super.handle(request);
}
};
List<URI> locations = new ArrayList<>();
int numLocations = 16;
List<DataSize> expectedMaxSizes = new ArrayList<>();
// add pages
for (int i = 0; i < numLocations; i++) {
URI location = URI.create("http://localhost:" + (8080 + i));
locations.add(location);
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
processor.setComplete(location);
expectedMaxSizes.add(maxResponseSize);
}
try (ExchangeClient exchangeClient = createExchangeClient(processor, bufferCapacity, maxResponseSize)) {
for (int i = 0; i < numLocations; i++) {
exchangeClient.addLocation(locations.get(i), TaskId.valueOf("taskid.0.0." + i));
}
exchangeClient.noMoreLocations();
assertFalse(exchangeClient.isClosed());
long start = System.nanoTime();
countDownLatch.countDown();
// wait for a page to be fetched
do {
// there is no thread coordination here, so sleep is the best we can do
assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
sleepUninterruptibly(100, MILLISECONDS);
} while (exchangeClient.getStatus().getBufferedPages() < 16);
// Client should have sent 16 requests for a single page (0) and gotten them back
// The memory limit should be hit immediately and then it doesn't fetch the third page from each
assertEquals(exchangeClient.getStatus().getBufferedPages(), 16);
assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
List<PageBufferClientStatus> pageBufferClientStatuses = exchangeClient.getStatus().getPageBufferClientStatuses();
assertEquals(16, pageBufferClientStatuses.stream().filter(status -> status.getPagesReceived() == 1).mapToInt(PageBufferClientStatus::getPagesReceived).sum());
assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
for (int i = 0; i < numLocations * 3; i++) {
assertNotNull(getNextPage(exchangeClient));
}
do {
// there is no thread coordination here, so sleep is the best we can do
assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
sleepUninterruptibly(100, MILLISECONDS);
} while (processor.getRequestMaxSizes().size() < 64);
for (int i = 0; i < 48; i++) {
expectedMaxSizes.add(maxResponseSize);
}
assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
}
}
use of com.facebook.airlift.http.client.Response in project presto by prestodb.
the class TaskInfoFetcher method sendMetadataUpdates.
private synchronized void sendMetadataUpdates(MetadataUpdates results) {
TaskStatus taskStatus = getTaskInfo().getTaskStatus();
// we already have the final task info
if (isDone(getTaskInfo())) {
stop();
return;
}
// outstanding request?
if (metadataUpdateFuture != null && !metadataUpdateFuture.isDone()) {
// this should never happen
return;
}
byte[] metadataUpdatesJson = metadataUpdatesCodec.toBytes(results);
Request request = setContentTypeHeaders(isBinaryTransportEnabled, preparePost()).setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("metadataresults").build()).setBodyGenerator(createStaticBodyGenerator(metadataUpdatesJson)).build();
errorTracker.startRequest();
metadataUpdateFuture = httpClient.executeAsync(request, new ResponseHandler<Response, RuntimeException>() {
@Override
public Response handleException(Request request, Exception exception) {
throw propagate(request, exception);
}
@Override
public Response handle(Request request, Response response) {
return response;
}
});
currentRequestStartNanos.set(System.nanoTime());
}
use of com.facebook.airlift.http.client.Response in project presto by prestodb.
the class HttpRpcShuffleClient method acknowledgeResultsAsync.
@Override
public void acknowledgeResultsAsync(long nextToken) {
URI uri = uriBuilderFrom(location).appendPath(String.valueOf(nextToken)).appendPath("acknowledge").build();
httpClient.executeAsync(prepareGet().setUri(uri).build(), new ResponseHandler<Void, RuntimeException>() {
@Override
public Void handleException(Request request, Exception exception) {
log.debug(exception, "Acknowledge request failed: %s", uri);
return null;
}
@Override
public Void handle(Request request, Response response) {
if (familyForStatusCode(response.getStatusCode()) != HttpStatus.Family.SUCCESSFUL) {
log.debug("Unexpected acknowledge response code: %s", response.getStatusCode());
}
return null;
}
});
}
Aggregations