Search in sources :

Example 1 with IClientConfig

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

the class LBBuilderTest method testBuildWithArchaiusProperties.

@Test
public void testBuildWithArchaiusProperties() {
    Configuration config = ConfigurationManager.getConfigInstance();
    config.setProperty("client1.niws.client." + Keys.DeploymentContextBasedVipAddresses, "dummy:7001");
    config.setProperty("client1.niws.client." + Keys.InitializeNFLoadBalancer, "true");
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerClassName, DynamicServerListLoadBalancer.class.getName());
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerRuleClassName, RoundRobinRule.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListFilterClassName, ZoneAffinityServerListFilter.class.getName());
    IClientConfig clientConfig = IClientConfig.Builder.newBuilder(NiwsClientConfig.class, "client1").build();
    ILoadBalancer lb = LoadBalancerBuilder.newBuilder().withClientConfig(clientConfig).buildLoadBalancerFromConfigWithReflection();
    assertNotNull(lb);
    assertEquals(DynamicServerListLoadBalancer.class.getName(), lb.getClass().getName());
    DynamicServerListLoadBalancer<Server> dynamicLB = (DynamicServerListLoadBalancer<Server>) lb;
    assertTrue(dynamicLB.getFilter() instanceof ZoneAffinityServerListFilter);
    assertTrue(dynamicLB.getRule() instanceof RoundRobinRule);
    assertTrue(dynamicLB.getPing() instanceof DummyPing);
    assertEquals(Lists.newArrayList(expected), lb.getAllServers());
}
Also used : Configuration(org.apache.commons.configuration.Configuration) Server(com.netflix.loadbalancer.Server) DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) RoundRobinRule(com.netflix.loadbalancer.RoundRobinRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with IClientConfig

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

the class LBBuilderTest method testBuildStaticServerListLoadBalancer.

@Test
public void testBuildStaticServerListLoadBalancer() {
    List<Server> list = Lists.newArrayList(expected, expected);
    IRule rule = new AvailabilityFilteringRule();
    IClientConfig clientConfig = IClientConfig.Builder.newBuilder().withDefaultValues().withMaxAutoRetriesNextServer(3).build();
    assertEquals(3, clientConfig.get(Keys.MaxAutoRetriesNextServer).intValue());
    BaseLoadBalancer lb = LoadBalancerBuilder.newBuilder().withRule(rule).buildFixedServerListLoadBalancer(list);
    assertEquals(list, lb.getAllServers());
    assertSame(rule, lb.getRule());
}
Also used : Server(com.netflix.loadbalancer.Server) IClientConfig(com.netflix.client.config.IClientConfig) BaseLoadBalancer(com.netflix.loadbalancer.BaseLoadBalancer) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) IRule(com.netflix.loadbalancer.IRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with IClientConfig

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

the class DiscoveryEnabledNIWSServerList method createClientConfig.

private static IClientConfig createClientConfig(String vipAddresses) {
    IClientConfig clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues();
    clientConfig.set(Keys.DeploymentContextBasedVipAddresses, vipAddresses);
    return clientConfig;
}
Also used : IClientConfig(com.netflix.client.config.IClientConfig)

Example 4 with IClientConfig

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

the class FollowRedirectTest method testRedirectFollowed.

@Test
public void testRedirectFollowed() throws Exception {
    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues("myclient2").set(IClientConfigKey.Keys.FollowRedirects, Boolean.TRUE);
    ClientFactory.registerClientFromProperties("myclient2", config);
    com.netflix.niws.client.http.RestClient client = (com.netflix.niws.client.http.RestClient) ClientFactory.getNamedClient("myclient2");
    HttpRequest request = HttpRequest.newBuilder().uri(new URI("http://localhost:" + redirectingServer.getPort())).build();
    HttpResponse response = client.execute(request);
    assertEquals(200, response.getStatus());
}
Also used : HttpRequest(com.netflix.client.http.HttpRequest) IClientConfig(com.netflix.client.config.IClientConfig) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 5 with IClientConfig

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

the class LoadBalancingHttpClient method submit.

/**
     * Subject an operation to run in the load balancer
     * 
     * @param request
     * @param errorHandler
     * @param requestConfig
     * @param rxClientConfig
     * @return
     */
private Observable<HttpClientResponse<O>> submit(final Server server, final HttpClientRequest<I> request, final RetryHandler errorHandler, final IClientConfig requestConfig, final ClientConfig rxClientConfig) {
    RetryHandler retryHandler = errorHandler;
    if (retryHandler == null) {
        retryHandler = getRequestRetryHandler(request, requestConfig);
    }
    final IClientConfig config = requestConfig == null ? DefaultClientConfigImpl.getEmptyConfig() : requestConfig;
    final ExecutionContext<HttpClientRequest<I>> context = new ExecutionContext<HttpClientRequest<I>>(request, config, this.getClientConfig(), retryHandler);
    Observable<HttpClientResponse<O>> result = submitToServerInURI(request, config, rxClientConfig, retryHandler, context);
    if (result == null) {
        LoadBalancerCommand<HttpClientResponse<O>> command;
        if (retryHandler != defaultRetryHandler) {
            // need to create new builder instead of the default one
            command = LoadBalancerCommand.<HttpClientResponse<O>>builder().withExecutionContext(context).withLoadBalancerContext(lbContext).withListeners(listeners).withClientConfig(this.getClientConfig()).withRetryHandler(retryHandler).withServer(server).build();
        } else {
            command = defaultCommandBuilder;
        }
        result = command.submit(requestToOperation(request, getRxClientConfig(config, rxClientConfig)));
    }
    return result;
}
Also used : HttpClientRequest(io.reactivex.netty.protocol.http.client.HttpClientRequest) ExecutionContext(com.netflix.loadbalancer.reactive.ExecutionContext) RequestSpecificRetryHandler(com.netflix.client.RequestSpecificRetryHandler) RetryHandler(com.netflix.client.RetryHandler) HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) IClientConfig(com.netflix.client.config.IClientConfig) URI(java.net.URI)

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