Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
André Dörnbrack authored and ryanjbaxter committed Jun 9, 2017
1 parent a59f5e1 commit 12a9a2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Expand Up @@ -18,17 +18,17 @@

package org.springframework.cloud.netflix.ribbon;

import java.util.ArrayList;
import java.util.List;
import com.netflix.client.config.CommonClientConfigKey;
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.LoadBalancedRetryPolicy;
import org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpMethod;
import org.springframework.util.StringUtils;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig;
import com.netflix.client.config.IClientConfigKey;

import java.util.ArrayList;
import java.util.List;

/**
* {@link LoadBalancedRetryPolicy} for Ribbon clients.
Expand Down Expand Up @@ -60,7 +60,7 @@ public RibbonLoadBalancedRetryPolicy(String serviceId, RibbonLoadBalancerContext
for(String code : retryableStatusCodesArray) {
if(!StringUtils.isEmpty(code)) {
try {
retryableStatusCodes.add(Integer.valueOf(code));
retryableStatusCodes.add(Integer.valueOf(code.trim()));
} catch (NumberFormatException e) {
//TODO log
}
Expand Down
Expand Up @@ -201,7 +201,7 @@ public void testGetRetryPolicyRetryCount() throws Exception {
}

@Test
public void testRetryableStatusCodest() throws Exception {
public void testRetryableStatusCodes() throws Exception {
int sameServer = 3;
int nextServer = 3;
RibbonServer server = getRibbonServer();
Expand All @@ -210,7 +210,7 @@ public void testRetryableStatusCodest() throws Exception {
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,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));
RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
RibbonLoadBalancedRetryPolicyFactory factory = new RibbonLoadBalancedRetryPolicyFactory(clientFactory);
Expand All @@ -219,6 +219,7 @@ public void testRetryableStatusCodest() throws Exception {
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));
}

Expand Down

0 comments on commit 12a9a2e

Please sign in to comment.