Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
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-boot-admin
Commits
ba7cc524
Commit
ba7cc524
authored
May 18, 2018
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deregister when the context has a parent bootstrap context
fixes #738
parent
92a3442d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
RegistrationApplicationListener.java
.../client/registration/RegistrationApplicationListener.java
+2
-1
RegistrationApplicationListenerTest.java
...ent/registration/RegistrationApplicationListenerTest.java
+32
-1
No files found.
spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/registration/RegistrationApplicationListener.java
View file @
ba7cc524
...
@@ -72,7 +72,8 @@ public class RegistrationApplicationListener implements InitializingBean, Dispos
...
@@ -72,7 +72,8 @@ public class RegistrationApplicationListener implements InitializingBean, Dispos
@EventListener
@EventListener
@Order
(
Ordered
.
LOWEST_PRECEDENCE
)
@Order
(
Ordered
.
LOWEST_PRECEDENCE
)
public
void
onClosedContext
(
ContextClosedEvent
event
)
{
public
void
onClosedContext
(
ContextClosedEvent
event
)
{
if
(
event
.
getApplicationContext
().
getParent
()
==
null
)
{
if
(
event
.
getApplicationContext
().
getParent
()
==
null
||
"bootstrap"
.
equals
(
event
.
getApplicationContext
().
getParent
().
getId
()))
{
stopRegisterTask
();
stopRegisterTask
();
if
(
autoDeregister
)
{
if
(
autoDeregister
)
{
...
...
spring-boot-admin-client/src/test/java/de/codecentric/boot/admin/client/registration/RegistrationApplicationListenerTest.java
View file @
ba7cc524
...
@@ -21,6 +21,7 @@ import java.util.concurrent.ScheduledFuture;
...
@@ -21,6 +21,7 @@ import java.util.concurrent.ScheduledFuture;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
;
import
org.springframework.web.context.ConfigurableWebApplicationContext
;
import
org.springframework.web.context.ConfigurableWebApplicationContext
;
...
@@ -112,12 +113,42 @@ public class RegistrationApplicationListenerTest {
...
@@ -112,12 +113,42 @@ public class RegistrationApplicationListenerTest {
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
listener
.
setAutoDeregister
(
true
);
listener
.
setAutoDeregister
(
true
);
listener
.
onClosedContext
(
new
ContextClosedEvent
(
mock
(
WebApplicationContext
.
class
)));
listener
.
onClosedContext
(
new
ContextClosedEvent
(
mock
(
ApplicationContext
.
class
)));
verify
(
registrator
).
deregister
();
}
@Test
public
void
should_deregister_when_autoDeregister_and_parent_is_bootstrap_contex
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ThreadPoolTaskScheduler
scheduler
=
mock
(
ThreadPoolTaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
listener
.
setAutoDeregister
(
true
);
ApplicationContext
parentContext
=
mock
(
ApplicationContext
.
class
);
when
(
parentContext
.
getId
()).
thenReturn
(
"bootstrap"
);
ApplicationContext
mockContext
=
mock
(
ApplicationContext
.
class
);
when
(
mockContext
.
getParent
()).
thenReturn
(
parentContext
);
listener
.
onClosedContext
(
new
ContextClosedEvent
(
mockContext
));
verify
(
registrator
).
deregister
();
verify
(
registrator
).
deregister
();
}
}
@Test
@Test
public
void
should_not_deregister_when_autoDeregister_and_not_root
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ThreadPoolTaskScheduler
scheduler
=
mock
(
ThreadPoolTaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
listener
.
setAutoDeregister
(
true
);
ApplicationContext
mockContext
=
mock
(
ApplicationContext
.
class
);
when
(
mockContext
.
getParent
()).
thenReturn
(
mock
(
ApplicationContext
.
class
));
listener
.
onClosedContext
(
new
ContextClosedEvent
(
mockContext
));
verify
(
registrator
,
never
()).
deregister
();
}
@Test
public
void
should_init_and_shutdown_taskScheduler
()
{
public
void
should_init_and_shutdown_taskScheduler
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
ThreadPoolTaskScheduler
scheduler
=
mock
(
ThreadPoolTaskScheduler
.
class
);
ThreadPoolTaskScheduler
scheduler
=
mock
(
ThreadPoolTaskScheduler
.
class
);
...
...
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