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
c974de01
Commit
c974de01
authored
Jul 11, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x
parents
277da462
5f751fe3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
9 deletions
+29
-9
ShutdownEndpoint.java
...ringframework/boot/actuate/endpoint/ShutdownEndpoint.java
+5
-4
ShutdownEndpointTests.java
...ramework/boot/actuate/endpoint/ShutdownEndpointTests.java
+24
-5
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ShutdownEndpoint.java
View file @
c974de01
...
...
@@ -30,6 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
*
* @author Dave Syer
* @author Christian Dupuis
* @author Andy Wilkinson
*/
@ConfigurationProperties
(
prefix
=
"endpoints.shutdown"
)
public
class
ShutdownEndpoint
extends
AbstractEndpoint
<
Map
<
String
,
Object
>>
...
...
@@ -61,8 +62,7 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>>
return
SHUTDOWN_MESSAGE
;
}
finally
{
new
Thread
(
new
Runnable
()
{
Thread
thread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
...
...
@@ -73,8 +73,9 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>>
}
ShutdownEndpoint
.
this
.
context
.
close
();
}
}).
start
();
});
thread
.
setContextClassLoader
(
getClass
().
getClassLoader
());
thread
.
start
();
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java
View file @
c974de01
...
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.Map
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -34,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
* @author Dave Syer
* @author Andy Wilkinson
*/
public
class
ShutdownEndpointTests
extends
AbstractEndpointTests
<
ShutdownEndpoint
>
{
...
...
@@ -50,18 +54,31 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
@Test
public
void
invoke
()
throws
Exception
{
CountDownLatch
latch
=
this
.
context
.
getBean
(
Config
.
class
).
latch
;
assertThat
((
String
)
getEndpointBean
().
invoke
().
get
(
"message"
))
.
startsWith
(
"Shutting down"
);
Config
config
=
this
.
context
.
getBean
(
Config
.
class
);
ClassLoader
previousTccl
=
Thread
.
currentThread
().
getContextClassLoader
();
Map
<
String
,
Object
>
result
;
Thread
.
currentThread
().
setContextClassLoader
(
new
URLClassLoader
(
new
URL
[
0
],
getClass
().
getClassLoader
()));
try
{
result
=
getEndpointBean
().
invoke
();
}
finally
{
Thread
.
currentThread
().
setContextClassLoader
(
previousTccl
);
}
assertThat
((
String
)
result
.
get
(
"message"
)).
startsWith
(
"Shutting down"
);
assertThat
(
this
.
context
.
isActive
()).
isTrue
();
assertThat
(
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)).
isTrue
();
assertThat
(
config
.
latch
.
await
(
10
,
TimeUnit
.
SECONDS
)).
isTrue
();
assertThat
(
config
.
threadContextClassLoader
)
.
isEqualTo
(
getClass
().
getClassLoader
());
}
@Configuration
@EnableConfigurationProperties
public
static
class
Config
{
private
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
volatile
ClassLoader
threadContextClassLoader
;
@Bean
public
ShutdownEndpoint
endpoint
()
{
...
...
@@ -75,6 +92,8 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
@Override
public
void
onApplicationEvent
(
ContextClosedEvent
event
)
{
Config
.
this
.
threadContextClassLoader
=
Thread
.
currentThread
()
.
getContextClassLoader
();
Config
.
this
.
latch
.
countDown
();
}
...
...
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