Search in sources :

Example 16 with IClientConfig

use of com.netflix.client.config.IClientConfig in project ribbon by Netflix.

the class NettyClientTest method testObservableWithMultipleServersFailed.

@Test
public void testObservableWithMultipleServersFailed() throws Exception {
    IClientConfig config = IClientConfig.Builder.newBuilder().withDefaultValues().withRetryOnAllOperations(true).withMaxAutoRetries(1).withMaxAutoRetriesNextServer(3).withConnectTimeout(100).build();
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    BaseLoadBalancer lb = new BaseLoadBalancer(new DummyPing(), new AvailabilityFilteringRule());
    LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config);
    Server badServer = new Server("localhost:12345");
    Server badServer1 = new Server("localhost:12346");
    Server badServer2 = new Server("localhost:12347");
    List<Server> servers = Lists.newArrayList(badServer, badServer1, badServer2);
    lb.setServersList(servers);
    Observable<Person> observableWithRetries = getPersonObservable(lbObservables.submit(request));
    ObserverWithLatch<Person> observer = new ObserverWithLatch<Person>();
    observableWithRetries.subscribe(observer);
    observer.await();
    assertNull(observer.obj);
    observer.error.printStackTrace();
    assertTrue(observer.error instanceof ClientException);
    ServerStats stats = lbObservables.getServerStats(badServer);
    // two requests to bad server because retry same server is set to 1
    assertEquals(2, stats.getTotalRequestsCount());
    assertEquals(0, stats.getActiveRequestsCount());
    assertEquals(2, stats.getSuccessiveConnectionFailureCount());
}
Also used : 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) ServerStats(com.netflix.loadbalancer.ServerStats) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) ClientException(com.netflix.client.ClientException) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) Person(com.netflix.ribbon.test.resources.EmbeddedResources.Person) Test(org.junit.Test)

Example 17 with IClientConfig

use of com.netflix.client.config.IClientConfig in project ribbon by Netflix.

the class RibbonTransportFactory method newTcpClient.

public final RxClient<ByteBuf, ByteBuf> newTcpClient(String name) {
    IClientConfig config = clientConfigFactory.newConfig();
    config.loadProperties(name);
    return newTcpClient(config);
}
Also used : IClientConfig(com.netflix.client.config.IClientConfig)

Example 18 with IClientConfig

use of com.netflix.client.config.IClientConfig in project ribbon by Netflix.

the class ShutDownTest method testLifeCycleShutdown.

@Test
public void testLifeCycleShutdown() throws Exception {
    final AtomicBoolean shutDownCalled = new AtomicBoolean(false);
    final HttpClient<ByteBuf, ByteBuf> client = new HttpClient<ByteBuf, ByteBuf>() {

        @Override
        public Observable<HttpClientResponse<ByteBuf>> submit(HttpClientRequest<ByteBuf> request) {
            return null;
        }

        @Override
        public Observable<HttpClientResponse<ByteBuf>> submit(HttpClientRequest<ByteBuf> request, ClientConfig config) {
            return null;
        }

        @Override
        public Observable<ObservableConnection<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>>> connect() {
            return null;
        }

        @Override
        public void shutdown() {
            shutDownCalled.set(true);
        }

        @Override
        public String name() {
            return "SampleMovieService";
        }

        @Override
        public Subscription subscribe(MetricEventsListener<? extends ClientMetricsEvent<?>> listener) {
            return null;
        }
    };
    RibbonTransportFactory transportFactory = new RibbonTransportFactory(ClientConfigFactory.DEFAULT) {

        @Override
        public HttpClient<ByteBuf, ByteBuf> newHttpClient(IClientConfig config) {
            return client;
        }
    };
    HttpResourceGroup.Builder groupBuilder = HttpResourceGroup.Builder.newBuilder("SampleMovieService", ClientConfigFactory.DEFAULT, transportFactory);
    HttpResourceGroup group = groupBuilder.build();
    SampleMovieService service = RibbonDynamicProxy.newInstance(SampleMovieService.class, group);
    ProxyLifeCycle proxyLifeCycle = (ProxyLifeCycle) service;
    proxyLifeCycle.shutdown();
    assertTrue(proxyLifeCycle.isShutDown());
    assertTrue(shutDownCalled.get());
}
Also used : ObservableConnection(io.reactivex.netty.channel.ObservableConnection) RibbonTransportFactory(com.netflix.ribbon.RibbonTransportFactory) MetricEventsListener(io.reactivex.netty.metrics.MetricEventsListener) HttpResourceGroup(com.netflix.ribbon.http.HttpResourceGroup) ByteBuf(io.netty.buffer.ByteBuf) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpClientRequest(io.reactivex.netty.protocol.http.client.HttpClientRequest) SampleMovieService(com.netflix.ribbon.proxy.sample.MovieServiceInterfaces.SampleMovieService) ClientMetricsEvent(io.reactivex.netty.client.ClientMetricsEvent) HttpClient(io.reactivex.netty.protocol.http.client.HttpClient) HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) IClientConfig(com.netflix.client.config.IClientConfig) IClientConfig(com.netflix.client.config.IClientConfig) Test(org.junit.Test)

