Commit 4f148de7 by André Dörnbrack

code cleanup

parent 484bde10
...@@ -18,17 +18,17 @@ ...@@ -18,17 +18,17 @@
package org.springframework.cloud.netflix.ribbon; package org.springframework.cloud.netflix.ribbon;
import java.util.ArrayList; import com.netflix.client.config.CommonClientConfigKey;
import java.util.List; import com.netflix.client.config.IClientConfig;
import com.netflix.client.config.IClientConfigKey;
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext; import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext;
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy; import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy;
import org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser; import org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig; import java.util.ArrayList;
import com.netflix.client.config.IClientConfigKey; import java.util.List;
/** /**
* {@link LoadBalancedRetryPolicy} for Ribbon clients. * {@link LoadBalancedRetryPolicy} for Ribbon clients.
...@@ -60,7 +60,7 @@ public class RibbonLoadBalancedRetryPolicy implements LoadBalancedRetryPolicy { ...@@ -60,7 +60,7 @@ public class RibbonLoadBalancedRetryPolicy implements LoadBalancedRetryPolicy {
for(String code : retryableStatusCodesArray) { for(String code : retryableStatusCodesArray) {
if(!StringUtils.isEmpty(code)) { if(!StringUtils.isEmpty(code)) {
try { try {
retryableStatusCodes.add(Integer.valueOf(code)); retryableStatusCodes.add(Integer.valueOf(code.trim()));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
//TODO log //TODO log
} }
......
...@@ -201,7 +201,7 @@ public class RibbonLoadBalancedRetryPolicyFactoryTest { ...@@ -201,7 +201,7 @@ public class RibbonLoadBalancedRetryPolicyFactoryTest {
} }
@Test @Test
public void testRetryableStatusCodest() throws Exception { public void testRetryableStatusCodes() throws Exception {
int sameServer = 3; int sameServer = 3;
int nextServer = 3; int nextServer = 3;
RibbonServer server = getRibbonServer(); RibbonServer server = getRibbonServer();
...@@ -210,7 +210,7 @@ public class RibbonLoadBalancedRetryPolicyFactoryTest { ...@@ -210,7 +210,7 @@ public class RibbonLoadBalancedRetryPolicyFactoryTest {
doReturn(nextServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt()); doReturn(nextServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt());
doReturn(false).when(config).get(eq(CommonClientConfigKey.OkToRetryOnAllOperations), eq(false)); doReturn(false).when(config).get(eq(CommonClientConfigKey.OkToRetryOnAllOperations), eq(false));
doReturn(config).when(clientFactory).getClientConfig(eq(server.getServiceId())); doReturn(config).when(clientFactory).getClientConfig(eq(server.getServiceId()));
doReturn("404,502,foo, ,").when(config).getPropertyAsString(eq(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES),eq("")); doReturn("404, 418,502,foo, ,").when(config).getPropertyAsString(eq(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES),eq(""));
clientFactory.getLoadBalancerContext(server.getServiceId()).setRetryHandler(new DefaultLoadBalancerRetryHandler(config)); clientFactory.getLoadBalancerContext(server.getServiceId()).setRetryHandler(new DefaultLoadBalancerRetryHandler(config));
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server); RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
RibbonLoadBalancedRetryPolicyFactory factory = new RibbonLoadBalancedRetryPolicyFactory(clientFactory); RibbonLoadBalancedRetryPolicyFactory factory = new RibbonLoadBalancedRetryPolicyFactory(clientFactory);
...@@ -219,6 +219,7 @@ public class RibbonLoadBalancedRetryPolicyFactoryTest { ...@@ -219,6 +219,7 @@ public class RibbonLoadBalancedRetryPolicyFactoryTest {
doReturn(HttpMethod.GET).when(request).getMethod(); doReturn(HttpMethod.GET).when(request).getMethod();
assertThat(policy.retryableStatusCode(400), is(false)); assertThat(policy.retryableStatusCode(400), is(false));
assertThat(policy.retryableStatusCode(404), is(true)); assertThat(policy.retryableStatusCode(404), is(true));
assertThat(policy.retryableStatusCode(418), is(true));
assertThat(policy.retryableStatusCode(502), is(true)); assertThat(policy.retryableStatusCode(502), is(true));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment