Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
a533bc06
Commit
a533bc06
authored
Mar 13, 2018
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:spring-cloud/spring-cloud-netflix
parents
eeb89e6e
6dec4afe
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
99 additions
and
196 deletions
+99
-196
RibbonAutoConfiguration.java
...amework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
+3
-26
RibbonLoadBalancedRetryFactory.java
.../cloud/netflix/ribbon/RibbonLoadBalancedRetryFactory.java
+18
-6
HttpClientRibbonConfiguration.java
.../netflix/ribbon/apache/HttpClientRibbonConfiguration.java
+5
-10
RetryableRibbonLoadBalancingHttpClient.java
...ribbon/apache/RetryableRibbonLoadBalancingHttpClient.java
+11
-53
OkHttpRibbonConfiguration.java
...loud/netflix/ribbon/okhttp/OkHttpRibbonConfiguration.java
+4
-8
RetryableOkHttpLoadBalancingClient.java
...lix/ribbon/okhttp/RetryableOkHttpLoadBalancingClient.java
+9
-37
RibbonLoadBalancedRetryFactoryTests.java
...d/netflix/ribbon/RibbonLoadBalancedRetryFactoryTests.java
+13
-13
SpringRetryDisabledTests.java
...mework/cloud/netflix/ribbon/SpringRetryDisabledTests.java
+3
-4
SpringRetryEnabledTests.java
...amework/cloud/netflix/ribbon/SpringRetryEnabledTests.java
+4
-3
RibbonLoadBalancingHttpClientTests.java
...lix/ribbon/apache/RibbonLoadBalancingHttpClientTests.java
+0
-0
SpringRetryDisableOkHttpClientTests.java
...ix/ribbon/okhttp/SpringRetryDisableOkHttpClientTests.java
+3
-4
SpringRetryEnabledOkHttpClientTests.java
...ix/ribbon/okhttp/SpringRetryEnabledOkHttpClientTests.java
+18
-24
RibbonRetryIntegrationTestBase.java
...filters/route/support/RibbonRetryIntegrationTestBase.java
+8
-8
No files found.
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
View file @
a533bc06
...
...
@@ -34,9 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.client.loadbalancer.AsyncLoadBalancerAutoConfiguration
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedBackOffPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryListenerFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer
;
...
...
@@ -91,29 +89,8 @@ public class RibbonAutoConfiguration {
@Bean
@ConditionalOnClass
(
name
=
"org.springframework.retry.support.RetryTemplate"
)
@ConditionalOnMissingBean
public
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
(
SpringClientFactory
clientFactory
)
{
return
new
RibbonLoadBalancedRetryPolicyFactory
(
clientFactory
);
}
@Bean
@ConditionalOnMissingClass
(
value
=
"org.springframework.retry.support.RetryTemplate"
)
@ConditionalOnMissingBean
public
LoadBalancedRetryPolicyFactory
neverRetryPolicyFactory
()
{
return
new
LoadBalancedRetryPolicyFactory
.
NeverRetryFactory
();
}
@Bean
@ConditionalOnClass
(
name
=
"org.springframework.retry.support.RetryTemplate"
)
@ConditionalOnMissingBean
public
LoadBalancedBackOffPolicyFactory
loadBalancedBackoffPolicyFactory
()
{
return
new
LoadBalancedBackOffPolicyFactory
.
NoBackOffPolicyFactory
();
}
@Bean
@ConditionalOnClass
(
name
=
"org.springframework.retry.support.RetryTemplate"
)
@ConditionalOnMissingBean
public
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
()
{
return
new
LoadBalancedRetryListenerFactory
.
DefaultRetryListenerFactory
();
public
LoadBalancedRetryFactory
loadBalancedRetryPolicyFactory
(
final
SpringClientFactory
clientFactory
)
{
return
new
RibbonLoadBalancedRetryFactory
(
clientFactory
);
}
@Bean
...
...
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetry
Policy
Factory.java
→
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryFactory.java
View file @
a533bc06
...
...
@@ -15,26 +15,38 @@
*/
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser
;
import
org.springframework.retry.RetryListener
;
import
org.springframework.retry.backoff.BackOffPolicy
;
/**
* @author Ryan Baxter
*/
public
class
RibbonLoadBalancedRetry
PolicyFactory
implements
LoadBalancedRetryPolic
yFactory
{
public
class
RibbonLoadBalancedRetry
Factory
implements
LoadBalancedRetr
yFactory
{
private
SpringClientFactory
clientFactory
;
public
RibbonLoadBalancedRetry
Policy
Factory
(
SpringClientFactory
clientFactory
)
{
public
RibbonLoadBalancedRetryFactory
(
SpringClientFactory
clientFactory
)
{
this
.
clientFactory
=
clientFactory
;
}
@Override
public
LoadBalancedRetryPolicy
create
(
String
serviceId
,
ServiceInstanceChooser
loadBal
anceChooser
)
{
public
LoadBalancedRetryPolicy
create
RetryPolicy
(
String
service
,
ServiceInstanceChooser
serviceInst
anceChooser
)
{
RibbonLoadBalancerContext
lbContext
=
this
.
clientFactory
.
getLoadBalancerContext
(
serviceId
);
return
new
RibbonLoadBalancedRetryPolicy
(
serviceId
,
lbContext
,
loadBalanceChooser
,
clientFactory
.
getClientConfig
(
serviceId
));
.
getLoadBalancerContext
(
service
);
return
new
RibbonLoadBalancedRetryPolicy
(
service
,
lbContext
,
serviceInstanceChooser
,
clientFactory
.
getClientConfig
(
service
));
}
@Override
public
RetryListener
[]
createRetryListeners
(
String
service
)
{
return
new
RetryListener
[
0
];
}
@Override
public
BackOffPolicy
createBackOffPolicy
(
String
service
)
{
return
null
;
}
}
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientRibbonConfiguration.java
View file @
a533bc06
...
...
@@ -32,9 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedBackOffPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryListenerFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory
;
import
org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientName
;
...
...
@@ -133,14 +131,11 @@ public class HttpClientRibbonConfiguration {
@ConditionalOnMissingBean
(
AbstractLoadBalancerAwareClient
.
class
)
@ConditionalOnClass
(
name
=
"org.springframework.retry.support.RetryTemplate"
)
public
RetryableRibbonLoadBalancingHttpClient
retryableRibbonLoadBalancingHttpClient
(
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
ILoadBalancer
loadBalancer
,
RetryHandler
retryHandler
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
,
CloseableHttpClient
httpClient
,
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
,
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
)
{
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
ILoadBalancer
loadBalancer
,
RetryHandler
retryHandler
,
LoadBalancedRetryFactory
loadBalancedRetryFactory
,
CloseableHttpClient
httpClient
)
{
RetryableRibbonLoadBalancingHttpClient
client
=
new
RetryableRibbonLoadBalancingHttpClient
(
httpClient
,
config
,
serverIntrospector
,
loadBalancedRetryPolicyFactory
,
loadBalancedBackOffPolicyFactory
,
loadBalancedRetryListenerFactory
);
httpClient
,
config
,
serverIntrospector
,
loadBalancedRetryFactory
);
client
.
setLoadBalancer
(
loadBalancer
);
client
.
setRetryHandler
(
retryHandler
);
Monitors
.
registerObject
(
"Client_"
+
this
.
name
,
client
);
...
...
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RetryableRibbonLoadBalancingHttpClient.java
View file @
a533bc06
...
...
@@ -15,7 +15,6 @@
*/
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
apache
;
import
java.io.IOException
;
import
java.net.URI
;
import
org.apache.commons.lang.BooleanUtils
;
import
org.apache.http.HttpResponse
;
...
...
@@ -23,15 +22,12 @@ import org.apache.http.client.config.RequestConfig;
import
org.apache.http.client.methods.HttpUriRequest
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
BackOffPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
RecoveryCallback
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetry
Listener
Factory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.RibbonRecoveryCallback
;
import
org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser
;
import
org.springframework.cloud.client.loadbalancer.InterceptorRetryPolicy
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonProperties
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.support.ContextAwareRequest
;
...
...
@@ -45,11 +41,9 @@ import org.springframework.retry.policy.NeverRetryPolicy;
import
org.springframework.retry.support.RetryTemplate
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
com.netflix.client.ClientException
;
import
com.netflix.client.RequestSpecificRetryHandler
;
import
com.netflix.client.RetryHandler
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.loadbalancer.Server
;
/**
* An Apache HTTP client which leverages Spring Retry to retry failed requests.
...
...
@@ -57,50 +51,13 @@ import com.netflix.loadbalancer.Server;
* @author Gang Li
*/
public
class
RetryableRibbonLoadBalancingHttpClient
extends
RibbonLoadBalancingHttpClient
{
private
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
=
new
LoadBalancedRetryPolicyFactory
.
NeverRetryFactory
();
private
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
=
new
LoadBalancedBackOffPolicyFactory
.
NoBackOffPolicyFactory
();
private
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
=
new
LoadBalancedRetryListenerFactory
.
DefaultRetryListenerFactory
();
@Deprecated
//TODO remove in 2.0.x
public
RetryableRibbonLoadBalancingHttpClient
(
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
)
{
super
(
config
,
serverIntrospector
);
this
.
loadBalancedRetryPolicyFactory
=
loadBalancedRetryPolicyFactory
;
}
@Deprecated
//TODO remove in 2.0.x
public
RetryableRibbonLoadBalancingHttpClient
(
CloseableHttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
)
{
super
(
delegate
,
config
,
serverIntrospector
);
this
.
loadBalancedRetryPolicyFactory
=
loadBalancedRetryPolicyFactory
;
}
@Deprecated
//TODO remove in 2.0.x
public
RetryableRibbonLoadBalancingHttpClient
(
CloseableHttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
,
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
)
{
super
(
delegate
,
config
,
serverIntrospector
);
this
.
loadBalancedRetryPolicyFactory
=
loadBalancedRetryPolicyFactory
;
this
.
loadBalancedBackOffPolicyFactory
=
loadBalancedBackOffPolicyFactory
;
}
private
LoadBalancedRetryFactory
loadBalancedRetryFactory
;
public
RetryableRibbonLoadBalancingHttpClient
(
CloseableHttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
,
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
,
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
)
{
LoadBalancedRetryFactory
loadBalancedRetryFactory
)
{
super
(
delegate
,
config
,
serverIntrospector
);
this
.
loadBalancedRetryPolicyFactory
=
loadBalancedRetryPolicyFactory
;
this
.
loadBalancedBackOffPolicyFactory
=
loadBalancedBackOffPolicyFactory
;
this
.
loadBalancedRetryListenerFactory
=
loadBalancedRetryListenerFactory
;
this
.
loadBalancedRetryFactory
=
loadBalancedRetryFactory
;
}
@Override
...
...
@@ -113,14 +70,15 @@ public class RetryableRibbonLoadBalancingHttpClient extends RibbonLoadBalancingH
builder
.
setRedirectsEnabled
(
ribbon
.
isFollowRedirects
(
this
.
followRedirects
));
final
RequestConfig
requestConfig
=
builder
.
build
();
final
LoadBalancedRetryPolicy
retryPolicy
=
loadBalancedRetry
PolicyFactory
.
create
(
this
.
getClientName
(),
this
);
final
LoadBalancedRetryPolicy
retryPolicy
=
loadBalancedRetry
Factory
.
createRetryPolicy
(
this
.
getClientName
(),
this
);
RetryCallback
<
RibbonApacheHttpResponse
,
IO
Exception
>
retryCallback
=
context
->
{
RetryCallback
<
RibbonApacheHttpResponse
,
Exception
>
retryCallback
=
context
->
{
//on retries the policy will choose the server and set it in the context
//extract the server and update the request being made
RibbonApacheHttpRequest
newRequest
=
request
;
if
(
context
instanceof
LoadBalancedRetryContext
)
{
ServiceInstance
service
=
((
LoadBalancedRetryContext
)
context
).
getServiceInstance
();
validateServiceInstance
(
service
);
if
(
service
!=
null
)
{
//Reconstruct the request URI using the host and port set in the retry context
newRequest
=
newRequest
.
withNewUri
(
UriComponentsBuilder
.
newInstance
().
host
(
service
.
getHost
())
...
...
@@ -139,7 +97,7 @@ public class RetryableRibbonLoadBalancingHttpClient extends RibbonLoadBalancingH
}
return
new
RibbonApacheHttpResponse
(
httpResponse
,
httpUriRequest
.
getURI
());
};
RibbonRecoveryCallback
<
RibbonApacheHttpResponse
,
HttpResponse
>
recoveryCallback
=
new
Ribbon
RecoveryCallback
<
RibbonApacheHttpResponse
,
HttpResponse
>()
{
LoadBalancedRecoveryCallback
<
RibbonApacheHttpResponse
,
HttpResponse
>
recoveryCallback
=
new
LoadBalanced
RecoveryCallback
<
RibbonApacheHttpResponse
,
HttpResponse
>()
{
@Override
protected
RibbonApacheHttpResponse
createResponse
(
HttpResponse
response
,
URI
uri
)
{
return
new
RibbonApacheHttpResponse
(
response
,
uri
);
...
...
@@ -165,9 +123,9 @@ public class RetryableRibbonLoadBalancingHttpClient extends RibbonLoadBalancingH
boolean
retryable
=
isRequestRetryable
(
request
);
retryTemplate
.
setRetryPolicy
(
retryPolicy
==
null
||
!
retryable
?
new
NeverRetryPolicy
()
:
new
RetryPolicy
(
request
,
retryPolicy
,
this
,
this
.
getClientName
()));
BackOffPolicy
backOffPolicy
=
loadBalanced
BackOffPolic
yFactory
.
createBackOffPolicy
(
this
.
getClientName
());
BackOffPolicy
backOffPolicy
=
loadBalanced
Retr
yFactory
.
createBackOffPolicy
(
this
.
getClientName
());
retryTemplate
.
setBackOffPolicy
(
backOffPolicy
==
null
?
new
NoBackOffPolicy
()
:
backOffPolicy
);
RetryListener
[]
retryListeners
=
this
.
loadBalancedRetry
Listener
Factory
.
createRetryListeners
(
this
.
getClientName
());
RetryListener
[]
retryListeners
=
this
.
loadBalancedRetryFactory
.
createRetryListeners
(
this
.
getClientName
());
if
(
retryListeners
!=
null
&&
retryListeners
.
length
!=
0
)
{
retryTemplate
.
setListeners
(
retryListeners
);
}
...
...
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonConfiguration.java
View file @
a533bc06
...
...
@@ -25,9 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedBackOffPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryListenerFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory
;
import
org.springframework.cloud.commons.httpclient.OkHttpClientFactory
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientName
;
...
...
@@ -101,12 +99,10 @@ public class OkHttpRibbonConfiguration {
ServerIntrospector
serverIntrospector
,
ILoadBalancer
loadBalancer
,
RetryHandler
retryHandler
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
,
OkHttpClient
delegate
,
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
,
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
)
{
LoadBalancedRetryFactory
loadBalancedRetryFactory
,
OkHttpClient
delegate
)
{
RetryableOkHttpLoadBalancingClient
client
=
new
RetryableOkHttpLoadBalancingClient
(
delegate
,
config
,
serverIntrospector
,
loadBalancedRetry
PolicyFactory
,
loadBalancedBackOffPolicyFactory
,
loadBalancedRetryListener
Factory
);
serverIntrospector
,
loadBalancedRetryFactory
);
client
.
setLoadBalancer
(
loadBalancer
);
client
.
setRetryHandler
(
retryHandler
);
Monitors
.
registerObject
(
"Client_"
+
this
.
name
,
client
);
...
...
spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/RetryableOkHttpLoadBalancingClient.java
View file @
a533bc06
...
...
@@ -24,12 +24,10 @@ import java.net.URI;
import
org.apache.commons.lang.BooleanUtils
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.InterceptorRetryPolicy
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
BackOffPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
RecoveryCallback
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetry
Listener
Factory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.RibbonRecoveryCallback
;
import
org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser
;
import
org.springframework.cloud.netflix.ribbon.support.ContextAwareRequest
;
import
org.springframework.http.HttpRequest
;
...
...
@@ -55,38 +53,12 @@ import com.netflix.client.config.IClientConfig;
*/
public
class
RetryableOkHttpLoadBalancingClient
extends
OkHttpLoadBalancingClient
{
private
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
;
private
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
=
new
LoadBalancedBackOffPolicyFactory
.
NoBackOffPolicyFactory
();
private
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
=
new
LoadBalancedRetryListenerFactory
.
DefaultRetryListenerFactory
();
private
LoadBalancedRetryFactory
loadBalancedRetryFactory
;
@Deprecated
//TODO remove in 2.0.x
public
RetryableOkHttpLoadBalancingClient
(
OkHttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
LoadBalancedRetryPolic
yFactory
loadBalancedRetryPolicyFactory
)
{
LoadBalancedRetr
yFactory
loadBalancedRetryPolicyFactory
)
{
super
(
delegate
,
config
,
serverIntrospector
);
this
.
loadBalancedRetryPolicyFactory
=
loadBalancedRetryPolicyFactory
;
}
@Deprecated
//TODO remove in 2.0.x
public
RetryableOkHttpLoadBalancingClient
(
OkHttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
,
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
)
{
super
(
delegate
,
config
,
serverIntrospector
);
this
.
loadBalancedRetryPolicyFactory
=
loadBalancedRetryPolicyFactory
;
this
.
loadBalancedBackOffPolicyFactory
=
loadBalancedBackOffPolicyFactory
;
}
public
RetryableOkHttpLoadBalancingClient
(
OkHttpClient
delegate
,
IClientConfig
config
,
ServerIntrospector
serverIntrospector
,
LoadBalancedRetryPolicyFactory
loadBalancedRetryPolicyFactory
,
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
,
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
)
{
super
(
delegate
,
config
,
serverIntrospector
);
this
.
loadBalancedRetryPolicyFactory
=
loadBalancedRetryPolicyFactory
;
this
.
loadBalancedBackOffPolicyFactory
=
loadBalancedBackOffPolicyFactory
;
this
.
loadBalancedRetryListenerFactory
=
loadBalancedRetryListenerFactory
;
this
.
loadBalancedRetryFactory
=
loadBalancedRetryPolicyFactory
;
}
@Override
...
...
@@ -103,9 +75,9 @@ public class RetryableOkHttpLoadBalancingClient extends OkHttpLoadBalancingClien
RetryCallback
<
OkHttpRibbonResponse
,
Exception
>
callback
,
RecoveryCallback
<
OkHttpRibbonResponse
>
recoveryCallback
)
throws
Exception
{
RetryTemplate
retryTemplate
=
new
RetryTemplate
();
BackOffPolicy
backOffPolicy
=
loadBalanced
BackOffPolic
yFactory
.
createBackOffPolicy
(
this
.
getClientName
());
BackOffPolicy
backOffPolicy
=
loadBalanced
Retr
yFactory
.
createBackOffPolicy
(
this
.
getClientName
());
retryTemplate
.
setBackOffPolicy
(
backOffPolicy
==
null
?
new
NoBackOffPolicy
()
:
backOffPolicy
);
RetryListener
[]
retryListeners
=
this
.
loadBalancedRetry
Listener
Factory
.
createRetryListeners
(
this
.
getClientName
());
RetryListener
[]
retryListeners
=
this
.
loadBalancedRetryFactory
.
createRetryListeners
(
this
.
getClientName
());
if
(
retryListeners
!=
null
&&
retryListeners
.
length
!=
0
)
{
retryTemplate
.
setListeners
(
retryListeners
);
}
...
...
@@ -118,7 +90,7 @@ public class RetryableOkHttpLoadBalancingClient extends OkHttpLoadBalancingClien
@Override
public
OkHttpRibbonResponse
execute
(
final
OkHttpRibbonRequest
ribbonRequest
,
final
IClientConfig
configOverride
)
throws
Exception
{
final
LoadBalancedRetryPolicy
retryPolicy
=
loadBalancedRetry
PolicyFactory
.
create
(
this
.
getClientName
(),
this
);
final
LoadBalancedRetryPolicy
retryPolicy
=
loadBalancedRetry
Factory
.
createRetryPolicy
(
this
.
getClientName
(),
this
);
RetryCallback
<
OkHttpRibbonResponse
,
Exception
>
retryCallback
=
new
RetryCallback
<
OkHttpRibbonResponse
,
Exception
>()
{
@Override
public
OkHttpRibbonResponse
doWithRetry
(
RetryContext
context
)
throws
Exception
{
...
...
@@ -152,7 +124,7 @@ public class RetryableOkHttpLoadBalancingClient extends OkHttpLoadBalancingClien
return
new
OkHttpRibbonResponse
(
response
,
newRequest
.
getUri
());
}
};
return
this
.
executeWithRetry
(
ribbonRequest
,
retryPolicy
,
retryCallback
,
new
Ribbon
RecoveryCallback
<
OkHttpRibbonResponse
,
Response
>(){
return
this
.
executeWithRetry
(
ribbonRequest
,
retryPolicy
,
retryCallback
,
new
LoadBalanced
RecoveryCallback
<
OkHttpRibbonResponse
,
Response
>(){
@Override
protected
OkHttpRibbonResponse
createResponse
(
Response
response
,
URI
uri
)
{
...
...
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetry
Policy
FactoryTests.java
→
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryFactoryTests.java
View file @
a533bc06
...
...
@@ -57,7 +57,7 @@ import static org.mockito.Mockito.verify;
/**
* @author Ryan Baxter
*/
public
class
RibbonLoadBalancedRetry
Policy
FactoryTests
{
public
class
RibbonLoadBalancedRetryFactoryTests
{
@Mock
private
SpringClientFactory
clientFactory
;
...
...
@@ -107,8 +107,8 @@ public class RibbonLoadBalancedRetryPolicyFactoryTests {
doReturn
(
config
).
when
(
clientFactory
).
getClientConfig
(
eq
(
server
.
getServiceId
()));
clientFactory
.
getLoadBalancerContext
(
server
.
getServiceId
()).
setRetryHandler
(
new
DefaultLoadBalancerRetryHandler
(
config
));
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
server
);
RibbonLoadBalancedRetry
PolicyFactory
factory
=
new
RibbonLoadBalancedRetryPolic
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
(
server
.
getServiceId
(),
client
);
RibbonLoadBalancedRetry
Factory
factory
=
new
RibbonLoadBalancedRetr
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
RetryPolicy
(
server
.
getServiceId
(),
client
);
HttpRequest
request
=
mock
(
HttpRequest
.
class
);
doReturn
(
HttpMethod
.
GET
).
when
(
request
).
getMethod
();
LoadBalancedRetryContext
context
=
new
LoadBalancedRetryContext
(
null
,
request
);
...
...
@@ -135,8 +135,8 @@ public class RibbonLoadBalancedRetryPolicyFactoryTests {
doReturn
(
config
).
when
(
clientFactory
).
getClientConfig
(
eq
(
server
.
getServiceId
()));
clientFactory
.
getLoadBalancerContext
(
server
.
getServiceId
()).
setRetryHandler
(
new
DefaultLoadBalancerRetryHandler
(
config
));
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
server
);
RibbonLoadBalancedRetry
PolicyFactory
factory
=
new
RibbonLoadBalancedRetryPolic
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
(
server
.
getServiceId
(),
client
);
RibbonLoadBalancedRetry
Factory
factory
=
new
RibbonLoadBalancedRetr
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
RetryPolicy
(
server
.
getServiceId
(),
client
);
HttpRequest
request
=
mock
(
HttpRequest
.
class
);
doReturn
(
HttpMethod
.
POST
).
when
(
request
).
getMethod
();
LoadBalancedRetryContext
context
=
new
LoadBalancedRetryContext
(
null
,
request
);
...
...
@@ -163,8 +163,8 @@ public class RibbonLoadBalancedRetryPolicyFactoryTests {
doReturn
(
config
).
when
(
clientFactory
).
getClientConfig
(
eq
(
server
.
getServiceId
()));
clientFactory
.
getLoadBalancerContext
(
server
.
getServiceId
()).
initWithNiwsConfig
(
config
);
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
server
);
RibbonLoadBalancedRetry
PolicyFactory
factory
=
new
RibbonLoadBalancedRetryPolic
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
(
server
.
getServiceId
(),
client
);
RibbonLoadBalancedRetry
Factory
factory
=
new
RibbonLoadBalancedRetr
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
RetryPolicy
(
server
.
getServiceId
(),
client
);
HttpRequest
request
=
mock
(
HttpRequest
.
class
);
doReturn
(
HttpMethod
.
POST
).
when
(
request
).
getMethod
();
LoadBalancedRetryContext
context
=
new
LoadBalancedRetryContext
(
null
,
request
);
...
...
@@ -186,8 +186,8 @@ public class RibbonLoadBalancedRetryPolicyFactoryTests {
doReturn
(
""
).
when
(
config
).
getPropertyAsString
(
eq
(
RibbonLoadBalancedRetryPolicy
.
RETRYABLE_STATUS_CODES
),
eq
(
""
));
clientFactory
.
getLoadBalancerContext
(
server
.
getServiceId
()).
setRetryHandler
(
new
DefaultLoadBalancerRetryHandler
(
config
));
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
server
);
RibbonLoadBalancedRetry
PolicyFactory
factory
=
new
RibbonLoadBalancedRetryPolic
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
(
server
.
getServiceId
(),
client
);
RibbonLoadBalancedRetry
Factory
factory
=
new
RibbonLoadBalancedRetr
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
RetryPolicy
(
server
.
getServiceId
(),
client
);
HttpRequest
request
=
mock
(
HttpRequest
.
class
);
doReturn
(
HttpMethod
.
GET
).
when
(
request
).
getMethod
();
LoadBalancedRetryContext
context
=
spy
(
new
LoadBalancedRetryContext
(
null
,
request
));
...
...
@@ -232,8 +232,8 @@ public class RibbonLoadBalancedRetryPolicyFactoryTests {
clientFactory
.
getLoadBalancerContext
(
server
.
getServiceId
()).
setRetryHandler
(
new
DefaultLoadBalancerRetryHandler
(
config
));
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
server
);
RibbonLoadBalancedRetry
PolicyFactory
factory
=
new
RibbonLoadBalancedRetryPolic
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
(
server
.
getServiceId
(),
client
);
RibbonLoadBalancedRetry
Factory
factory
=
new
RibbonLoadBalancedRetr
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
RetryPolicy
(
server
.
getServiceId
(),
client
);
HttpRequest
request
=
mock
(
HttpRequest
.
class
);
LoadBalancedRetryContext
context
=
spy
(
new
LoadBalancedRetryContext
(
null
,
request
));
...
...
@@ -260,8 +260,8 @@ public class RibbonLoadBalancedRetryPolicyFactoryTests {
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
);
RibbonLoadBalancedRetry
PolicyFactory
factory
=
new
RibbonLoadBalancedRetryPolic
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
(
server
.
getServiceId
(),
client
);
RibbonLoadBalancedRetry
Factory
factory
=
new
RibbonLoadBalancedRetr
yFactory
(
clientFactory
);
LoadBalancedRetryPolicy
policy
=
factory
.
create
RetryPolicy
(
server
.
getServiceId
(),
client
);
HttpRequest
request
=
mock
(
HttpRequest
.
class
);
doReturn
(
HttpMethod
.
GET
).
when
(
request
).
getMethod
();
assertThat
(
policy
.
retryableStatusCode
(
400
),
is
(
false
));
...
...
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/SpringRetryDisabledTests.java
View file @
a533bc06
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetry
Policy
Factory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
;
import
org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient
;
import
org.springframework.cloud.test.ClassPathExclusions
;
...
...
@@ -48,9 +48,8 @@ public class SpringRetryDisabledTests {
LoadBalancerAutoConfiguration
.
class
,
RibbonClientConfiguration
.
class
))
.
run
(
context
->
{
Map
<
String
,
LoadBalancedRetryPolicyFactory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetryPolicyFactory
.
class
);
assertThat
(
factories
.
values
(),
hasSize
(
1
));
assertThat
(
factories
.
values
().
toArray
()[
0
],
instanceOf
(
LoadBalancedRetryPolicyFactory
.
NeverRetryFactory
.
class
));
Map
<
String
,
LoadBalancedRetryFactory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetryFactory
.
class
);
assertThat
(
factories
.
values
(),
hasSize
(
0
));
Map
<
String
,
RibbonLoadBalancingHttpClient
>
clients
=
context
.
getBeansOfType
(
RibbonLoadBalancingHttpClient
.
class
);
assertThat
(
clients
.
values
(),
hasSize
(
1
));
assertThat
(
clients
.
values
().
toArray
()[
0
],
instanceOf
(
RibbonLoadBalancingHttpClient
.
class
));
...
...
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/SpringRetryEnabledTests.java
View file @
a533bc06
...
...
@@ -22,7 +22,8 @@ import java.util.Map;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.BeansException
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
;
import
org.springframework.cloud.commons.httpclient.HttpClientConfiguration
;
import
org.springframework.cloud.netflix.ribbon.apache.RetryableRibbonLoadBalancingHttpClient
;
...
...
@@ -48,9 +49,9 @@ public class SpringRetryEnabledTests implements ApplicationContextAware {
@Test
public
void
testLoadBalancedRetryFactoryBean
()
throws
Exception
{
Map
<
String
,
LoadBalancedRetry
PolicyFactory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetryPolic
yFactory
.
class
);
Map
<
String
,
LoadBalancedRetry
Factory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetr
yFactory
.
class
);
assertThat
(
factories
.
values
(),
hasSize
(
1
));
assertThat
(
factories
.
values
().
toArray
()[
0
],
instanceOf
(
RibbonLoadBalancedRetry
Policy
Factory
.
class
));
assertThat
(
factories
.
values
().
toArray
()[
0
],
instanceOf
(
RibbonLoadBalancedRetryFactory
.
class
));
Map
<
String
,
RibbonLoadBalancingHttpClient
>
clients
=
context
.
getBeansOfType
(
RibbonLoadBalancingHttpClient
.
class
);
assertThat
(
clients
.
values
(),
hasSize
(
1
));
assertThat
(
clients
.
values
().
toArray
()[
0
],
instanceOf
(
RetryableRibbonLoadBalancingHttpClient
.
class
));
...
...
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/apache/RibbonLoadBalancingHttpClientTests.java
View file @
a533bc06
This diff is collapsed.
Click to expand it.
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/SpringRetryDisableOkHttpClientTests.java
View file @
a533bc06
...
...
@@ -22,7 +22,7 @@ import org.junit.Test;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetry
Policy
Factory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
;
import
org.springframework.cloud.commons.httpclient.HttpClientConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration
;
...
...
@@ -52,9 +52,8 @@ public class SpringRetryDisableOkHttpClientTests {
.
withUserConfiguration
(
OkHttpLoadBalancingClientTests
.
OkHttpClientConfiguration
.
class
)
.
run
(
context
->
{
Map
<
String
,
LoadBalancedRetryPolicyFactory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetryPolicyFactory
.
class
);
assertThat
(
factories
.
values
(),
hasSize
(
1
));
assertThat
(
factories
.
values
().
toArray
()[
0
],
instanceOf
(
LoadBalancedRetryPolicyFactory
.
NeverRetryFactory
.
class
));
Map
<
String
,
LoadBalancedRetryFactory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetryFactory
.
class
);
assertThat
(
factories
.
values
(),
hasSize
(
0
));
Map
<
String
,
OkHttpLoadBalancingClient
>
clients
=
context
.
getBeansOfType
(
OkHttpLoadBalancingClient
.
class
);
assertThat
(
clients
.
values
(),
hasSize
(
1
));
assertThat
(
clients
.
values
().
toArray
()[
0
],
instanceOf
(
OkHttpLoadBalancingClient
.
class
));
...
...
spring-cloud-netflix-ribbon/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/SpringRetryEnabledOkHttpClientTests.java
View file @
a533bc06
...
...
@@ -15,32 +15,22 @@
*/
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
okhttp
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
java.net.URI
;
import
java.util.Map
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.BeansException
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedBackOffPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryListenerFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration
;
import
org.springframework.cloud.commons.httpclient.HttpClientConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryPolicy
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext
;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
...
...
@@ -50,7 +40,6 @@ import org.springframework.http.HttpMethod;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
com.netflix.client.ClientException
;
import
com.netflix.client.DefaultLoadBalancerRetryHandler
;
import
com.netflix.client.RetryHandler
;
...
...
@@ -59,8 +48,15 @@ import com.netflix.client.config.DefaultClientConfigImpl;
import
com.netflix.loadbalancer.ILoadBalancer
;
import
com.netflix.loadbalancer.Server
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* @author Ryan Baxter
...
...
@@ -74,16 +70,14 @@ public class SpringRetryEnabledOkHttpClientTests implements ApplicationContextAw
private
ApplicationContext
context
;
private
ILoadBalancer
loadBalancer
;
private
LoadBalancedBackOffPolicyFactory
loadBalancedBackOffPolicyFactory
=
new
LoadBalancedBackOffPolicyFactory
.
NoBackOffPolicyFactory
();
private
LoadBalancedRetryListenerFactory
loadBalancedRetryListenerFactory
=
new
LoadBalancedRetryListenerFactory
.
DefaultRetryListenerFactory
();
@Test
public
void
testLoadBalancedRetryFactoryBean
()
throws
Exception
{
Map
<
String
,
LoadBalancedRetry
Policy
Factory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetry
Policy
Factory
.
class
);
Map
<
String
,
LoadBalancedRetryFactory
>
factories
=
context
.
getBeansOfType
(
LoadBalancedRetryFactory
.
class
);
assertThat
(
factories
.
values
(),
hasSize
(
1
));
assertThat
(
factories
.
values
().
toArray
()[
0
],
instanceOf
(
RibbonLoadBalancedRetry
Policy
Factory
.
class
));
instanceOf
(
RibbonLoadBalancedRetryFactory
.
class
));
Map
<
String
,
OkHttpLoadBalancingClient
>
clients
=
context
.
getBeansOfType
(
OkHttpLoadBalancingClient
.
class
);
assertThat
(
clients
.
values
(),
hasSize
(
1
));
...
...
@@ -111,9 +105,9 @@ public class SpringRetryEnabledOkHttpClientTests implements ApplicationContextAw
SpringClientFactory
clientFactory
=
mock
(
SpringClientFactory
.
class
);
doReturn
(
context
).
when
(
clientFactory
).
getLoadBalancerContext
(
eq
(
serviceName
));
doReturn
(
clientConfig
).
when
(
clientFactory
).
getClientConfig
(
eq
(
serviceName
));
LoadBalancedRetry
PolicyFactory
factory
=
new
RibbonLoadBalancedRetryPolic
yFactory
(
clientFactory
);
LoadBalancedRetry
Factory
factory
=
new
RibbonLoadBalancedRetr
yFactory
(
clientFactory
);
RetryableOkHttpLoadBalancingClient
client
=
new
RetryableOkHttpLoadBalancingClient
(
delegate
,
clientConfig
,
introspector
,
factory
,
loadBalancedBackOffPolicyFactory
,
loadBalancedRetryListenerFactory
);
factory
);
client
.
setLoadBalancer
(
lb
);
ReflectionTestUtils
.
setField
(
client
,
"delegate"
,
delegate
);
return
client
;
...
...
spring-cloud-netflix-zuul/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/support/RibbonRetryIntegrationTestBase.java
View file @
a533bc06
...
...
@@ -30,13 +30,13 @@ import org.junit.Test;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser
;
import
org.springframework.cloud.netflix.ribbon.RibbonClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonClients
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryPolicy
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetry
Policy
Factory
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
...
...
@@ -210,23 +210,23 @@ public abstract class RibbonRetryIntegrationTestBase {
extends
RibbonClientConfiguration
{
@Bean
public
LoadBalancedRetry
Policy
Factory
loadBalancedRetryPolicyFactory
(
public
LoadBalancedRetryFactory
loadBalancedRetryPolicyFactory
(
SpringClientFactory
factory
)
{
return
new
MyRibbonRetry
Policy
Factory
(
factory
);
return
new
MyRibbonRetryFactory
(
factory
);
}
public
static
class
MyRibbonRetry
Policy
Factory
extends
RibbonLoadBalancedRetry
Policy
Factory
{
public
static
class
MyRibbonRetryFactory
extends
RibbonLoadBalancedRetryFactory
{
private
SpringClientFactory
factory
;
public
MyRibbonRetry
Policy
Factory
(
SpringClientFactory
clientFactory
)
{
public
MyRibbonRetryFactory
(
SpringClientFactory
clientFactory
)
{
super
(
clientFactory
);
this
.
factory
=
clientFactory
;
}
@Override
public
LoadBalancedRetryPolicy
create
(
String
serviceId
,
public
LoadBalancedRetryPolicy
create
RetryPolicy
(
String
serviceId
,
ServiceInstanceChooser
loadBalanceChooser
)
{
RibbonLoadBalancerContext
lbContext
=
this
.
factory
.
getLoadBalancerContext
(
serviceId
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment