use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestHttpClientBinder method testGlobalFilterBinding.
@Test
public void testGlobalFilterBinding() {
HttpRequestFilter globalFilter1 = (r) -> r;
HttpRequestFilter globalFilter2 = (r) -> r;
HttpRequestFilter filter1 = (r) -> r;
HttpRequestFilter filter2 = (r) -> r;
Injector injector = new Bootstrap(binder -> {
httpClientBinder(binder).addGlobalFilterBinding().toInstance(globalFilter1);
httpClientBinder(binder).bindGlobalFilter(globalFilter2);
httpClientBinder(binder).bindHttpClient("foo", FooClient.class).addFilterBinding().toInstance(filter1);
httpClientBinder(binder).bindHttpClient("bar", BarClient.class).addFilterBinding().toInstance(filter2);
}, new TraceTokenModule()).quiet().initialize();
JettyHttpClient fooClient = (JettyHttpClient) injector.getInstance(Key.get(HttpClient.class, FooClient.class));
assertFilterCount(fooClient, 3);
assertEquals(fooClient.getRequestFilters().get(0), globalFilter1);
assertEquals(fooClient.getRequestFilters().get(1), globalFilter2);
assertEquals(fooClient.getRequestFilters().get(2), filter1);
JettyHttpClient barClient = (JettyHttpClient) injector.getInstance(Key.get(HttpClient.class, BarClient.class));
assertFilterCount(barClient, 3);
assertEquals(barClient.getRequestFilters().get(0), globalFilter1);
assertEquals(barClient.getRequestFilters().get(1), globalFilter2);
assertEquals(barClient.getRequestFilters().get(2), filter2);
}
use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestServiceInventory method testFileServiceInventory.
@Test
public void testFileServiceInventory() throws Exception {
try (JettyHttpClient httpClient = new JettyHttpClient()) {
ServiceInventoryConfig serviceInventoryConfig = new ServiceInventoryConfig().setServiceInventoryUri(Resources.getResource("service-inventory.json").toURI());
ServiceInventory serviceInventory = new ServiceInventory(serviceInventoryConfig, new NodeInfo("test"), JsonCodec.jsonCodec(ServiceDescriptorsRepresentation.class), httpClient);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors()), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery")), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery", "general")), 2);
serviceInventory.updateServiceInventory();
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors()), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery")), 2);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors("discovery", "general")), 2);
}
}
use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestServiceInventory method testNullServiceInventory.
@Test
public void testNullServiceInventory() {
try (JettyHttpClient httpClient = new JettyHttpClient()) {
ServiceInventory serviceInventory = new ServiceInventory(new ServiceInventoryConfig(), new NodeInfo("test"), JsonCodec.jsonCodec(ServiceDescriptorsRepresentation.class), httpClient);
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors()), 0);
serviceInventory.updateServiceInventory();
assertEquals(Iterables.size(serviceInventory.getServiceDescriptors()), 0);
}
}
use of io.airlift.http.client.jetty.JettyHttpClient in project airlift by airlift.
the class TestHttpEventClient method setup.
@BeforeMethod
public void setup() throws Exception {
httpClient = new JettyHttpClient(new HttpClientConfig().setConnectTimeout(new Duration(10, SECONDS)));
servlet = new DummyServlet();
server = createServer(servlet);
server.start();
}
Aggregations