Search in sources :

Example 1 with HttpStatus

use of com.facebook.airlift.http.client.HttpStatus in project presto by prestodb.

the class MockExchangeRequestProcessor method handle.

@Override
public Response handle(Request request) {
    if (request.getMethod().equalsIgnoreCase("DELETE")) {
        return new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(), new byte[0]);
    }
    // verify we got a data size and it parses correctly
    assertTrue(!request.getHeaders().get(PrestoHeaders.PRESTO_MAX_SIZE).isEmpty());
    DataSize maxSize = DataSize.valueOf(request.getHeader(PrestoHeaders.PRESTO_MAX_SIZE));
    assertTrue(maxSize.compareTo(expectedMaxSize) <= 0);
    requestMaxSizes.add(maxSize);
    RequestLocation requestLocation = new RequestLocation(request.getUri());
    URI location = requestLocation.getLocation();
    BufferResult result = buffers.getUnchecked(location).getPages(requestLocation.getSequenceId(), maxSize);
    byte[] bytes = new byte[0];
    HttpStatus status;
    if (!result.getSerializedPages().isEmpty()) {
        DynamicSliceOutput sliceOutput = new DynamicSliceOutput(64);
        PagesSerdeUtil.writeSerializedPages(sliceOutput, result.getSerializedPages());
        bytes = dataChanger.apply(sliceOutput.slice().getBytes());
        status = HttpStatus.OK;
    } else {
        status = HttpStatus.NO_CONTENT;
    }
    return new TestingResponse(status, ImmutableListMultimap.of(CONTENT_TYPE, PRESTO_PAGES, PRESTO_TASK_INSTANCE_ID, String.valueOf(result.getTaskInstanceId()), PRESTO_PAGE_TOKEN, String.valueOf(result.getToken()), PRESTO_PAGE_NEXT_TOKEN, String.valueOf(result.getNextToken()), PRESTO_BUFFER_COMPLETE, String.valueOf(result.isBufferComplete())), bytes);
}
Also used : TestingResponse(com.facebook.airlift.http.client.testing.TestingResponse) BufferResult(com.facebook.presto.execution.buffer.BufferResult) HttpStatus(com.facebook.airlift.http.client.HttpStatus) DataSize(io.airlift.units.DataSize) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) URI(java.net.URI)

Aggregations

HttpStatus (com.facebook.airlift.http.client.HttpStatus)1 TestingResponse (com.facebook.airlift.http.client.testing.TestingResponse)1 BufferResult (com.facebook.presto.execution.buffer.BufferResult)1 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)1 DataSize (io.airlift.units.DataSize)1 URI (java.net.URI)1