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
2f581a11
Commit
2f581a11
authored
Jul 21, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use JUnit assertions
parent
110f8727
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
28 deletions
+27
-28
RestTemplateRetryTest.java
...ork/cloud/netflix/resttemplate/RestTemplateRetryTest.java
+27
-28
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/resttemplate/RestTemplateRetryTest.java
View file @
2f581a11
...
...
@@ -20,7 +20,6 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.util.Assert
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -40,6 +39,9 @@ import com.netflix.loadbalancer.ServerList;
import
com.netflix.loadbalancer.ServerStats
;
import
com.netflix.niws.client.http.HttpClientLoadBalancerErrorHandler
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
RestTemplateRetryTest
.
Application
.
class
)
@WebIntegrationTest
(
randomPort
=
true
,
value
=
{
...
...
@@ -77,13 +79,13 @@ public class RestTemplateRetryTest {
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/good"
)
public
int
good
()
{
int
lValue
=
hits
.
getAndIncrement
();
int
lValue
=
this
.
hits
.
getAndIncrement
();
return
lValue
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/timeout"
)
public
int
timeout
()
throws
Exception
{
int
lValue
=
retryHits
.
getAndIncrement
();
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
)
{
...
...
@@ -107,7 +109,7 @@ public class RestTemplateRetryTest {
@Before
public
void
setup
()
throws
Exception
{
// Force Ribbon configuration by making one call.
testClient
.
getForObject
(
"http://badClients/ping"
,
Integer
.
class
);
t
his
.
t
estClient
.
getForObject
(
"http://badClients/ping"
,
Integer
.
class
);
}
@Test
...
...
@@ -129,7 +131,7 @@ public class RestTemplateRetryTest {
// A null pointer should NOT trigger a circuit breaker.
for
(
int
index
=
0
;
index
<
10
;
index
++)
{
try
{
testClient
.
getForObject
(
"http://badClients/null"
,
Integer
.
class
);
t
his
.
t
estClient
.
getForObject
(
"http://badClients/null"
,
Integer
.
class
);
}
catch
(
Exception
exception
)
{
}
...
...
@@ -138,9 +140,9 @@ public class RestTemplateRetryTest {
logServerStats
(
LocalBadClientConfiguration
.
badServer2
);
logServerStats
(
LocalBadClientConfiguration
.
goodServer
);
Assert
.
is
True
(
badServer1Stats
.
isCircuitBreakerTripped
());
Assert
.
is
True
(
badServer2Stats
.
isCircuitBreakerTripped
());
Assert
.
isTrue
(
goodServerStats
.
getTotalRequestsCount
()
==
targetConnectionCount
);
assert
True
(
badServer1Stats
.
isCircuitBreakerTripped
());
assert
True
(
badServer2Stats
.
isCircuitBreakerTripped
());
assertEquals
(
targetConnectionCount
,
goodServerStats
.
getTotalRequestsCount
()
);
// Wait for any timeout thread to finish.
...
...
@@ -176,17 +178,17 @@ public class RestTemplateRetryTest {
int
hits
=
0
;
for
(
int
index
=
0
;
index
<
20
;
index
++)
{
hits
=
testClient
.
getForObject
(
"http://badClients/good"
,
Integer
.
class
);
hits
=
t
his
.
t
estClient
.
getForObject
(
"http://badClients/good"
,
Integer
.
class
);
}
logServerStats
(
LocalBadClientConfiguration
.
badServer
);
logServerStats
(
LocalBadClientConfiguration
.
badServer2
);
logServerStats
(
LocalBadClientConfiguration
.
goodServer
);
Assert
.
is
True
(
badServer1Stats
.
isCircuitBreakerTripped
());
Assert
.
is
True
(
badServer2Stats
.
isCircuitBreakerTripped
());
Assert
.
isTrue
(
goodServerStats
.
getTotalRequestsCount
()
==
targetConnectionCount
);
Assert
.
isTrue
(
hits
==
20
);
assert
True
(
badServer1Stats
.
isCircuitBreakerTripped
());
assert
True
(
badServer2Stats
.
isCircuitBreakerTripped
());
assertEquals
(
targetConnectionCount
,
goodServerStats
.
getTotalRequestsCount
()
);
assertEquals
(
20
,
hits
);
System
.
out
.
println
(
"Retry Hits: "
+
hits
);
}
...
...
@@ -204,24 +206,25 @@ public class RestTemplateRetryTest {
badServer1Stats
.
clearSuccessiveConnectionFailureCount
();
badServer2Stats
.
clearSuccessiveConnectionFailureCount
();
Assert
.
is
True
(!
badServer1Stats
.
isCircuitBreakerTripped
());
Assert
.
is
True
(!
badServer2Stats
.
isCircuitBreakerTripped
());
assert
True
(!
badServer1Stats
.
isCircuitBreakerTripped
());
assert
True
(!
badServer2Stats
.
isCircuitBreakerTripped
());
int
hits
=
0
;
for
(
int
index
=
0
;
index
<
15
;
index
++)
{
hits
=
testClient
.
getForObject
(
"http://badClients/timeout"
,
Integer
.
class
);
hits
=
this
.
testClient
.
getForObject
(
"http://badClients/timeout"
,
Integer
.
class
);
}
logServerStats
(
LocalBadClientConfiguration
.
badServer
);
logServerStats
(
LocalBadClientConfiguration
.
badServer2
);
logServerStats
(
LocalBadClientConfiguration
.
goodServer
);
Assert
.
is
True
(
badServer1Stats
.
isCircuitBreakerTripped
());
Assert
.
is
True
(
badServer2Stats
.
isCircuitBreakerTripped
());
Assert
.
is
True
(!
goodServerStats
.
isCircuitBreakerTripped
());
assert
True
(
badServer1Stats
.
isCircuitBreakerTripped
());
assert
True
(
badServer2Stats
.
isCircuitBreakerTripped
());
assert
True
(!
goodServerStats
.
isCircuitBreakerTripped
());
// 15 + 4 timeouts. See the endpoint for timeout conditions.
Assert
.
isTrue
(
hits
==
19
);
assertEquals
(
19
,
hits
);
// Wait for any timeout thread to finish.
Thread
.
sleep
(
600
);
...
...
@@ -266,12 +269,8 @@ class LocalBadClientConfiguration {
badServer
=
new
Server
(
"mybadhost"
,
10001
);
badServer2
=
new
Server
(
"localhost"
,
-
1
);
balancer
=
LoadBalancerBuilder
.
newBuilder
()
.
withClientConfig
(
config
)
.
withRule
(
rule
)
.
withPing
(
ping
)
.
buildFixedServerListLoadBalancer
(
balancer
=
LoadBalancerBuilder
.
newBuilder
().
withClientConfig
(
config
)
.
withRule
(
rule
).
withPing
(
ping
).
buildFixedServerListLoadBalancer
(
Arrays
.
asList
(
badServer
,
badServer2
,
goodServer
));
return
balancer
;
}
...
...
@@ -283,8 +282,8 @@ class LocalBadClientConfiguration {
static
class
OverrideRetryHandler
extends
HttpClientLoadBalancerErrorHandler
{
public
OverrideRetryHandler
()
{
circuitRelated
.
add
(
UnknownHostException
.
class
);
retriable
.
add
(
UnknownHostException
.
class
);
this
.
circuitRelated
.
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