diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2018-01-29 14:54:04 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2018-01-29 14:58:37 +0100 |
commit | 7af5ec2c5ecbb9d742fc162d19850f3583bbafc1 (patch) | |
tree | ad664b83f8b698c3fa617ed55dcd221c0ff53840 /container-core/src/main | |
parent | c90710ca371546d34023470f08929b4cd73b5ff9 (diff) |
Don't run snapshot thread in StateHandlerTest
Make ThreadFactory configurable in StateMonitor to enable
StateHandlerTest to control the snapshot thread (in this case stop it
from running).
Diffstat (limited to 'container-core/src/main')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java index 6ccd25ad6c7..a5be5cb0b0a 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java @@ -11,6 +11,7 @@ import com.yahoo.log.LogLevel; import java.util.Map; import java.util.TreeSet; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -38,12 +39,19 @@ public class StateMonitor extends AbstractComponent { @Inject public StateMonitor(HealthMonitorConfig config, Timer timer) { + this(config, timer, runnable -> { + Thread thread = new Thread(runnable, "StateMonitor"); + thread.setDaemon(true); + return thread; + }); + } + + StateMonitor(HealthMonitorConfig config, Timer timer, ThreadFactory threadFactory) { this.timer = timer; this.snapshotIntervalMs = (long)(config.snapshot_interval() * TimeUnit.SECONDS.toMillis(1)); this.lastSnapshotTimeMs = timer.currentTimeMillis(); this.status = Status.valueOf(config.initialStatus()); - thread = new Thread(StateMonitor.this::run, "StateMonitor"); - thread.setDaemon(true); + thread = threadFactory.newThread(this::run); thread.start(); } @@ -69,6 +77,7 @@ public class StateMonitor extends AbstractComponent { /** Returns the interval between each metrics snapshot used by this */ public long getSnapshotIntervalMillis() { return snapshotIntervalMs; } + /** NOTE: For unit testing only. May lead to undefined behaviour if StateMonitor thread is running simultaneously **/ boolean checkTime() { long now = timer.currentTimeMillis(); if (now < lastSnapshotTimeMs + snapshotIntervalMs) { |