Search in sources :

Example 1 with HttpClientConfig

use of io.reactivex.netty.protocol.http.client.HttpClient.HttpClientConfig in project ribbon by Netflix.

the class NettyClientTest method testObservableWithMultipleServersWithOverrideRxConfig.

@Test
public void testObservableWithMultipleServersWithOverrideRxConfig() throws Exception {
    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "1000");
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    Server badServer = new Server("localhost:12345");
    Server goodServer = new Server("localhost:" + port);
    List<Server> servers = Lists.newArrayList(badServer, badServer, badServer, goodServer);
    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder().withRule(new AvailabilityFilteringRule()).withPing(new DummyPing()).buildFixedServerListLoadBalancer(servers);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(1, 3, true));
    HttpClientConfig rxconfig = HttpClientConfig.Builder.newDefaultConfig();
    Person person = getPersonObservable(lbObservables.submit(request, rxconfig)).toBlocking().single();
    assertEquals(EmbeddedResources.defaultPerson, person);
    ServerStats stats = lbObservables.getServerStats(badServer);
    // two requests to bad server because retry same server is set to 1
    assertEquals(4, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    assertEquals(4, stats.getSuccessiveConnectionFailureCount());
    stats = lbObservables.getServerStats(goodServer);
    assertEquals(1, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    assertEquals(0, stats.getSuccessiveConnectionFailureCount());
    final HttpClientListener listener = lbObservables.getListener();
    assertEquals(1, listener.getConnectionCount());
    waitUntilTrueOrTimeout(1000, new Func0<Boolean>() {

        @Override
        public Boolean call() {
            return listener.getPoolReleases() == 1;
        }
    });
}
Also used : HttpClientConfig(io.reactivex.netty.protocol.http.client.HttpClient.HttpClientConfig) HttpServer(com.sun.net.httpserver.HttpServer) Server(com.netflix.loadbalancer.Server) MockWebServer(com.google.mockwebserver.MockWebServer) BaseLoadBalancer(com.netflix.loadbalancer.BaseLoadBalancer) ByteBuf(io.netty.buffer.ByteBuf) HttpClientListener(io.reactivex.netty.servo.http.HttpClientListener) ServerStats(com.netflix.loadbalancer.ServerStats) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) Person(com.netflix.ribbon.test.resources.EmbeddedResources.Person) Test(org.junit.Test)

Aggregations

MockWebServer (com.google.mockwebserver.MockWebServer)1 IClientConfig (com.netflix.client.config.IClientConfig)1 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)1 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)1 DummyPing (com.netflix.loadbalancer.DummyPing)1 Server (com.netflix.loadbalancer.Server)1 ServerStats (com.netflix.loadbalancer.ServerStats)1 Person (com.netflix.ribbon.test.resources.EmbeddedResources.Person)1 HttpServer (com.sun.net.httpserver.HttpServer)1 ByteBuf (io.netty.buffer.ByteBuf)1 HttpClientConfig (io.reactivex.netty.protocol.http.client.HttpClient.HttpClientConfig)1 HttpClientListener (io.reactivex.netty.servo.http.HttpClientListener)1 Test (org.junit.Test)1