use of com.facebook.airlift.http.client.testing.TestingHttpClient in project presto by prestodb.
the class TestPinotClusterInfoFetcher method testBrokersParsed.
private void testBrokersParsed(boolean useHttps) {
HttpClient httpClient = new TestingHttpClient(request -> {
Assert.assertEquals(request.getUri().getScheme(), useHttps ? "https" : "http");
return TestingResponse.mockResponse(HttpStatus.OK, MediaType.JSON_UTF_8, "{\n" + " \"tableName\": \"dummy\",\n" + " \"brokers\": [\n" + " {\n" + " \"tableType\": \"offline\",\n" + " \"instances\": [\n" + " \"Broker_dummy-broker-host1-datacenter1_6513\",\n" + " \"Broker_dummy-broker-host2-datacenter1_6513\",\n" + " \"Broker_dummy-broker-host4-datacenter1_6513\"\n" + " ]\n" + " },\n" + " {\n" + " \"tableType\": \"realtime\",\n" + " \"instances\": [\n" + " \"Broker_dummy-broker-host1-datacenter1_6513\",\n" + " \"Broker_dummy-broker-host2-datacenter1_6513\",\n" + " \"Broker_dummy-broker-host3-datacenter1_6513\"\n" + " ]\n" + " }\n" + " ],\n" + " \"server\": [\n" + " {\n" + " \"tableType\": \"offline\",\n" + " \"instances\": [\n" + " \"Server_dummy-server-host8-datacenter1_7090\",\n" + " \"Server_dummy-server-host9-datacenter1_7090\"\n" + " ]\n" + " },\n" + " {\n" + " \"tableType\": \"realtime\",\n" + " \"instances\": [\n" + " \"Server_dummy-server-host7-datacenter1_7090\",\n" + " \"Server_dummy-server-host4-datacenter1_7090\",\n" + " \"Server_dummy-server-host5-datacenter1_7090\",\n" + " \"Server_dummy-server-host6-datacenter1_7090\"\n" + " ]\n" + " }\n" + " ]\n" + "}");
});
PinotConfig pinotConfig = new PinotConfig().setMetadataCacheExpiry(new Duration(0, TimeUnit.MILLISECONDS)).setControllerUrls("localhost:7900").setUseHttpsForController(useHttps);
PinotClusterInfoFetcher pinotClusterInfoFetcher = new PinotClusterInfoFetcher(pinotConfig, new PinotMetrics(), httpClient, MetadataUtil.TABLES_JSON_CODEC, MetadataUtil.BROKERS_FOR_TABLE_JSON_CODEC, MetadataUtil.ROUTING_TABLES_JSON_CODEC, MetadataUtil.ROUTING_TABLES_V2_JSON_CODEC, MetadataUtil.TIME_BOUNDARY_JSON_CODEC, MetadataUtil.INSTANCE_JSON_CODEC);
ImmutableSet<String> brokers = ImmutableSet.copyOf(pinotClusterInfoFetcher.getAllBrokersForTable("dummy"));
Assert.assertEquals(ImmutableSet.of("dummy-broker-host1-datacenter1:6513", "dummy-broker-host2-datacenter1:6513", "dummy-broker-host3-datacenter1:6513", "dummy-broker-host4-datacenter1:6513"), brokers);
}
use of com.facebook.airlift.http.client.testing.TestingHttpClient in project presto by prestodb.
the class TestPinotClusterInfoFetcher method testInstanceParsed.
private void testInstanceParsed(boolean useHttps) {
HttpClient httpClient = new TestingHttpClient((request) -> {
Assert.assertEquals(request.getUri().getScheme(), useHttps ? "https" : "http");
return TestingResponse.mockResponse(HttpStatus.OK, MediaType.JSON_UTF_8, "{\n" + " \"instanceName\": \"Server_192.168.1.19_8098\",\n" + " \"hostName\": \"192.168.1.19\",\n" + " \"enabled\": true,\n" + " \"port\": \"8098\",\n" + " \"tags\": [\n" + " \"DefaultTenant_OFFLINE\",\n" + " \"DefaultTenant_REALTIME\"\n" + " ],\n" + " \"pools\": null,\n" + " \"grpcPort\": 8090\n" + "}");
});
PinotConfig pinotConfig = new PinotConfig().setMetadataCacheExpiry(new Duration(0, TimeUnit.MILLISECONDS)).setControllerUrls("localhost:7900").setUseHttpsForController(useHttps);
PinotClusterInfoFetcher pinotClusterInfoFetcher = new PinotClusterInfoFetcher(pinotConfig, new PinotMetrics(), httpClient, MetadataUtil.TABLES_JSON_CODEC, MetadataUtil.BROKERS_FOR_TABLE_JSON_CODEC, MetadataUtil.ROUTING_TABLES_JSON_CODEC, MetadataUtil.ROUTING_TABLES_V2_JSON_CODEC, MetadataUtil.TIME_BOUNDARY_JSON_CODEC, MetadataUtil.INSTANCE_JSON_CODEC);
final PinotClusterInfoFetcher.Instance instance = pinotClusterInfoFetcher.getInstance("Server_192.168.1.19_8098");
Assert.assertEquals(instance.getInstanceName(), "Server_192.168.1.19_8098");
Assert.assertEquals(instance.getHostName(), "192.168.1.19");
Assert.assertEquals(instance.isEnabled(), true);
Assert.assertEquals(instance.getPort(), 8098);
Assert.assertEquals(instance.getGrpcPort(), 8090);
Assert.assertEquals(instance.getPools(), null);
Assert.assertEquals(instance.getTags().size(), 2);
Assert.assertEquals(instance.getTags().get(0), "DefaultTenant_OFFLINE");
Assert.assertEquals(instance.getTags().get(1), "DefaultTenant_REALTIME");
}
use of com.facebook.airlift.http.client.testing.TestingHttpClient 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.TestingHttpClient 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.TestingHttpClient 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");
}
Aggregations