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
58471753
Commit
58471753
authored
Jan 15, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Turbine port listener class and add tests
parent
e2e09c46
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
7 deletions
+75
-7
TurbinePortApplicationListener.java
.../netflix/turbine/amqp/TurbinePortApplicationListener.java
+14
-5
spring.factories
...turbine-amqp/src/main/resources/META-INF/spring.factories
+2
-2
TurbinePortApplicationListenerTests.java
...lix/turbine/amqp/TurbinePortApplicationListenerTests.java
+59
-0
No files found.
spring-cloud-netflix-turbine-amqp/src/main/java/org/springframework/cloud/netflix/turbine/amqp/TurbinePort
SpringApplicationRu
nListener.java
→
spring-cloud-netflix-turbine-amqp/src/main/java/org/springframework/cloud/netflix/turbine/amqp/TurbinePort
Applicatio
nListener.java
View file @
58471753
...
...
@@ -7,7 +7,7 @@ import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEven
import
org.springframework.context.ApplicationListener
;
import
org.springframework.core.env.MapPropertySource
;
public
class
TurbinePort
SpringApplicationRu
nListener
implements
public
class
TurbinePort
Applicatio
nListener
implements
ApplicationListener
<
ApplicationEnvironmentPreparedEvent
>
{
@Override
...
...
@@ -21,11 +21,20 @@ public class TurbinePortSpringApplicationRunListener implements
if
(
serverPort
==
null
&&
managementPort
==
null
)
{
return
;
}
if
(
serverPort
!=
-
1
)
{
if
(
serverPort
!=
Integer
.
valueOf
(-
1
)
)
{
Map
<
String
,
Object
>
ports
=
new
HashMap
<
String
,
Object
>();
ports
.
put
(
"server.port"
,
-
1
);
if
(
serverPort
!=
null
&&
turbinePort
==
null
)
{
ports
.
put
(
"turbine.amqp.port"
,
serverPort
);
if
(
turbinePort
==
null
)
{
// The actual server.port used by the application forced to be -1 (no user
// endpoints) because no value was provided for turbine
ports
.
put
(
"server.port"
,
-
1
);
if
(
serverPort
!=
null
)
{
// Turbine port defaults to server port value supplied by user
ports
.
put
(
"turbine.amqp.port"
,
serverPort
);
}
}
else
if
(
managementPort
!=
null
&&
serverPort
==
null
)
{
// User wants 2 ports, but hasn't specified server.port explicitly
ports
.
put
(
"server.port"
,
managementPort
);
}
event
.
getEnvironment
().
getPropertySources
()
.
addFirst
(
new
MapPropertySource
(
"ports"
,
ports
));
...
...
spring-cloud-netflix-turbine-amqp/src/main/resources/META-INF/spring.factories
View file @
58471753
...
...
@@ -2,4 +2,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.netflix.turbine.amqp.TurbineAmqpAutoConfiguration
org.springframework.context.ApplicationListener=\
org.springframework.cloud.netflix.turbine.amqp.TurbinePortSpringApplicationRunListener
\ No newline at end of file
org.springframework.cloud.netflix.turbine.amqp.TurbinePortApplicationListener
\ No newline at end of file
spring-cloud-netflix-turbine-amqp/src/test/java/org/springframework/cloud/netflix/turbine/amqp/TurbinePortApplicationListenerTests.java
0 → 100644
View file @
58471753
package
org
.
springframework
.
cloud
.
netflix
.
turbine
.
amqp
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
public
class
TurbinePortApplicationListenerTests
{
private
TurbinePortApplicationListener
listener
=
new
TurbinePortApplicationListener
();
private
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
private
ApplicationEnvironmentPreparedEvent
event
=
new
ApplicationEnvironmentPreparedEvent
(
new
SpringApplication
(),
null
,
environment
);
@Test
public
void
noop
()
{
listener
.
onApplicationEvent
(
event
);
}
@Test
public
void
serverPortOnly
()
{
EnvironmentTestUtils
.
addEnvironment
(
environment
,
"server.port=9999"
);
listener
.
onApplicationEvent
(
event
);
assertEquals
(
"-1"
,
environment
.
resolvePlaceholders
(
"${server.port}"
));
assertEquals
(
"9999"
,
environment
.
resolvePlaceholders
(
"${turbine.amqp.port}"
));
}
@Test
public
void
turbinePortOnly
()
{
EnvironmentTestUtils
.
addEnvironment
(
environment
,
"turbine.amqp.port=9999"
);
listener
.
onApplicationEvent
(
event
);
assertEquals
(
"9999"
,
environment
.
resolvePlaceholders
(
"${turbine.amqp.port}"
));
assertEquals
(
"0"
,
environment
.
resolvePlaceholders
(
"${server.port:0}"
));
}
@Test
public
void
turbineAndManagementPorts
()
{
EnvironmentTestUtils
.
addEnvironment
(
environment
,
"turbine.amqp.port=9999"
,
"management.port=9000"
);
listener
.
onApplicationEvent
(
event
);
assertEquals
(
"9999"
,
environment
.
resolvePlaceholders
(
"${turbine.amqp.port}"
));
assertEquals
(
"9000"
,
environment
.
resolvePlaceholders
(
"${server.port:0}"
));
assertEquals
(
"9000"
,
environment
.
resolvePlaceholders
(
"${management.port:0}"
));
}
@Test
public
void
turbineAndServerPorts
()
{
EnvironmentTestUtils
.
addEnvironment
(
environment
,
"turbine.amqp.port=9999"
,
"server.port=9000"
);
listener
.
onApplicationEvent
(
event
);
assertEquals
(
"9999"
,
environment
.
resolvePlaceholders
(
"${turbine.amqp.port}"
));
assertEquals
(
"9000"
,
environment
.
resolvePlaceholders
(
"${server.port:0}"
));
assertEquals
(
"0"
,
environment
.
resolvePlaceholders
(
"${management.port:0}"
));
}
}
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