Search in sources :

Example 6 with RibbonServer

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancerClientTests method testReconstructUriWithSecureClientConfig.

@Test
public void testReconstructUriWithSecureClientConfig() throws Exception {
    RibbonServer server = getRibbonServer();
    IClientConfig config = mock(IClientConfig.class);
    when(config.get(CommonClientConfigKey.IsSecure)).thenReturn(true);
    when(clientFactory.getClientConfig(server.getServiceId())).thenReturn(config);
    RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
    ServiceInstance serviceInstance = client.choose(server.getServiceId());
    URI uri = client.reconstructURI(serviceInstance, new URL("http://" + server.getServiceId()).toURI());
    assertEquals(server.getHost(), uri.getHost());
    assertEquals(server.getPort(), uri.getPort());
    assertEquals("https", uri.getScheme());
}
Also used : RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) IClientConfig(com.netflix.client.config.IClientConfig) ServiceInstance(org.springframework.cloud.client.ServiceInstance) URI(java.net.URI) URL(java.net.URL) Test(org.junit.Test)

Example 7 with RibbonServer

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancerClientTests method testReconstructUriWithPath.

private void testReconstructUriWithPath(String scheme, String path) {
    RibbonServer server = getRibbonServer();
    IClientConfig config = mock(IClientConfig.class);
    when(config.get(CommonClientConfigKey.IsSecure)).thenReturn(true);
    when(clientFactory.getClientConfig(server.getServiceId())).thenReturn(config);
    RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
    ServiceInstance serviceInstance = client.choose(server.getServiceId());
    URI expanded = new DefaultUriBuilderFactory().expand(scheme + "://" + server.getServiceId() + path);
    URI reconstructed = client.reconstructURI(serviceInstance, expanded);
    assertThat(reconstructed).hasPath(path);
}
Also used : RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) IClientConfig(com.netflix.client.config.IClientConfig) ServiceInstance(org.springframework.cloud.client.ServiceInstance) URI(java.net.URI) DefaultUriBuilderFactory(org.springframework.web.util.DefaultUriBuilderFactory)

Example 8 with RibbonServer

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancerClientTests method testChoose.

@Test
public void testChoose() {
    RibbonServer server = getRibbonServer();
    RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
    ServiceInstance serviceInstance = client.choose(server.getServiceId());
    assertServiceInstance(server, serviceInstance);
}
Also used : RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.Test)

Example 9 with RibbonServer

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancerClientTests method testExecuteIOException.

@Test
public void testExecuteIOException() {
    final RibbonServer ribbonServer = getRibbonServer();
    RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(ribbonServer);
    try {
        client.execute(ribbonServer.getServiceId(), instance -> {
            assertServiceInstance(ribbonServer, instance);
            throw new IOException();
        });
        fail("Should have thrown exception");
    } catch (Exception ex) {
        assertThat(ex).isInstanceOf(IOException.class);
    }
    verifyServerStats();
}
Also used : RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with RibbonServer

use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.

the class RibbonLoadBalancedRetryPolicy method updateServerInstanceStats.

private void updateServerInstanceStats(LoadBalancedRetryContext context) {
    ServiceInstance serviceInstance = context.getServiceInstance();
    if (serviceInstance instanceof RibbonServer) {
        Server lbServer = ((RibbonServer) serviceInstance).getServer();
        ServerStats serverStats = lbContext.getServerStats(lbServer);
        serverStats.incrementSuccessiveConnectionFailureCount();
        serverStats.addToFailureCount();
        LOGGER.debug(lbServer.getHostPort() + " RetryCount: " + context.getRetryCount() + " Successive Failures: " + serverStats.getSuccessiveConnectionFailureCount() + " CircuitBreakerTripped:" + serverStats.isCircuitBreakerTripped());
    }
}
Also used : RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) Server(com.netflix.loadbalancer.Server) RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) ServerStats(com.netflix.loadbalancer.ServerStats) ServiceInstance(org.springframework.cloud.client.ServiceInstance)

Aggregations

RibbonServer (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer)16 Test (org.junit.Test)13 IClientConfig (com.netflix.client.config.IClientConfig)10 ServiceInstance (org.springframework.cloud.client.ServiceInstance)8 HttpRequest (org.springframework.http.HttpRequest)7 LoadBalancedRetryPolicy (org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy)6 DefaultLoadBalancerRetryHandler (com.netflix.client.DefaultLoadBalancerRetryHandler)5 IOException (java.io.IOException)5 URI (java.net.URI)5 LoadBalancedRetryContext (org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext)5 Server (com.netflix.loadbalancer.Server)4 URL (java.net.URL)4 ServerStats (com.netflix.loadbalancer.ServerStats)2 DefaultUriBuilderFactory (org.springframework.web.util.DefaultUriBuilderFactory)2 CommonClientConfigKey (com.netflix.client.config.CommonClientConfigKey)1 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)1 LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)1 SocketException (java.net.SocketException)1 Collections (java.util.Collections)1 Map (java.util.Map)1