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
f76f294f
Commit
f76f294f
authored
Aug 17, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename test to conform to usual pattern
parent
64fff7ed
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
54 deletions
+52
-54
RestTemplateRetryTests.java
...rk/cloud/netflix/resttemplate/RestTemplateRetryTests.java
+52
-54
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/resttemplate/RestTemplateRetryTest.java
→
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/resttemplate/RestTemplateRetryTest
s
.java
View file @
f76f294f
package
org
.
springframework
.
cloud
.
netflix
.
resttemplate
;
package
org
.
springframework
.
cloud
.
netflix
.
resttemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
@@ -42,16 +39,19 @@ import com.netflix.loadbalancer.ServerList;
...
@@ -42,16 +39,19 @@ import com.netflix.loadbalancer.ServerList;
import
com.netflix.loadbalancer.ServerStats
;
import
com.netflix.loadbalancer.ServerStats
;
import
com.netflix.niws.client.http.HttpClientLoadBalancerErrorHandler
;
import
com.netflix.niws.client.http.HttpClientLoadBalancerErrorHandler
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
RestTemplateRetryTest
.
Application
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
value
=
{
@SpringBootTest
(
classes
=
RestTemplateRetryTest
s
.
Application
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"spring.application.name=resttemplatetest"
,
"spring.application.name=resttemplatetest"
,
"logging.level.org.springframework.cloud.netflix.resttemplate=DEBUG"
,
"logging.level.org.springframework.cloud.netflix.resttemplate=DEBUG"
,
"badClients.ribbon.MaxAutoRetries=0"
,
"badClients.ribbon.MaxAutoRetries=0"
,
"badClients.ribbon.OkToRetryOnAllOperations=true"
,
"ribbon.http.client.enabled"
})
"badClients.ribbon.OkToRetryOnAllOperations=true"
,
"ribbon.http.client.enabled"
})
@DirtiesContext
@DirtiesContext
public
class
RestTemplateRetryTest
{
public
class
RestTemplateRetryTest
s
{
final
private
static
Log
logger
=
LogFactory
.
getLog
(
RestTemplateRetryTest
.
class
);
final
private
static
Log
logger
=
LogFactory
.
getLog
(
RestTemplateRetryTest
s
.
class
);
@Value
(
"${local.server.port}"
)
@Value
(
"${local.server.port}"
)
private
int
port
=
0
;
private
int
port
=
0
;
...
@@ -59,50 +59,7 @@ public class RestTemplateRetryTest {
...
@@ -59,50 +59,7 @@ public class RestTemplateRetryTest {
@Autowired
@Autowired
private
RestTemplate
testClient
;
private
RestTemplate
testClient
;
public
RestTemplateRetryTest
()
{
public
RestTemplateRetryTests
()
{
}
@Configuration
@EnableAutoConfiguration
@RestController
@RibbonClient
(
name
=
"badClients"
,
configuration
=
LocalBadClientConfiguration
.
class
)
public
static
class
Application
{
private
AtomicInteger
hits
=
new
AtomicInteger
(
1
);
private
AtomicInteger
retryHits
=
new
AtomicInteger
(
1
);
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/ping"
)
public
int
ping
()
{
return
0
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/good"
)
public
int
good
()
{
int
lValue
=
this
.
hits
.
getAndIncrement
();
return
lValue
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/timeout"
)
public
int
timeout
()
throws
Exception
{
int
lValue
=
this
.
retryHits
.
getAndIncrement
();
// Force the good server to have 2 consecutive errors a couple of times.
if
(
lValue
==
2
||
lValue
==
3
||
lValue
==
5
||
lValue
==
6
)
{
Thread
.
sleep
(
500
);
}
return
lValue
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/null"
)
public
int
isNull
()
throws
Exception
{
throw
new
NullPointerException
(
"Null"
);
}
@LoadBalanced
@Bean
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
}
}
@Before
@Before
...
@@ -188,7 +145,7 @@ public class RestTemplateRetryTest {
...
@@ -188,7 +145,7 @@ public class RestTemplateRetryTest {
assertTrue
(
badServer2Stats
.
isCircuitBreakerTripped
());
assertTrue
(
badServer2Stats
.
isCircuitBreakerTripped
());
assertEquals
(
targetConnectionCount
,
goodServerStats
.
getTotalRequestsCount
());
assertEquals
(
targetConnectionCount
,
goodServerStats
.
getTotalRequestsCount
());
assertEquals
(
20
,
hits
);
assertEquals
(
20
,
hits
);
System
.
out
.
println
(
"Retry Hits: "
+
hits
);
logger
.
debug
(
"Retry Hits: "
+
hits
);
}
}
@Test
@Test
...
@@ -230,6 +187,49 @@ public class RestTemplateRetryTest {
...
@@ -230,6 +187,49 @@ public class RestTemplateRetryTest {
}
}
@Configuration
@EnableAutoConfiguration
@RestController
@RibbonClient
(
name
=
"badClients"
,
configuration
=
LocalBadClientConfiguration
.
class
)
public
static
class
Application
{
private
AtomicInteger
hits
=
new
AtomicInteger
(
1
);
private
AtomicInteger
retryHits
=
new
AtomicInteger
(
1
);
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/ping"
)
public
int
ping
()
{
return
0
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/good"
)
public
int
good
()
{
int
lValue
=
this
.
hits
.
getAndIncrement
();
return
lValue
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/timeout"
)
public
int
timeout
()
throws
Exception
{
int
lValue
=
this
.
retryHits
.
getAndIncrement
();
// Force the good server to have 2 consecutive errors a couple of times.
if
(
lValue
==
2
||
lValue
==
3
||
lValue
==
5
||
lValue
==
6
)
{
Thread
.
sleep
(
500
);
}
return
lValue
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/null"
)
public
int
isNull
()
throws
Exception
{
throw
new
NullPointerException
(
"Null"
);
}
@LoadBalanced
@Bean
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
}
}
}
}
// Load balancer with fixed server list for "local" pointing to localhost
// Load balancer with fixed server list for "local" pointing to localhost
...
@@ -251,8 +251,7 @@ class LocalBadClientConfiguration {
...
@@ -251,8 +251,7 @@ class LocalBadClientConfiguration {
@Bean
@Bean
public
IRule
loadBalancerRule
()
{
public
IRule
loadBalancerRule
()
{
// This is a good place to try different load balancing rules and how those rules
// This is a good place to try different load balancing rules and how those rules
// behave in failure
// behave in failure states: BestAvailableRule, WeightedResponseTimeRule, etc
// states: BestAvailableRule, WeightedResponseTimeRule, etc
// This rule just uses a round robin and will skip servers that are in circuit
// This rule just uses a round robin and will skip servers that are in circuit
// breaker state.
// breaker state.
...
@@ -283,7 +282,6 @@ class LocalBadClientConfiguration {
...
@@ -283,7 +282,6 @@ class LocalBadClientConfiguration {
public
OverrideRetryHandler
()
{
public
OverrideRetryHandler
()
{
this
.
circuitRelated
.
add
(
UnknownHostException
.
class
);
this
.
circuitRelated
.
add
(
UnknownHostException
.
class
);
this
.
retriable
.
add
(
UnknownHostException
.
class
);
this
.
retriable
.
add
(
UnknownHostException
.
class
);
}
}
}
}
...
...
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