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
5acf4e1a
Unverified
Commit
5acf4e1a
authored
Apr 25, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw IOException in RibbonLoadBalancerClient.execute
Fixes proper RestTemplate behavior. fixes gh-986
parent
2b409524
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
RibbonLoadBalancerClient.java
...mework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
+7
-1
RibbonLoadBalancerClientTests.java
...k/cloud/netflix/ribbon/RibbonLoadBalancerClientTests.java
+26
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
View file @
5acf4e1a
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.util.Collections
;
import
java.util.Map
;
...
...
@@ -71,7 +72,7 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
}
@Override
public
<
T
>
T
execute
(
String
serviceId
,
LoadBalancerRequest
<
T
>
request
)
{
public
<
T
>
T
execute
(
String
serviceId
,
LoadBalancerRequest
<
T
>
request
)
throws
IOException
{
ILoadBalancer
loadBalancer
=
getLoadBalancer
(
serviceId
);
Server
server
=
getServer
(
loadBalancer
);
if
(
server
==
null
)
{
...
...
@@ -89,6 +90,11 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
statsRecorder
.
recordStats
(
returnVal
);
return
returnVal
;
}
// catch IOException and rethrow so RestTemplate behaves correctly
catch
(
IOException
ex
)
{
statsRecorder
.
recordStats
(
ex
);
throw
ex
;
}
catch
(
Exception
ex
)
{
statsRecorder
.
recordStats
(
ex
);
ReflectionUtils
.
rethrowRuntimeException
(
ex
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClientTests.java
View file @
5acf4e1a
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URL
;
import
java.util.Collections
;
...
...
@@ -38,9 +39,12 @@ import com.netflix.loadbalancer.ServerStats;
import
lombok.SneakyThrows
;
import
static
org
.
hamcrest
.
Matchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyDouble
;
...
...
@@ -139,7 +143,7 @@ public class RibbonLoadBalancerClientTests {
}
@Test
public
void
testExecute
()
{
public
void
testExecute
()
throws
IOException
{
final
RibbonServer
server
=
getRibbonServer
();
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
server
);
final
String
returnVal
=
"myval"
;
...
...
@@ -176,6 +180,27 @@ public class RibbonLoadBalancerClientTests {
verifyServerStats
();
}
@Test
public
void
testExecuteIOException
()
{
final
RibbonServer
ribbonServer
=
getRibbonServer
();
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
ribbonServer
);
try
{
client
.
execute
(
ribbonServer
.
getServiceId
(),
new
LoadBalancerRequest
<
Object
>()
{
@Override
public
Object
apply
(
ServiceInstance
instance
)
throws
Exception
{
assertServiceInstance
(
ribbonServer
,
instance
);
throw
new
IOException
();
}
});
fail
(
"Should have thrown exception"
);
}
catch
(
Exception
ex
)
{
assertThat
(
"wrong exception type"
,
ex
,
is
(
instanceOf
(
IOException
.
class
)));
}
verifyServerStats
();
}
protected
RibbonServer
getRibbonServer
()
{
return
new
RibbonServer
(
"testService"
,
new
Server
(
"myhost"
,
9080
),
false
,
Collections
.
singletonMap
(
"mykey"
,
"myvalue"
));
...
...
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