Example 19 with IClientConfig

use of com.netflix.client.config.IClientConfig in project camel by apache.

the class RibbonLoadBalancer method createLoadBalancer.

// ************************
// Helpers
// ************************
private ZoneAwareLoadBalancer<RibbonServiceDefinition> createLoadBalancer(String serviceName, ServiceDiscovery serviceDiscovery) {
    // setup client config
    IClientConfig config = configuration.getClientName() != null ? IClientConfig.Builder.newBuilder(configuration.getClientName()).build() : IClientConfig.Builder.newBuilder().build();
    if (configuration.getClientConfig() != null) {
        for (Map.Entry<String, String> entry : configuration.getClientConfig().entrySet()) {
            IClientConfigKey key = IClientConfigKey.Keys.valueOf(entry.getKey());
            String value = entry.getValue();
            LOGGER.debug("RibbonClientConfig: {}={}", key.key(), value);
            config.set(key, value);
        }
    }
    return new ZoneAwareLoadBalancer<>(config, configuration.getRuleOrDefault(RoundRobinRule::new), configuration.getPingOrDefault(DummyPing::new), new RibbonServerList(serviceName, serviceDiscovery, serviceFilter), null, new PollingServerListUpdater(config));
}
Also used : PollingServerListUpdater(com.netflix.loadbalancer.PollingServerListUpdater) IClientConfig(com.netflix.client.config.IClientConfig) ZoneAwareLoadBalancer(com.netflix.loadbalancer.ZoneAwareLoadBalancer) IClientConfigKey(com.netflix.client.config.IClientConfigKey) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 20 with IClientConfig

use of com.netflix.client.config.IClientConfig in project ribbon by Netflix.

the class RxMovieProxyExampleTest method testTransportFactoryWithInjection.

@Test
public void testTransportFactoryWithInjection() {
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON);
            bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
        }
    });
    RibbonTransportFactory transportFactory = injector.getInstance(RibbonTransportFactory.class);
    HttpClient<ByteBuf, ByteBuf> client = transportFactory.newHttpClient("myClient");
    IClientConfig config = ((LoadBalancingHttpClient) client).getClientConfig();
    assertEquals("MyConfig", config.getNameSpace());
}
Also used : Injector(com.google.inject.Injector) DefaultClientConfigFactory(com.netflix.client.config.ClientConfigFactory.DefaultClientConfigFactory) ClientConfigFactory(com.netflix.client.config.ClientConfigFactory) RibbonTransportFactory(com.netflix.ribbon.RibbonTransportFactory) DefaultRibbonTransportFactory(com.netflix.ribbon.RibbonTransportFactory.DefaultRibbonTransportFactory) IClientConfig(com.netflix.client.config.IClientConfig) LoadBalancingHttpClient(com.netflix.ribbon.transport.netty.http.LoadBalancingHttpClient) ByteBuf(io.netty.buffer.ByteBuf) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

IClientConfig (com.netflix.client.config.IClientConfig)36 Test (org.junit.Test)27 Server (com.netflix.loadbalancer.Server)20 ByteBuf (io.netty.buffer.ByteBuf)20 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)18 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)18 DummyPing (com.netflix.loadbalancer.DummyPing)18 MockWebServer (com.google.mockwebserver.MockWebServer)17 HttpServer (com.sun.net.httpserver.HttpServer)10 Person (com.netflix.ribbon.test.resources.EmbeddedResources.Person)9 ServerStats (com.netflix.loadbalancer.ServerStats)8 ExecutionListener (com.netflix.loadbalancer.reactive.ExecutionListener)7 MockResponse (com.google.mockwebserver.MockResponse)6 ClientException (com.netflix.client.ClientException)6 AbortExecutionException (com.netflix.loadbalancer.reactive.ExecutionListener.AbortExecutionException)5 HttpClientResponse (io.reactivex.netty.protocol.http.client.HttpClientResponse)5 RequestSpecificRetryHandler (com.netflix.client.RequestSpecificRetryHandler)4 RetryHandler (com.netflix.client.RetryHandler)4 HttpClientListener (io.reactivex.netty.servo.http.HttpClientListener)4 ExecutionContext (com.netflix.loadbalancer.reactive.ExecutionContext)3