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