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
9c416bf6
Commit
9c416bf6
authored
Jan 01, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use getHostname() instead of field in DatacenterInfo
Fixes gh-122
parent
3bbe4ae2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
36 deletions
+31
-36
EurekaInstanceConfigBean.java
...mework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
+2
-2
EurekaInstanceConfigBeanTests.java
...k/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
+29
-34
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
View file @
9c416bf6
...
...
@@ -136,11 +136,11 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
public
String
getId
()
{
String
instanceId
=
metadataMap
.
get
(
"instanceId"
);
if
(
instanceId
!=
null
)
{
String
old
=
hostname
;
String
old
=
getHostname
()
;
String
id
=
old
.
endsWith
(
instanceId
)
?
old
:
old
+
":"
+
instanceId
;
return
id
;
}
return
hostname
;
return
getHostname
()
;
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
View file @
9c416bf6
/*
*
Copyright 2013-2014 the original author or authors.
Copyright 2013-2014 the original author or authors.
*
*
Licensed under the Apache License, Version 2.0 (the "License");
*
you may not use this file except in compliance with the License.
*
You may obtain a copy of the License at
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
*
*
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
*
*
Unless required by applicable law or agreed to in writing, software
*
distributed under the License is distributed on an "AS IS" BASIS,
*
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
See the License for the specific language governing permissions and
*
limitations under the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
org
.
springframework
.
cloud
.
netflix
.
eureka
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
boot
.
test
.
EnvironmentTestUtils
.
addEnvironment
;
import
org.junit.After
;
...
...
@@ -106,6 +107,24 @@ public class EurekaInstanceConfigBeanTests {
.
getInitialStatus
());
}
@Test
public
void
testPerferIpAddress
()
throws
Exception
{
addEnvironment
(
context
,
"eureka.instance.preferIpAddress:true"
);
setupContext
();
assertTrue
(
"Wrong hostname: "
+
getInstanceConfig
().
getHostname
(),
getInstanceConfig
().
getHostname
().
startsWith
(
"127.0."
));
}
@Test
public
void
testPerferIpAddressInDatacenter
()
throws
Exception
{
addEnvironment
(
context
,
"eureka.instance.preferIpAddress:true"
);
setupContext
();
String
id
=
((
UniqueIdentifier
)
getInstanceConfig
().
getDataCenterInfo
()).
getId
();
assertTrue
(
"Wrong hostname: "
+
id
,
id
.
startsWith
(
"127.0."
));
}
private
void
setupContext
()
{
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
...
...
@@ -116,30 +135,6 @@ public class EurekaInstanceConfigBeanTests {
return
context
.
getBean
(
EurekaInstanceConfigBean
.
class
);
}
/*
* @Test public void serviceUrlWithCompositePropertySource() { CompositePropertySource
* source = new CompositePropertySource("composite");
* context.getEnvironment().getPropertySources().addFirst(source);
* source.addPropertySource(new MapPropertySource("config", Collections .<String,
* Object> singletonMap("eureka.client.serviceUrl.defaultZone",
* "http://example.com")));
* context.register(PropertyPlaceholderAutoConfiguration.class,
* TestConfiguration.class); context.refresh();
* assertEquals("{defaultZone=http://example.com}",
* context.getBean(EurekaInstanceConfigBean.class).getServiceUrl().toString());
* assertEquals( "[http://example.com]",
* context.getBean(EurekaInstanceConfigBean.class)
* .getEurekaServerServiceUrls("defaultZone").toString()); }
*
* @Test public void serviceUrlWithDefault() {
* EnvironmentTestUtils.addEnvironment(context,
* "eureka.client.serviceUrl.defaultZone:",
* "eureka.client.serviceUrl.default:http://example.com");
* context.register(PropertyPlaceholderAutoConfiguration.class,
* TestConfiguration.class); context.refresh(); assertEquals( "[http://example.com]",
* context.getBean(EurekaInstanceConfigBean.class)
* .getEurekaServerServiceUrls("defaultZone").toString()); }
*/
@Configuration
@EnableConfigurationProperties
(
EurekaInstanceConfigBean
.
class
)
protected
static
class
TestConfiguration
{
...
...
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