use of com.facebook.airlift.http.client.testing.TestingResponse in project presto by prestodb.
the class TestDiscoveryNodeManager method setup.
@BeforeMethod
public void setup() {
testHttpClient = new TestingHttpClient(input -> new TestingResponse(OK, ArrayListMultimap.create(), ACTIVE.name().getBytes()));
expectedVersion = new NodeVersion("1");
coordinator = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.8"), expectedVersion, true);
resourceManager = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.9"), expectedVersion, false, true);
currentNode = new InternalNode(nodeInfo.getNodeId(), URI.create("http://192.0.1.1"), expectedVersion, false);
activeNodes = ImmutableSet.of(currentNode, new InternalNode(UUID.randomUUID().toString(), URI.create("http://192.0.2.1:8080"), expectedVersion, false), new InternalNode(UUID.randomUUID().toString(), URI.create("http://192.0.2.3"), expectedVersion, false), coordinator, resourceManager);
inactiveNodes = ImmutableSet.of(new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.3.9"), NodeVersion.UNKNOWN, false), new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.4.9"), new NodeVersion("2"), false));
selector.announceNodes(activeNodes, inactiveNodes);
}
use of com.facebook.airlift.http.client.testing.TestingResponse in project presto by prestodb.
the class TestPageBufferClient method testLifecycle.
@Test
public void testLifecycle() throws Exception {
DataSize expectedMaxSize = new DataSize(10, Unit.MEGABYTE);
CyclicBarrier beforeRequest = new CyclicBarrier(2);
CyclicBarrier afterRequest = new CyclicBarrier(2);
StaticRequestProcessor processor = new StaticRequestProcessor(beforeRequest, afterRequest);
processor.setResponse(new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(), new byte[0]));
CyclicBarrier requestComplete = new CyclicBarrier(2);
TestingClientCallback callback = new TestingClientCallback(requestComplete);
URI location = URI.create("http://localhost:8080");
PageBufferClient client = new PageBufferClient(new HttpRpcShuffleClient(new TestingHttpClient(processor, scheduler), location), new Duration(1, TimeUnit.MINUTES), true, location, Optional.empty(), callback, scheduler, pageBufferClientCallbackExecutor);
assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
client.scheduleRequest(expectedMaxSize);
beforeRequest.await(10, TimeUnit.SECONDS);
assertStatus(client, location, "running", 0, 1, 0, 0, "processing request");
assertEquals(client.isRunning(), true);
afterRequest.await(10, TimeUnit.SECONDS);
requestComplete.await(10, TimeUnit.SECONDS);
assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");
client.close();
beforeRequest.await(10, TimeUnit.SECONDS);
assertStatus(client, location, "closed", 0, 1, 1, 1, "processing request");
afterRequest.await(10, TimeUnit.SECONDS);
requestComplete.await(10, TimeUnit.SECONDS);
assertStatus(client, location, "closed", 0, 1, 2, 1, "not scheduled");
}
use of com.facebook.airlift.http.client.testing.TestingResponse in project presto by prestodb.
the class TestPageBufferClient method testCloseDuringPendingRequest.
@Test
public void testCloseDuringPendingRequest() throws Exception {
DataSize expectedMaxSize = new DataSize(10, Unit.MEGABYTE);
CyclicBarrier beforeRequest = new CyclicBarrier(2);
CyclicBarrier afterRequest = new CyclicBarrier(2);
StaticRequestProcessor processor = new StaticRequestProcessor(beforeRequest, afterRequest);
processor.setResponse(new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(), new byte[0]));
CyclicBarrier requestComplete = new CyclicBarrier(2);
TestingClientCallback callback = new TestingClientCallback(requestComplete);
URI location = URI.create("http://localhost:8080");
PageBufferClient client = new PageBufferClient(new HttpRpcShuffleClient(new TestingHttpClient(processor, scheduler), location), new Duration(1, TimeUnit.MINUTES), true, location, Optional.empty(), callback, scheduler, pageBufferClientCallbackExecutor);
assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
// send request
client.scheduleRequest(expectedMaxSize);
beforeRequest.await(10, TimeUnit.SECONDS);
assertStatus(client, location, "running", 0, 1, 0, 0, "processing request");
assertEquals(client.isRunning(), true);
// request is pending, now close it
client.close();
try {
requestComplete.await(10, TimeUnit.SECONDS);
} catch (BrokenBarrierException ignored) {
}
try {
afterRequest.await(10, TimeUnit.SECONDS);
} catch (BrokenBarrierException ignored) {
afterRequest.reset();
}
// client.close() triggers a DELETE request, so wait for it to finish
beforeRequest.await(10, TimeUnit.SECONDS);
afterRequest.await(10, TimeUnit.SECONDS);
requestComplete.await(10, TimeUnit.SECONDS);
assertStatus(client, location, "closed", 0, 1, 2, 1, "not scheduled");
}
use of com.facebook.airlift.http.client.testing.TestingResponse in project presto by prestodb.
the class TestPageBufferClient method testInvalidResponses.
@Test
public void testInvalidResponses() throws Exception {
DataSize expectedMaxSize = new DataSize(10, Unit.MEGABYTE);
CyclicBarrier beforeRequest = new CyclicBarrier(1);
CyclicBarrier afterRequest = new CyclicBarrier(1);
StaticRequestProcessor processor = new StaticRequestProcessor(beforeRequest, afterRequest);
CyclicBarrier requestComplete = new CyclicBarrier(2);
TestingClientCallback callback = new TestingClientCallback(requestComplete);
URI location = URI.create("http://localhost:8080");
PageBufferClient client = new PageBufferClient(new HttpRpcShuffleClient(new TestingHttpClient(processor, scheduler), location), new Duration(1, TimeUnit.MINUTES), true, location, Optional.empty(), callback, scheduler, pageBufferClientCallbackExecutor);
assertStatus(client, location, "queued", 0, 0, 0, 0, "not scheduled");
// send not found response and verify response was ignored
processor.setResponse(new TestingResponse(HttpStatus.NOT_FOUND, ImmutableListMultimap.of(CONTENT_TYPE, PRESTO_PAGES), new byte[0]));
client.scheduleRequest(expectedMaxSize);
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 1);
assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
assertContains(callback.getFailure().getCause().getMessage(), "Expected response code to be 200, but was 404 Not Found");
assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled");
// send invalid content type response and verify response was ignored
callback.resetStats();
processor.setResponse(new TestingResponse(HttpStatus.OK, ImmutableListMultimap.of(CONTENT_TYPE, "INVALID_TYPE"), new byte[0]));
client.scheduleRequest(expectedMaxSize);
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 1);
assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
assertContains(callback.getFailure().getCause().getMessage(), "Expected application/x-presto-pages response from server but got INVALID_TYPE");
assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled");
// send unexpected content type response and verify response was ignored
callback.resetStats();
processor.setResponse(new TestingResponse(HttpStatus.OK, ImmutableListMultimap.of(CONTENT_TYPE, "text/plain"), new byte[0]));
client.scheduleRequest(expectedMaxSize);
requestComplete.await(10, TimeUnit.SECONDS);
assertEquals(callback.getPages().size(), 0);
assertEquals(callback.getCompletedRequests(), 1);
assertEquals(callback.getFinishedBuffers(), 0);
assertEquals(callback.getFailedBuffers(), 1);
assertInstanceOf(callback.getFailure(), PageTransportErrorException.class);
assertContains(callback.getFailure().getCause().getMessage(), "Expected application/x-presto-pages response from server but got text/plain");
assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");
// close client and verify
client.close();
requestComplete.await(10, TimeUnit.SECONDS);
assertStatus(client, location, "closed", 0, 3, 4, 3, "not scheduled");
}
use of com.facebook.airlift.http.client.testing.TestingResponse in project presto by prestodb.
the class TestFullSmileResponseHandler method testMissingContentType.
@Test
public void testMissingContentType() {
SmileResponse<User> response = handler.handle(null, new TestingResponse(OK, ImmutableListMultimap.of(), "hello".getBytes(UTF_8)));
assertFalse(response.hasValue());
assertNull(response.getException());
assertNull(response.getSmileBytes());
assertEquals(response.getResponseBytes(), "hello".getBytes(UTF_8));
assertTrue(response.getHeaders().isEmpty());
}
Aggregations