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());
}
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());
}
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;
}
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());
}
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;
}
Aggregations