Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
c6657aaf
Commit
c6657aaf
authored
Oct 31, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7066 from youngm/pidotherevents
* pr/7066: Support ApplicationReadyEvent from PidFileWriter
parents
5a3b881e
970dcc3f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
ApplicationPidFileWriter.java
...springframework/boot/system/ApplicationPidFileWriter.java
+7
-1
ApplicationPidFileWriterTests.java
...gframework/boot/system/ApplicationPidFileWriterTests.java
+24
-1
No files found.
spring-boot/src/main/java/org/springframework/boot/system/ApplicationPidFileWriter.java
View file @
c6657aaf
...
...
@@ -30,6 +30,7 @@ import org.springframework.boot.ApplicationPid;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.event.SpringApplicationEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.core.Ordered
;
...
...
@@ -49,7 +50,8 @@ import org.springframework.util.Assert;
* <p>
* Note: access to the Spring {@link Environment} is only possible when the
* {@link #setTriggerEventType(Class) triggerEventType} is set to
* {@link ApplicationEnvironmentPreparedEvent} or {@link ApplicationPreparedEvent}.
* {@link ApplicationEnvironmentPreparedEvent}, {@link ApplicationReadyEvent}, or
* {@link ApplicationPreparedEvent}.
*
* @author Jakub Kubrynski
* @author Dave Syer
...
...
@@ -231,6 +233,10 @@ public class ApplicationPidFileWriter
return
((
ApplicationPreparedEvent
)
event
).
getApplicationContext
()
.
getEnvironment
();
}
if
(
event
instanceof
ApplicationReadyEvent
)
{
return
((
ApplicationReadyEvent
)
event
).
getApplicationContext
()
.
getEnvironment
();
}
return
null
;
}
...
...
spring-boot/src/test/java/org/springframework/boot/system/ApplicationPidFileWriterTests.java
View file @
c6657aaf
...
...
@@ -29,6 +29,7 @@ import org.junit.rules.TemporaryFolder;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.event.ApplicationStartedEvent
;
import
org.springframework.boot.context.event.SpringApplicationEvent
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -99,7 +100,7 @@ public class ApplicationPidFileWriterTests {
}
@Test
public
void
differentEventTypes
()
throws
Exception
{
public
void
tryEnvironmentPreparedEvent
()
throws
Exception
{
File
file
=
this
.
temporaryFolder
.
newFile
();
SpringApplicationEvent
event
=
createEnvironmentPreparedEvent
(
"spring.pid.file"
,
file
.
getAbsolutePath
());
...
...
@@ -111,6 +112,19 @@ public class ApplicationPidFileWriterTests {
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))).
isNotEmpty
();
}
@Test
public
void
tryReadyEvent
()
throws
Exception
{
File
file
=
this
.
temporaryFolder
.
newFile
();
SpringApplicationEvent
event
=
createReadyEvent
(
"spring.pid.file"
,
file
.
getAbsolutePath
());
ApplicationPidFileWriter
listener
=
new
ApplicationPidFileWriter
();
listener
.
onApplicationEvent
(
event
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))).
isEmpty
();
listener
.
setTriggerEventType
(
ApplicationReadyEvent
.
class
);
listener
.
onApplicationEvent
(
event
);
assertThat
(
FileCopyUtils
.
copyToString
(
new
FileReader
(
file
))).
isNotEmpty
();
}
@Test
public
void
withNoEnvironment
()
throws
Exception
{
File
file
=
this
.
temporaryFolder
.
newFile
();
...
...
@@ -170,6 +184,15 @@ public class ApplicationPidFileWriterTests {
context
);
}
private
SpringApplicationEvent
createReadyEvent
(
String
propName
,
String
propValue
)
{
ConfigurableEnvironment
environment
=
createEnvironment
(
propName
,
propValue
);
ConfigurableApplicationContext
context
=
mock
(
ConfigurableApplicationContext
.
class
);
given
(
context
.
getEnvironment
()).
willReturn
(
environment
);
return
new
ApplicationReadyEvent
(
new
SpringApplication
(),
new
String
[]
{},
context
);
}
private
ConfigurableEnvironment
createEnvironment
(
String
propName
,
String
propValue
)
{
MockPropertySource
propertySource
=
mockPropertySource
(
propName
,
propValue
);
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
...
...
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