Search in sources :

Example 26 with JettyHttpClient

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);
}
Also used : Assert.assertSame(org.testng.Assert.assertSame) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Assertions.assertInstanceOf(io.airlift.testing.Assertions.assertInstanceOf) Key(com.google.inject.Key) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Target(java.lang.annotation.Target) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Assert.assertNotNull(org.testng.Assert.assertNotNull) ElementType(java.lang.annotation.ElementType) RUNTIME(java.lang.annotation.RetentionPolicy.RUNTIME) Duration(io.airlift.units.Duration) Retention(java.lang.annotation.Retention) Injector(com.google.inject.Injector) TraceTokenModule(io.airlift.tracetoken.TraceTokenModule) HttpClientBinder.httpClientBinder(io.airlift.http.client.HttpClientBinder.httpClientBinder) ImmutableList(com.google.common.collect.ImmutableList) Assert.assertNotSame(org.testng.Assert.assertNotSame) Bootstrap(io.airlift.bootstrap.Bootstrap) Qualifier(javax.inject.Qualifier) Assert.assertTrue(org.testng.Assert.assertTrue) Assert.assertFalse(org.testng.Assert.assertFalse) Injector(com.google.inject.Injector) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Bootstrap(io.airlift.bootstrap.Bootstrap) TraceTokenModule(io.airlift.tracetoken.TraceTokenModule) Test(org.testng.annotations.Test)

Example 27 with JettyHttpClient

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);
    }
}
Also used : JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) NodeInfo(io.airlift.node.NodeInfo) Test(org.testng.annotations.Test)

Example 28 with JettyHttpClient

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);
    }
}
Also used : JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) NodeInfo(io.airlift.node.NodeInfo) Test(org.testng.annotations.Test)

Example 29 with JettyHttpClient

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();
}
Also used : HttpClientConfig(io.airlift.http.client.HttpClientConfig) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Duration(io.airlift.units.Duration) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)29 Test (org.testng.annotations.Test)21 HttpClient (io.airlift.http.client.HttpClient)11 HttpClientConfig (io.airlift.http.client.HttpClientConfig)11 Injector (com.google.inject.Injector)10 Bootstrap (io.airlift.bootstrap.Bootstrap)10 Duration (io.airlift.units.Duration)9 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)8 TestingNodeModule (io.airlift.node.testing.TestingNodeModule)8 StatusResponse (io.airlift.http.client.StatusResponseHandler.StatusResponse)7 StringResponse (io.airlift.http.client.StringResponseHandler.StringResponse)7 URI (java.net.URI)7 ImmutableMap (com.google.common.collect.ImmutableMap)5 NodeInfo (io.airlift.node.NodeInfo)4 InMemoryEventModule (io.airlift.event.client.InMemoryEventModule)3 TheServlet (io.airlift.http.server.TheServlet)3 TraceTokenModule (io.airlift.tracetoken.TraceTokenModule)3 File (java.io.File)3 Map (java.util.Map)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3