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
3c5126c7
Commit
3c5126c7
authored
Jan 25, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate tests and bootstrap config for config server
parent
dbb60595
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
198 deletions
+14
-198
EurekaDiscoveryClientConfigServiceAutoConfiguration.java
.../EurekaDiscoveryClientConfigServiceAutoConfiguration.java
+1
-3
EurekaDiscoveryClientConfigServiceBootstrapConfiguration.java
...kaDiscoveryClientConfigServiceBootstrapConfiguration.java
+4
-59
spring.factories
...ureka-client/src/main/resources/META-INF/spring.factories
+2
-2
DiscoveryClientConfigServiceAutoConfigurationTests.java
...g/DiscoveryClientConfigServiceAutoConfigurationTests.java
+7
-7
DiscoveryClientConfigServiceBootstrapConfigurationTests.java
...coveryClientConfigServiceBootstrapConfigurationTests.java
+0
-127
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientConfigServiceAutoConfiguration.java
→
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/
Eureka
DiscoveryClientConfigServiceAutoConfiguration.java
View file @
3c5126c7
...
...
@@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
com.netflix.discovery.EurekaClient
;
...
...
@@ -35,8 +34,7 @@ import com.netflix.discovery.EurekaClient;
*/
@ConditionalOnBean
({
EurekaDiscoveryClientConfiguration
.
class
})
@ConditionalOnProperty
(
value
=
"spring.cloud.config.discovery.enabled"
,
matchIfMissing
=
false
)
@Configuration
(
value
=
"DiscoveryClientConfigServiceAutoConfiguration"
)
public
class
DiscoveryClientConfigServiceAutoConfiguration
{
public
class
EurekaDiscoveryClientConfigServiceAutoConfiguration
{
@Autowired
private
ConfigurableApplicationContext
context
;
...
...
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientConfigServiceBootstrapConfiguration.java
→
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/
Eureka
DiscoveryClientConfigServiceBootstrapConfiguration.java
View file @
3c5126c7
...
...
@@ -16,77 +16,22 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.config.client.ConfigClientProperties
;
import
org.springframework.cloud.config.client.ConfigServicePropertySourceLocator
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.context.event.EventListener
;
import
com.netflix.discovery.EurekaClient
;
import
lombok.extern.apachecommons.CommonsLog
;
/**
*
Bootstrap configuration for a
config client that wants to lookup the config server via
*
Eureka-specific helper for
config client that wants to lookup the config server via
* discovery.
*
* @author Dave Syer
*/
@ConditionalOnClass
(
{
EurekaClient
.
class
,
ConfigServicePropertySourceLocator
.
class
}
)
@ConditionalOnClass
(
ConfigServicePropertySourceLocator
.
class
)
@ConditionalOnProperty
(
value
=
"spring.cloud.config.discovery.enabled"
,
matchIfMissing
=
false
)
@Configuration
@Import
({
UtilAutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
})
@CommonsLog
public
class
DiscoveryClientConfigServiceBootstrapConfiguration
{
@Autowired
private
ConfigClientProperties
config
;
@Autowired
private
DiscoveryClient
client
;
@EventListener
(
ContextRefreshedEvent
.
class
)
public
void
onApplicationEvent
(
ContextRefreshedEvent
event
)
{
refresh
();
}
private
void
refresh
()
{
try
{
log
.
debug
(
"Locating configserver via discovery"
);
ServiceInstance
server
=
this
.
client
.
getInstances
(
this
.
config
.
getDiscovery
().
getServiceId
()).
get
(
0
);
String
url
=
getHomePage
(
server
);
if
(
server
.
getMetadata
().
containsKey
(
"password"
))
{
String
user
=
server
.
getMetadata
().
get
(
"user"
);
user
=
user
==
null
?
"user"
:
user
;
this
.
config
.
setUsername
(
user
);
String
password
=
server
.
getMetadata
().
get
(
"password"
);
this
.
config
.
setPassword
(
password
);
}
if
(
server
.
getMetadata
().
containsKey
(
"configPath"
))
{
String
path
=
server
.
getMetadata
().
get
(
"configPath"
);
if
(
url
.
endsWith
(
"/"
)
&&
path
.
startsWith
(
"/"
))
{
url
=
url
.
substring
(
0
,
url
.
length
()
-
1
);
}
url
=
url
+
path
;
}
this
.
config
.
setUri
(
url
);
}
catch
(
Exception
ex
)
{
log
.
warn
(
"Could not locate configserver via discovery"
,
ex
);
}
}
private
String
getHomePage
(
ServiceInstance
server
)
{
return
server
.
getUri
().
toString
()
+
"/"
;
}
@Import
({
EurekaClientAutoConfiguration
.
class
})
public
class
EurekaDiscoveryClientConfigServiceBootstrapConfiguration
{
}
spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring.factories
View file @
3c5126c7
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration,\
org.springframework.cloud.netflix.eureka.config.DiscoveryClientConfigServiceAutoConfiguration,\
org.springframework.cloud.netflix.eureka.config.
Eureka
DiscoveryClientConfigServiceAutoConfiguration,\
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\
org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.netflix.eureka.config.DiscoveryClientConfigServiceBootstrapConfiguration
org.springframework.cloud.netflix.eureka.config.
Eureka
DiscoveryClientConfigServiceBootstrapConfiguration
org.springframework.cloud.client.discovery.EnableDiscoveryClient=\
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientConfigServiceAutoConfigurationTests.java
View file @
3c5126c7
...
...
@@ -24,8 +24,8 @@ import org.mockito.Mockito;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.cloud.config.client.ConfigClientProperties
;
import
org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -62,7 +62,7 @@ public class DiscoveryClientConfigServiceAutoConfigurationTests {
"eureka.instance.metadataMap.foo:bar"
,
"eureka.instance.nonSecurePort:7001"
,
"eureka.instance.hostname:foo"
);
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
DiscoveryClientConfigServiceAutoConfiguration
.
class
).
length
);
Eureka
DiscoveryClientConfigServiceAutoConfiguration
.
class
).
length
);
EurekaClient
eurekaClient
=
this
.
context
.
getParent
().
getBean
(
EurekaClient
.
class
);
Mockito
.
verify
(
eurekaClient
,
times
(
2
)).
getInstancesByVipAddress
(
"CONFIGSERVER"
,
false
);
...
...
@@ -79,16 +79,16 @@ public class DiscoveryClientConfigServiceAutoConfigurationTests {
AnnotationConfigApplicationContext
parent
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
parent
,
env
);
parent
.
register
(
UtilAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
EnvironmentKnobbler
.
class
,
EurekaDiscoveryClientConfigServiceBootstrapConfiguration
.
class
,
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
,
EnvironmentKnobbler
.
class
,
ConfigClientProperties
.
class
);
ConfigClientProperties
.
class
);
parent
.
refresh
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
setParent
(
parent
);
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
DiscoveryClientConfigServiceAutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
,
EurekaDiscoveryClientConfiguration
.
class
);
EurekaDiscoveryClientConfigServiceAutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
);
this
.
context
.
refresh
();
}
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientConfigServiceBootstrapConfigurationTests.java
deleted
100644 → 0
View file @
dbb60595
/*
* 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
*
* 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.
*/
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
config
;
import
java.util.Arrays
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.cloud.client.DefaultServiceInstance
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.config.client.ConfigClientProperties
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
* @author Dave Syer
*/
public
class
DiscoveryClientConfigServiceBootstrapConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
private
DiscoveryClient
client
=
Mockito
.
mock
(
DiscoveryClient
.
class
);
private
ServiceInstance
info
=
new
DefaultServiceInstance
(
"app"
,
"foo"
,
8877
,
false
);
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
offByDefault
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
(
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
);
assertEquals
(
0
,
this
.
context
.
getBeanNamesForType
(
DiscoveryClient
.
class
).
length
);
assertEquals
(
0
,
this
.
context
.
getBeanNamesForType
(
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
).
length
);
}
@Test
public
void
onWhenRequested
()
throws
Exception
{
given
(
this
.
client
.
getInstances
(
"CONFIGSERVER"
))
.
willReturn
(
Arrays
.
asList
(
this
.
info
));
setup
(
"spring.cloud.config.discovery.enabled=true"
);
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
).
length
);
Mockito
.
verify
(
this
.
client
).
getInstances
(
"CONFIGSERVER"
);
ConfigClientProperties
locator
=
this
.
context
.
getBean
(
ConfigClientProperties
.
class
);
assertEquals
(
"http://foo:8877/"
,
locator
.
getRawUri
());
}
@Test
public
void
secureWhenRequested
()
throws
Exception
{
this
.
info
=
new
DefaultServiceInstance
(
"app"
,
"foo"
,
443
,
true
);
given
(
this
.
client
.
getInstances
(
"CONFIGSERVER"
))
.
willReturn
(
Arrays
.
asList
(
this
.
info
));
setup
(
"spring.cloud.config.discovery.enabled=true"
);
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
).
length
);
Mockito
.
verify
(
this
.
client
).
getInstances
(
"CONFIGSERVER"
);
ConfigClientProperties
locator
=
this
.
context
.
getBean
(
ConfigClientProperties
.
class
);
assertEquals
(
"https://foo:443/"
,
locator
.
getRawUri
());
}
@Test
public
void
setsPasssword
()
throws
Exception
{
this
.
info
.
getMetadata
().
put
(
"password"
,
"bar"
);
given
(
this
.
client
.
getInstances
(
"CONFIGSERVER"
))
.
willReturn
(
Arrays
.
asList
(
this
.
info
));
setup
(
"spring.cloud.config.discovery.enabled=true"
);
ConfigClientProperties
locator
=
this
.
context
.
getBean
(
ConfigClientProperties
.
class
);
assertEquals
(
"http://foo:8877/"
,
locator
.
getRawUri
());
assertEquals
(
"bar"
,
locator
.
getPassword
());
assertEquals
(
"user"
,
locator
.
getUsername
());
}
@Test
public
void
setsPath
()
throws
Exception
{
this
.
info
.
getMetadata
().
put
(
"configPath"
,
"/bar"
);
given
(
this
.
client
.
getInstances
(
"CONFIGSERVER"
))
.
willReturn
(
Arrays
.
asList
(
this
.
info
));
setup
(
"spring.cloud.config.discovery.enabled=true"
);
ConfigClientProperties
locator
=
this
.
context
.
getBean
(
ConfigClientProperties
.
class
);
assertEquals
(
"http://foo:8877/bar"
,
locator
.
getRawUri
());
}
private
void
setup
(
String
...
env
)
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
env
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"eureka.client.enabled=false"
);
this
.
context
.
getDefaultListableBeanFactory
().
registerSingleton
(
"discoveryClient"
,
this
.
client
);
this
.
context
.
register
(
UtilAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
,
ConfigClientProperties
.
class
);
this
.
context
.
refresh
();
}
}
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