use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancedRetryFactoryTests method testGetRetryPolicyRetryOnNonGet.
@Test
public void testGetRetryPolicyRetryOnNonGet() throws Exception {
int sameServer = 3;
int nextServer = 3;
boolean retryOnAllOps = true;
RibbonServer server = getRibbonServer();
IClientConfig config = mock(IClientConfig.class);
doReturn(sameServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetries), anyInt());
doReturn(sameServer).when(config).getPropertyAsInteger(eq(CommonClientConfigKey.MaxAutoRetries), anyInt());
doReturn(nextServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt());
doReturn(nextServer).when(config).getPropertyAsInteger(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt());
doReturn(retryOnAllOps).when(config).get(eq(CommonClientConfigKey.OkToRetryOnAllOperations), anyBoolean());
doReturn(retryOnAllOps).when(config).getPropertyAsBoolean(eq(CommonClientConfigKey.OkToRetryOnAllOperations), anyBoolean());
doReturn("").when(config).getPropertyAsString(eq(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES), eq(""));
doReturn(server.getServiceId()).when(config).getClientName();
doReturn(config).when(clientFactory).getClientConfig(eq(server.getServiceId()));
clientFactory.getLoadBalancerContext(server.getServiceId()).initWithNiwsConfig(config);
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
RibbonLoadBalancedRetryFactory factory = new RibbonLoadBalancedRetryFactory(clientFactory);
LoadBalancedRetryPolicy policy = factory.createRetryPolicy(server.getServiceId(), client);
HttpRequest request = mock(HttpRequest.class);
doReturn(HttpMethod.POST).when(request).getMethod();
LoadBalancedRetryContext context = new LoadBalancedRetryContext(null, request);
assertThat(policy.canRetryNextServer(context), is(true));
assertThat(policy.canRetrySameServer(context), is(true));
assertThat(policy.retryableStatusCode(400), is(false));
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancedRetryFactoryTests method testGetRetryPolicyNotGet.
@Test
public void testGetRetryPolicyNotGet() throws Exception {
int sameServer = 3;
int nextServer = 3;
boolean retryOnAllOps = false;
RibbonServer server = getRibbonServer();
IClientConfig config = mock(IClientConfig.class);
doReturn(sameServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetries), anyInt());
doReturn(sameServer).when(config).getPropertyAsInteger(eq(CommonClientConfigKey.MaxAutoRetries), anyInt());
doReturn(nextServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt());
doReturn(nextServer).when(config).getPropertyAsInteger(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt());
doReturn(retryOnAllOps).when(config).get(eq(CommonClientConfigKey.OkToRetryOnAllOperations), anyBoolean());
doReturn(retryOnAllOps).when(config).getPropertyAsBoolean(eq(CommonClientConfigKey.OkToRetryOnAllOperations), anyBoolean());
doReturn("").when(config).getPropertyAsString(eq(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES), eq(""));
doReturn(server.getServiceId()).when(config).getClientName();
doReturn(config).when(clientFactory).getClientConfig(eq(server.getServiceId()));
clientFactory.getLoadBalancerContext(server.getServiceId()).setRetryHandler(new DefaultLoadBalancerRetryHandler(config));
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
RibbonLoadBalancedRetryFactory factory = new RibbonLoadBalancedRetryFactory(clientFactory);
LoadBalancedRetryPolicy policy = factory.createRetryPolicy(server.getServiceId(), client);
HttpRequest request = mock(HttpRequest.class);
doReturn(HttpMethod.POST).when(request).getMethod();
LoadBalancedRetryContext context = new LoadBalancedRetryContext(null, request);
assertThat(policy.canRetryNextServer(context), is(false));
assertThat(policy.canRetrySameServer(context), is(false));
assertThat(policy.retryableStatusCode(400), is(false));
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancedRetryFactoryTests method testRetryableStatusCodes.
@Test
public void testRetryableStatusCodes() throws Exception {
int sameServer = 3;
int nextServer = 3;
RibbonServer server = getRibbonServer();
IClientConfig config = mock(IClientConfig.class);
doReturn(sameServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetries), anyInt());
doReturn(nextServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt());
doReturn(false).when(config).get(eq(CommonClientConfigKey.OkToRetryOnAllOperations), eq(false));
doReturn(config).when(clientFactory).getClientConfig(eq(server.getServiceId()));
doReturn("404, 418,502,foo, ,").when(config).getPropertyAsString(eq(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES), eq(""));
clientFactory.getLoadBalancerContext(server.getServiceId()).setRetryHandler(new DefaultLoadBalancerRetryHandler(config));
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
RibbonLoadBalancedRetryFactory factory = new RibbonLoadBalancedRetryFactory(clientFactory);
LoadBalancedRetryPolicy policy = factory.createRetryPolicy(server.getServiceId(), client);
HttpRequest request = mock(HttpRequest.class);
doReturn(HttpMethod.GET).when(request).getMethod();
assertThat(policy.retryableStatusCode(400), is(false));
assertThat(policy.retryableStatusCode(404), is(true));
assertThat(policy.retryableStatusCode(418), is(true));
assertThat(policy.retryableStatusCode(502), is(true));
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancerClientTests method testReconstructURI.
private void testReconstructURI(String scheme) throws Exception {
RibbonServer server = getRibbonServer();
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
ServiceInstance serviceInstance = client.choose(server.getServiceId());
URI uri = client.reconstructURI(serviceInstance, new URL(scheme + "://" + server.getServiceId()).toURI());
assertThat(uri).hasScheme(scheme).hasHost(serviceInstance.getHost()).hasPort(serviceInstance.getPort());
}
use of org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancerClientTests method testReconstructHonorsRibbonServerScheme.
@Test
public void testReconstructHonorsRibbonServerScheme() {
RibbonServer server = new RibbonServer("testService", new Server("ws", "myhost", 9080), false, Collections.singletonMap("mykey", "myvalue"));
IClientConfig config = mock(IClientConfig.class);
when(config.get(CommonClientConfigKey.IsSecure)).thenReturn(false);
when(clientFactory.getClientConfig(server.getServiceId())).thenReturn(config);
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
ServiceInstance serviceInstance = client.choose(server.getServiceId());
URI uri = client.reconstructURI(serviceInstance, URI.create("http://testService"));
assertThat(uri).hasScheme("ws").hasHost("myhost").hasPort(9080);
}
Aggregations