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
75b1be53
Commit
75b1be53
authored
Dec 29, 2017
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use java8 Duration for intervals, timeouts, ...
parent
0b1dde1c
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
79 additions
and
86 deletions
+79
-86
AdminServerProperties.java
...ntric/boot/admin/server/config/AdminServerProperties.java
+9
-37
FilteringNotifier.java
...ic/boot/admin/server/notify/filter/FilteringNotifier.java
+4
-3
StatusUpdateTrigger.java
...ntric/boot/admin/server/services/StatusUpdateTrigger.java
+7
-7
InstanceWebClient.java
...ntric/boot/admin/server/web/client/InstanceWebClient.java
+7
-5
FilteringNotifierTest.java
...oot/admin/server/notify/filter/FilteringNotifierTest.java
+3
-2
InfoUpdaterTest.java
...decentric/boot/admin/server/services/InfoUpdaterTest.java
+2
-1
StatusUpdateTriggerTest.java
...c/boot/admin/server/services/StatusUpdateTriggerTest.java
+5
-4
InstanceWebClientTest.java
...c/boot/admin/server/web/client/InstanceWebClientTest.java
+3
-1
ClientProperties.java
...odecentric/boot/admin/client/config/ClientProperties.java
+6
-5
SpringBootAdminClientAutoConfiguration.java
...client/config/SpringBootAdminClientAutoConfiguration.java
+2
-2
DefaultApplicationFactory.java
.../admin/client/registration/DefaultApplicationFactory.java
+0
-5
RegistrationApplicationListener.java
.../client/registration/RegistrationApplicationListener.java
+3
-2
ServletApplicationFactory.java
.../admin/client/registration/ServletApplicationFactory.java
+15
-0
RegistrationApplicationListenerTest.java
...ent/registration/RegistrationApplicationListenerTest.java
+13
-12
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/config/AdminServerProperties.java
View file @
75b1be53
...
...
@@ -16,8 +16,10 @@
package
de
.
codecentric
.
boot
.
admin
.
server
.
config
;
import
java.time.Duration
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
@lombok
.
Data
@ConfigurationProperties
(
"spring.boot.admin"
)
public
class
AdminServerProperties
{
/**
...
...
@@ -59,58 +61,28 @@ public class AdminServerProperties {
this
.
probedEndpoints
=
probedEndpoints
;
}
@lombok
.
Data
public
static
class
MonitorProperties
{
/**
* Time interval
in ms
to update the status of instances with expired statusInfo
* Time interval to update the status of instances with expired statusInfo
*/
private
long
period
=
10_000L
;
private
Duration
period
=
Duration
.
ofSeconds
(
10
)
;
/**
* Lifetime of status
in ms
. The status won't be updated as long the last status isn't
* Lifetime of status. The status won't be updated as long the last status isn't
* expired.
*/
private
long
statusLifetime
=
10_000L
;
private
Duration
statusLifetime
=
Duration
.
ofSeconds
(
10
)
;
/**
* Connect timeout when querying the instances' status and info.
*/
private
int
connectTimeout
=
2_000
;
private
Duration
connectTimeout
=
Duration
.
ofSeconds
(
2
)
;
/**
* read timeout when querying the instances' status and info.
*/
private
int
readTimeout
=
5_000
;
private
Duration
readTimeout
=
Duration
.
ofSeconds
(
5
)
;
public
void
setPeriod
(
long
period
)
{
this
.
period
=
period
;
}
public
long
getPeriod
()
{
return
period
;
}
public
void
setStatusLifetime
(
long
statusLifetime
)
{
this
.
statusLifetime
=
statusLifetime
;
}
public
long
getStatusLifetime
()
{
return
statusLifetime
;
}
public
int
getConnectTimeout
()
{
return
connectTimeout
;
}
public
void
setConnectTimeout
(
int
connectTimeout
)
{
this
.
connectTimeout
=
connectTimeout
;
}
public
int
getReadTimeout
()
{
return
readTimeout
;
}
public
void
setReadTimeout
(
int
readTimeout
)
{
this
.
readTimeout
=
readTimeout
;
}
}
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/notify/filter/FilteringNotifier.java
View file @
75b1be53
...
...
@@ -22,6 +22,7 @@ import de.codecentric.boot.admin.server.notify.AbstractEventNotifier;
import
de.codecentric.boot.admin.server.notify.Notifier
;
import
reactor.core.publisher.Mono
;
import
java.time.Duration
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -43,7 +44,7 @@ public class FilteringNotifier extends AbstractEventNotifier {
private
final
ConcurrentMap
<
String
,
NotificationFilter
>
filters
=
new
ConcurrentHashMap
<>();
private
final
Notifier
delegate
;
private
long
lastCleanup
;
private
long
cleanupInterval
=
10_000L
;
private
Duration
cleanupInterval
=
Duration
.
ofSeconds
(
10
)
;
private
AtomicLong
counter
=
new
AtomicLong
();
public
FilteringNotifier
(
Notifier
delegate
,
InstanceRepository
repository
)
{
...
...
@@ -79,7 +80,7 @@ public class FilteringNotifier extends AbstractEventNotifier {
private
void
cleanUp
()
{
long
now
=
System
.
currentTimeMillis
();
if
(
lastCleanup
+
cleanupInterval
>
now
)
{
if
(
lastCleanup
+
cleanupInterval
.
toMillis
()
>
now
)
{
return
;
}
lastCleanup
=
now
;
...
...
@@ -110,7 +111,7 @@ public class FilteringNotifier extends AbstractEventNotifier {
}
}
public
void
setCleanupInterval
(
long
cleanupInterval
)
{
public
void
setCleanupInterval
(
Duration
cleanupInterval
)
{
this
.
cleanupInterval
=
cleanupInterval
;
}
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/StatusUpdateTrigger.java
View file @
75b1be53
...
...
@@ -37,8 +37,8 @@ public class StatusUpdateTrigger extends ResubscribingEventHandler<InstanceRegis
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
StatusUpdateTrigger
.
class
);
private
final
StatusUpdater
statusUpdater
;
private
Map
<
InstanceId
,
Long
>
lastQueried
=
new
HashMap
<>();
private
long
updateInterval
=
10_000L
;
private
long
statusLifetime
=
10_000L
;
private
Duration
updateInterval
=
Duration
.
ofSeconds
(
10
)
;
private
Duration
statusLifetime
=
Duration
.
ofSeconds
(
10
)
;
private
Disposable
intervalSubscription
;
...
...
@@ -50,8 +50,8 @@ public class StatusUpdateTrigger extends ResubscribingEventHandler<InstanceRegis
@Override
public
void
start
()
{
super
.
start
();
intervalSubscription
=
Flux
.
interval
(
Duration
.
ofMillis
(
updateInterval
)
)
.
doOnSubscribe
(
subscription
->
log
.
debug
(
"Scheduled status update every {}
ms
"
,
intervalSubscription
=
Flux
.
interval
(
updateInterval
)
.
doOnSubscribe
(
subscription
->
log
.
debug
(
"Scheduled status update every {}"
,
updateInterval
))
.
log
(
log
.
getName
(),
Level
.
FINEST
)
.
subscribeOn
(
Schedulers
.
newSingle
(
"status-monitor"
))
...
...
@@ -79,7 +79,7 @@ public class StatusUpdateTrigger extends ResubscribingEventHandler<InstanceRegis
protected
Mono
<
Void
>
updateStatusForAllInstances
()
{
log
.
debug
(
"Updating status for all instances"
);
long
expiryInstant
=
System
.
currentTimeMillis
()
-
statusLifetime
;
long
expiryInstant
=
System
.
currentTimeMillis
()
-
statusLifetime
.
toMillis
()
;
return
Flux
.
fromIterable
(
lastQueried
.
entrySet
())
.
filter
(
e
->
e
.
getValue
()
<
expiryInstant
)
.
map
(
Map
.
Entry
::
getKey
)
...
...
@@ -92,11 +92,11 @@ public class StatusUpdateTrigger extends ResubscribingEventHandler<InstanceRegis
.
doFinally
((
s
)
->
lastQueried
.
put
(
instanceId
,
System
.
currentTimeMillis
()));
}
public
void
setUpdateInterval
(
long
updateInterval
)
{
public
void
setUpdateInterval
(
Duration
updateInterval
)
{
this
.
updateInterval
=
updateInterval
;
}
public
void
setStatusLifetime
(
long
statusLifetime
)
{
public
void
setStatusLifetime
(
Duration
statusLifetime
)
{
this
.
statusLifetime
=
statusLifetime
;
}
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/web/client/InstanceWebClient.java
View file @
75b1be53
...
...
@@ -21,6 +21,7 @@ import io.netty.channel.ChannelOption;
import
io.netty.handler.timeout.ReadTimeoutHandler
;
import
reactor.core.publisher.Mono
;
import
java.time.Duration
;
import
java.util.concurrent.TimeUnit
;
import
org.springframework.boot.actuate.endpoint.http.ActuatorMediaType
;
import
org.springframework.http.HttpHeaders
;
...
...
@@ -32,10 +33,10 @@ public class InstanceWebClient {
private
final
WebClient
webClient
;
public
InstanceWebClient
(
HttpHeadersProvider
httpHeadersProvider
)
{
this
(
httpHeadersProvider
,
2000
,
5000
);
this
(
httpHeadersProvider
,
Duration
.
ofSeconds
(
2
),
Duration
.
ofSeconds
(
5
)
);
}
public
InstanceWebClient
(
HttpHeadersProvider
httpHeadersProvider
,
int
connectTimeout
,
int
readTimeout
)
{
public
InstanceWebClient
(
HttpHeadersProvider
httpHeadersProvider
,
Duration
connectTimeout
,
Duration
readTimeout
)
{
this
(
createDefaultWebClient
(
connectTimeout
,
readTimeout
),
httpHeadersProvider
);
}
...
...
@@ -61,12 +62,13 @@ public class InstanceWebClient {
.
build
();
}
private
static
WebClient
createDefaultWebClient
(
int
connectTimeout
,
int
readTimeout
)
{
private
static
WebClient
createDefaultWebClient
(
Duration
connectTimeout
,
Duration
readTimeout
)
{
ReactorClientHttpConnector
connector
=
new
ReactorClientHttpConnector
(
options
->
options
.
option
(
ChannelOption
.
CONNECT_TIMEOUT_MILLIS
,
connectTimeout
)
//
options
->
options
.
option
(
ChannelOption
.
CONNECT_TIMEOUT_MILLIS
,
(
int
)
connectTimeout
.
toMillis
()
)
//
.
compression
(
true
)
//
.
afterNettyContextInit
(
ctx
->
{
ctx
.
addHandlerLast
(
new
ReadTimeoutHandler
(
readTimeout
,
TimeUnit
.
MILLISECONDS
));
ctx
.
addHandlerLast
(
new
ReadTimeoutHandler
(
readTimeout
.
toMillis
(),
TimeUnit
.
MILLISECONDS
));
}));
return
WebClient
.
builder
()
.
clientConnector
(
connector
)
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/notify/filter/FilteringNotifierTest.java
View file @
75b1be53
...
...
@@ -25,6 +25,7 @@ import de.codecentric.boot.admin.server.notify.TestNotifier;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
import
java.time.Duration
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -40,7 +41,7 @@ public class FilteringNotifierTest {
private
InstanceRepository
repository
;
@Before
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
{
repository
=
mock
(
InstanceRepository
.
class
);
when
(
repository
.
find
(
instance
.
getId
())).
thenReturn
(
Mono
.
just
(
instance
));
}
...
...
@@ -53,7 +54,7 @@ public class FilteringNotifierTest {
@Test
public
void
test_expired_removal
()
{
FilteringNotifier
notifier
=
new
FilteringNotifier
(
new
TestNotifier
(),
repository
);
notifier
.
setCleanupInterval
(
0L
);
notifier
.
setCleanupInterval
(
Duration
.
ZERO
);
String
id1
=
notifier
.
addFilter
(
new
ApplicationNameNotificationFilter
(
"foo"
,
0L
));
String
id2
=
notifier
.
addFilter
(
new
ApplicationNameNotificationFilter
(
"bar"
,
-
1L
));
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/InfoUpdaterTest.java
View file @
75b1be53
...
...
@@ -62,7 +62,8 @@ public class InfoUpdaterTest {
repository
=
new
EventSourcingInstanceRepository
(
eventStore
);
repository
.
start
();
InstanceWebClient
instanceWebClient
=
new
InstanceWebClient
(
mock
(
HttpHeadersProvider
.
class
,
invocation
->
HttpHeaders
.
EMPTY
),
1000
,
1000
);
mock
(
HttpHeadersProvider
.
class
,
invocation
->
HttpHeaders
.
EMPTY
),
Duration
.
ofSeconds
(
1
),
Duration
.
ofSeconds
(
1
));
updater
=
new
InfoUpdater
(
repository
,
instanceWebClient
);
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/StatusUpdateTriggerTest.java
View file @
75b1be53
...
...
@@ -26,6 +26,7 @@ import de.codecentric.boot.admin.server.domain.values.Registration;
import
reactor.core.publisher.Mono
;
import
reactor.test.publisher.TestPublisher
;
import
java.time.Duration
;
import
org.junit.Test
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
...
@@ -49,8 +50,8 @@ public class StatusUpdateTriggerTest {
TestPublisher
<
InstanceEvent
>
publisher
=
TestPublisher
.
create
();
StatusUpdateTrigger
trigger
=
new
StatusUpdateTrigger
(
updater
,
publisher
);
trigger
.
setUpdateInterval
(
10L
);
trigger
.
setStatusLifetime
(
10L
);
trigger
.
setUpdateInterval
(
Duration
.
ofMillis
(
10
)
);
trigger
.
setStatusLifetime
(
Duration
.
ofMillis
(
10
)
);
//when trigger is initialized and an appliation is registered
trigger
.
start
();
...
...
@@ -62,7 +63,7 @@ public class StatusUpdateTriggerTest {
verify
(
updater
,
atLeast
(
2
)).
updateStatus
(
instance
.
getId
());
//given long lifetime
trigger
.
setStatusLifetime
(
10_000L
);
trigger
.
setStatusLifetime
(
Duration
.
ofSeconds
(
10
)
);
Thread
.
sleep
(
50L
);
clearInvocations
(
updater
);
//when the lifetime is not expired
...
...
@@ -71,7 +72,7 @@ public class StatusUpdateTriggerTest {
verify
(
updater
,
never
()).
updateStatus
(
any
(
InstanceId
.
class
));
//when trigger ist destroyed
trigger
.
setStatusLifetime
(
10L
);
trigger
.
setStatusLifetime
(
Duration
.
ofMillis
(
10
)
);
trigger
.
stop
();
clearInvocations
(
updater
);
Thread
.
sleep
(
15L
);
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/web/client/InstanceWebClientTest.java
View file @
75b1be53
...
...
@@ -23,6 +23,7 @@ import io.netty.handler.timeout.ReadTimeoutException;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
import
java.time.Duration
;
import
java.util.OptionalLong
;
import
org.junit.ClassRule
;
import
org.junit.Rule
;
...
...
@@ -58,7 +59,8 @@ public class InstanceWebClientTest {
public
WireMockClassRule
wireMock
=
wireMockClassRule
;
private
final
HttpHeadersProvider
headersProvider
=
mock
(
HttpHeadersProvider
.
class
,
invocation
->
EMPTY
);
private
InstanceWebClient
instanceWebClient
=
new
InstanceWebClient
(
headersProvider
,
1000
,
1000
);
private
InstanceWebClient
instanceWebClient
=
new
InstanceWebClient
(
headersProvider
,
Duration
.
ofSeconds
(
1
),
Duration
.
ofSeconds
(
1
));
@Test
public
void
should_rewirte_url
()
{
...
...
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/client/config/ClientProperties.java
View file @
75b1be53
...
...
@@ -15,6 +15,7 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
client
.
config
;
import
java.time.Duration
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
@lombok
.
Data
...
...
@@ -32,19 +33,19 @@ public class ClientProperties {
private
String
apiPath
=
"instances"
;
/**
* Time interval
(in ms)
the registration is repeated
* Time interval the registration is repeated
*/
private
long
period
=
10_000L
;
private
Duration
period
=
Duration
.
ofSeconds
(
10
)
;
/**
* Connect timeout
(in ms)
for the registration.
* Connect timeout for the registration.
*/
private
int
connectTimeout
=
5_000
;
private
Duration
connectTimeout
=
Duration
.
ofSeconds
(
5
)
;
/**
* Read timeout (in ms) for the registration.
*/
private
int
readTimeout
=
5_000
;
private
Duration
readTimeout
=
Duration
.
ofSeconds
(
5
)
;
/**
* Username for basic authentication on admin server
...
...
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/client/config/SpringBootAdminClientAutoConfiguration.java
View file @
75b1be53
...
...
@@ -87,8 +87,8 @@ public class SpringBootAdminClientAutoConfiguration {
RestTemplateBuilder
restTemplBuilder
)
{
RestTemplateBuilder
builder
=
restTemplBuilder
.
messageConverters
(
new
MappingJackson2HttpMessageConverter
())
.
requestFactory
(
SimpleClientHttpRequestFactory
.
class
)
.
setConnectTimeout
(
client
.
getConnectTimeout
())
.
setReadTimeout
(
client
.
getReadTimeout
());
.
setConnectTimeout
(
(
int
)
client
.
getConnectTimeout
().
toMillis
())
.
setReadTimeout
(
(
int
)
client
.
getReadTimeout
().
toMillis
());
if
(
client
.
getUsername
()
!=
null
)
{
builder
=
builder
.
basicAuthorization
(
client
.
getUsername
(),
client
.
getPassword
());
}
...
...
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/client/registration/DefaultApplicationFactory.java
View file @
75b1be53
...
...
@@ -107,7 +107,6 @@ public class DefaultApplicationFactory implements ApplicationFactory {
return
UriComponentsBuilder
.
fromUriString
(
getManagementBaseUrl
())
.
path
(
"/"
)
.
path
(
getManagementContextPath
())
.
path
(
getEndpointsWebPath
())
.
toUriString
();
}
...
...
@@ -142,10 +141,6 @@ public class DefaultApplicationFactory implements ApplicationFactory {
return
getLocalManagementPort
()
==
null
||
getLocalManagementPort
().
equals
(
getLocalServerPort
());
}
protected
String
getManagementContextPath
()
{
return
management
.
getContextPath
();
}
protected
String
getEndpointsWebPath
()
{
return
webEndpoint
.
getBasePath
();
}
...
...
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/client/registration/RegistrationApplicationListener.java
View file @
75b1be53
...
...
@@ -15,6 +15,7 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
;
import
java.time.Duration
;
import
java.util.concurrent.ScheduledFuture
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -37,7 +38,7 @@ public class RegistrationApplicationListener {
private
final
TaskScheduler
taskScheduler
;
private
boolean
autoDeregister
=
false
;
private
boolean
autoRegister
=
true
;
private
long
registerPeriod
=
10_000L
;
private
Duration
registerPeriod
=
Duration
.
ofSeconds
(
10
)
;
private
volatile
ScheduledFuture
<?>
scheduledTask
;
public
RegistrationApplicationListener
(
ApplicationRegistrator
registrator
,
TaskScheduler
taskScheduler
)
{
...
...
@@ -89,7 +90,7 @@ public class RegistrationApplicationListener {
this
.
autoRegister
=
autoRegister
;
}
public
void
setRegisterPeriod
(
long
registerPeriod
)
{
public
void
setRegisterPeriod
(
Duration
registerPeriod
)
{
this
.
registerPeriod
=
registerPeriod
;
}
}
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/client/registration/ServletApplicationFactory.java
View file @
75b1be53
...
...
@@ -23,10 +23,12 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathP
import
org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
;
import
org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.web.util.UriComponentsBuilder
;
public
class
ServletApplicationFactory
extends
DefaultApplicationFactory
{
private
final
ServletContext
servletContext
;
private
final
ServerProperties
.
Servlet
servlet
;
private
final
ManagementServerProperties
.
Servlet
managementServlet
;
public
ServletApplicationFactory
(
InstanceProperties
instance
,
ManagementServerProperties
management
,
...
...
@@ -37,6 +39,19 @@ public class ServletApplicationFactory extends DefaultApplicationFactory {
super
(
instance
,
management
,
server
,
endpointPathProvider
,
webEndpoint
);
this
.
servletContext
=
servletContext
;
this
.
servlet
=
server
.
getServlet
();
this
.
managementServlet
=
management
.
getServlet
();
}
@Override
protected
String
getManagementBaseUrl
()
{
return
UriComponentsBuilder
.
fromHttpUrl
(
super
.
getManagementBaseUrl
())
.
path
(
"/"
)
.
path
(
getManagementContextPath
())
.
toUriString
();
}
protected
String
getManagementContextPath
()
{
return
managementServlet
.
getContextPath
();
}
@Override
...
...
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/client/registration/RegistrationApplicationListenerTest.java
View file @
75b1be53
...
...
@@ -16,6 +16,7 @@
package
de
.
codecentric
.
boot
.
admin
.
client
.
registration
;
import
java.time.Duration
;
import
java.util.concurrent.ScheduledFuture
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
...
...
@@ -35,7 +36,7 @@ import static org.mockito.Mockito.when;
public
class
RegistrationApplicationListenerTest
{
@Test
public
void
test_register
()
throws
Exception
{
public
void
test_register
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
TaskScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
...
...
@@ -43,11 +44,11 @@ public class RegistrationApplicationListenerTest {
listener
.
onApplicationReady
(
new
ApplicationReadyEvent
(
mock
(
SpringApplication
.
class
),
null
,
mock
(
ConfigurableWebApplicationContext
.
class
)));
verify
(
scheduler
).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
10_000L
));
verify
(
scheduler
).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
Duration
.
ofSeconds
(
10
)
));
}
@Test
public
void
test_no_register
()
throws
Exception
{
public
void
test_no_register
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
TaskScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
...
...
@@ -56,23 +57,23 @@ public class RegistrationApplicationListenerTest {
listener
.
onApplicationReady
(
new
ApplicationReadyEvent
(
mock
(
SpringApplication
.
class
),
null
,
mock
(
ConfigurableWebApplicationContext
.
class
)));
verify
(
scheduler
,
never
()).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
10_000L
));
verify
(
scheduler
,
never
()).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
Duration
.
ofSeconds
(
10
)
));
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
@Test
public
void
test_no_register_after_close
()
throws
Exception
{
public
void
test_no_register_after_close
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
TaskScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
ScheduledFuture
task
=
mock
(
ScheduledFuture
.
class
);
when
(
scheduler
.
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
10_000L
))).
thenReturn
(
task
);
when
(
scheduler
.
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
Duration
.
ofSeconds
(
10
)
))).
thenReturn
(
task
);
listener
.
onApplicationReady
(
new
ApplicationReadyEvent
(
mock
(
SpringApplication
.
class
),
null
,
mock
(
ConfigurableWebApplicationContext
.
class
)));
verify
(
scheduler
).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
10_000L
));
verify
(
scheduler
).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
Duration
.
ofSeconds
(
10
)
));
listener
.
onClosedContext
(
new
ContextClosedEvent
(
mock
(
WebApplicationContext
.
class
)));
verify
(
task
).
cancel
(
true
);
...
...
@@ -80,23 +81,23 @@ public class RegistrationApplicationListenerTest {
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
@Test
public
void
test_start_stop
()
throws
Exception
{
public
void
test_start_stop
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
TaskScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
ScheduledFuture
task
=
mock
(
ScheduledFuture
.
class
);
when
(
scheduler
.
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
10_000L
))).
thenReturn
(
task
);
when
(
scheduler
.
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
Duration
.
ofSeconds
(
10
)
))).
thenReturn
(
task
);
listener
.
startRegisterTask
();
verify
(
scheduler
).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
10_000L
));
verify
(
scheduler
).
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
eq
(
Duration
.
ofSeconds
(
10
)
));
listener
.
stopRegisterTask
();
verify
(
task
).
cancel
(
true
);
}
@Test
public
void
test_no_deregister
()
throws
Exception
{
public
void
test_no_deregister
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
TaskScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
...
...
@@ -107,7 +108,7 @@ public class RegistrationApplicationListenerTest {
}
@Test
public
void
test_deregister
()
throws
Exception
{
public
void
test_deregister
()
{
ApplicationRegistrator
registrator
=
mock
(
ApplicationRegistrator
.
class
);
TaskScheduler
scheduler
=
mock
(
TaskScheduler
.
class
);
RegistrationApplicationListener
listener
=
new
RegistrationApplicationListener
(
registrator
,
scheduler
);
...
...
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