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
5a42cb1b
Commit
5a42cb1b
authored
Oct 20, 2016
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates based on latest version from commons
parent
ee99efba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
13 deletions
+17
-13
pom.xml
spring-cloud-netflix-core/pom.xml
+8
-0
RibbonLoadBalancedRetryPolicyFactory.java
.../netflix/ribbon/RibbonLoadBalancedRetryPolicyFactory.java
+4
-3
RibbonInterceptorTests.java
...ramework/cloud/netflix/ribbon/RibbonInterceptorTests.java
+5
-10
No files found.
spring-cloud-netflix-core/pom.xml
View file @
5a42cb1b
...
...
@@ -45,6 +45,14 @@
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.retry
</groupId>
<artifactId>
spring-retry
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-commons
</artifactId>
<optional>
true
</optional>
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryPolicyFactory.java
View file @
5a42cb1b
...
...
@@ -16,10 +16,10 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanceChooser
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.http.HttpMethod
;
/**
...
...
@@ -32,8 +32,9 @@ public class RibbonLoadBalancedRetryPolicyFactory implements LoadBalancedRetryPo
public
RibbonLoadBalancedRetryPolicyFactory
(
SpringClientFactory
clientFactory
)
{
this
.
clientFactory
=
clientFactory
;
}
@Override
public
LoadBalancedRetryPolicy
create
(
final
String
serviceId
,
final
LoadBalance
rClient
loadBalancerClient
)
{
public
LoadBalancedRetryPolicy
create
(
final
String
serviceId
,
final
LoadBalance
Chooser
loadBalanceChooser
)
{
final
RibbonLoadBalancerContext
lbContext
=
this
.
clientFactory
.
getLoadBalancerContext
(
serviceId
);
return
new
LoadBalancedRetryPolicy
()
{
...
...
@@ -69,7 +70,7 @@ public class RibbonLoadBalancedRetryPolicyFactory implements LoadBalancedRetryPo
//Do this before we increment the counters because the first call to this method
//is not a retry it is just an initial failure.
if
(!
canRetrySameServer
(
context
)
&&
canRetryNextServer
(
context
))
{
context
.
setServiceInstance
(
loadBalance
rClient
.
choose
(
serviceId
));
context
.
setServiceInstance
(
loadBalance
Chooser
.
choose
(
serviceId
));
}
//This method is called regardless of whether we are retrying or making the first request.
//Since we do not count the initial request in the retry count we don't reset the counter
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonInterceptorTests.java
View file @
5a42cb1b
...
...
@@ -16,30 +16,26 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
com.netflix.loadbalancer.Server
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URL
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicyFactory
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRetryProperties
;
import
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.http.client.ClientHttpRequestExecution
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.client.support.HttpRequestWrapper
;
import
org.springframework.retry.support.RetryTemplate
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URL
;
import
com.netflix.loadbalancer.Server
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
...
...
@@ -69,8 +65,7 @@ public class RibbonInterceptorTests {
@Test
public
void
testIntercept
()
throws
Exception
{
RibbonServer
server
=
new
RibbonServer
(
"myservice"
,
new
Server
(
"myhost"
,
8080
));
LoadBalancerInterceptor
interceptor
=
new
LoadBalancerInterceptor
(
new
MyClient
(
server
),
new
RetryTemplate
(),
new
LoadBalancerRetryProperties
(),
new
LoadBalancedRetryPolicyFactory
.
NeverRetryFactory
());
LoadBalancerInterceptor
interceptor
=
new
LoadBalancerInterceptor
(
new
MyClient
(
server
));
given
(
this
.
request
.
getURI
()).
willReturn
(
new
URL
(
"http://myservice"
).
toURI
());
given
(
this
.
execution
.
execute
(
isA
(
HttpRequest
.
class
),
isA
(
byte
[].
class
)))
.
willReturn
(
this
.
response
);
...
...
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