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
ddd7979a
Commit
ddd7979a
authored
Jan 20, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't refresh the ipAddress if set by user config.
fixes gh-573
parent
3fb26f69
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
9 deletions
+43
-9
EurekaInstanceConfigBean.java
...mework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
+7
-7
EurekaInstanceConfigBeanTests.java
...k/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
+36
-2
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
View file @
ddd7979a
...
...
@@ -308,16 +308,16 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
this
.
hostInfo
.
override
=
true
;
}
public
void
setIpAddress
(
String
ipAddress
)
{
this
.
ipAddress
=
ipAddress
;
this
.
hostInfo
.
override
=
true
;
}
@Override
public
String
getHostName
(
boolean
refresh
)
{
if
(
refresh
)
{
boolean
originalOverride
=
this
.
hostInfo
.
override
;
this
.
hostInfo
=
this
.
inetUtils
.
findFirstNonLoopbackHostInfo
();
this
.
hostInfo
.
setOverride
(
originalOverride
);
if
(
refresh
&&
!
this
.
hostInfo
.
override
)
{
this
.
ipAddress
=
this
.
hostInfo
.
getIpAddress
();
if
(!
this
.
hostInfo
.
override
)
{
this
.
hostname
=
this
.
hostInfo
.
getHostname
();
}
this
.
hostname
=
this
.
hostInfo
.
getHostname
();
}
return
this
.
preferIpAddress
?
this
.
ipAddress
:
this
.
hostname
;
}
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
View file @
ddd7979a
...
...
@@ -43,11 +43,14 @@ public class EurekaInstanceConfigBeanTests {
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
private
String
hostName
;
private
String
ipAddress
;
@Before
public
void
init
()
{
this
.
hostName
=
new
InetUtils
(
new
InetUtilsProperties
())
.
findFirstNonLoopbackHostInfo
().
getHostname
();
InetUtils
.
HostInfo
hostInfo
=
new
InetUtils
(
new
InetUtilsProperties
())
.
findFirstNonLoopbackHostInfo
();
this
.
hostName
=
hostInfo
.
getHostname
();
this
.
ipAddress
=
hostInfo
.
getIpAddress
();
}
@After
...
...
@@ -111,6 +114,37 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public
void
initialIpAddress
()
{
addEnvironment
(
this
.
context
,
"eureka.instance.appGroupName=mygroup"
);
setupContext
();
if
(
this
.
ipAddress
!=
null
)
{
assertEquals
(
this
.
ipAddress
,
getInstanceConfig
().
getIpAddress
());
}
}
@Test
public
void
refreshIpAddress
()
{
addEnvironment
(
this
.
context
,
"eureka.instance.appGroupName=mygroup"
);
setupContext
();
ReflectionTestUtils
.
setField
(
getInstanceConfig
(),
"ipAddress"
,
"10.0.0.1"
);
assertEquals
(
"10.0.0.1"
,
getInstanceConfig
().
getIpAddress
());
getInstanceConfig
().
getHostName
(
true
);
if
(
this
.
ipAddress
!=
null
)
{
assertEquals
(
this
.
ipAddress
,
getInstanceConfig
().
getIpAddress
());
}
}
@Test
public
void
refreshIpAddressWhenSetByUser
()
{
addEnvironment
(
this
.
context
,
"eureka.instance.appGroupName=mygroup"
);
setupContext
();
getInstanceConfig
().
setIpAddress
(
"10.0.0.1"
);
assertEquals
(
"10.0.0.1"
,
getInstanceConfig
().
getIpAddress
());
getInstanceConfig
().
getHostName
(
true
);
assertEquals
(
"10.0.0.1"
,
getInstanceConfig
().
getIpAddress
());
}
@Test
public
void
testDefaultInitialStatus
()
{
setupContext
();
assertEquals
(
"initialStatus wrong"
,
InstanceStatus
.
UP
,
getInstanceConfig
()
...
...
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