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
7b6f1480
Commit
7b6f1480
authored
Mar 02, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return null for choose() rather than throw an illegal argument exception.
fixes gh-236
parent
ab714bd9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
+22
-9
RibbonLoadBalancerClient.java
...mework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
+11
-9
RibbonLoadBalancerClientTests.java
...k/cloud/netflix/ribbon/RibbonLoadBalancerClientTests.java
+11
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
View file @
7b6f1480
...
...
@@ -53,7 +53,11 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
@Override
public
ServiceInstance
choose
(
String
serviceId
)
{
return
new
RibbonServer
(
serviceId
,
getServer
(
serviceId
));
Server
server
=
getServer
(
serviceId
);
if
(
server
==
null
)
{
return
null
;
}
return
new
RibbonServer
(
serviceId
,
server
);
}
@Override
...
...
@@ -61,7 +65,7 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
ILoadBalancer
loadBalancer
=
getLoadBalancer
(
serviceId
);
RibbonLoadBalancerContext
context
=
this
.
clientFactory
.
getLoadBalancerContext
(
serviceId
);
Server
server
=
getServer
(
serviceId
,
loadBalancer
);
Server
server
=
getServer
(
loadBalancer
);
RibbonServer
ribbonServer
=
new
RibbonServer
(
serviceId
,
server
);
ServerStats
serverStats
=
context
.
getServerStats
(
server
);
...
...
@@ -88,16 +92,14 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
}
protected
Server
getServer
(
String
serviceId
)
{
return
getServer
(
serviceId
,
getLoadBalancer
(
serviceId
));
return
getServer
(
getLoadBalancer
(
serviceId
));
}
protected
Server
getServer
(
String
serviceId
,
ILoadBalancer
loadBalancer
)
{
Server
server
=
loadBalancer
.
chooseServer
(
"default"
);
if
(
server
==
null
)
{
throw
new
IllegalStateException
(
"Unable to locate ILoadBalancer for service: "
+
serviceId
);
protected
Server
getServer
(
ILoadBalancer
loadBalancer
)
{
if
(
loadBalancer
==
null
)
{
return
null
;
}
return
server
;
return
loadBalancer
.
chooseServer
(
"default"
);
//TODO: better handling of key
}
protected
ILoadBalancer
getLoadBalancer
(
String
serviceId
)
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClientTests.java
View file @
7b6f1480
...
...
@@ -35,6 +35,7 @@ import com.netflix.loadbalancer.ServerStats;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyDouble
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
...
...
@@ -84,6 +85,16 @@ public class RibbonLoadBalancerClientTests {
}
@Test
public
void
testChooseMissing
()
{
given
(
this
.
clientFactory
.
getLoadBalancer
(
this
.
loadBalancer
.
getName
()))
.
willReturn
(
null
);
given
(
this
.
loadBalancer
.
getName
()).
willReturn
(
"missingservice"
);
RibbonLoadBalancerClient
client
=
new
RibbonLoadBalancerClient
(
this
.
clientFactory
);
ServiceInstance
instance
=
client
.
choose
(
"missingservice"
);
assertNull
(
"instance wasn't null"
,
instance
);
}
@Test
public
void
testExecute
()
{
final
RibbonServer
server
=
getRibbonServer
();
RibbonLoadBalancerClient
client
=
getRibbonLoadBalancerClient
(
server
);
...
...
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