diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-19 10:20:21 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-12-19 10:20:21 +0000 |
commit | 0c73d159fb48cea0bf2d1dc62708aff09c82cf99 (patch) | |
tree | fb8834ed860d4b130033e46a978d780a19015b23 /container-search/src | |
parent | ae0f989de2585ed10b751ce3340a43fe24c2ef88 (diff) |
Avoid starting the ping thread automatically for tests.
Diffstat (limited to 'container-search/src')
3 files changed, 18 insertions, 4 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/cluster/ClusterMonitor.java b/container-search/src/main/java/com/yahoo/search/cluster/ClusterMonitor.java index 2aa896948a1..d4b6279be89 100644 --- a/container-search/src/main/java/com/yahoo/search/cluster/ClusterMonitor.java +++ b/container-search/src/main/java/com/yahoo/search/cluster/ClusterMonitor.java @@ -39,9 +39,15 @@ public class ClusterMonitor<T> { private final Map<T, TrafficNodeMonitor<T>> nodeMonitors = Collections.synchronizedMap(new java.util.LinkedHashMap<>()); public ClusterMonitor(NodeManager<T> manager) { + this(manager, true); + } + + public ClusterMonitor(NodeManager<T> manager, boolean startPingThread) { nodeManager = manager; monitorThread = new MonitorThread("search.clustermonitor"); - monitorThread.start(); + if (startPingThread) { + monitorThread.start(); + } } /** Returns the configuration of this cluster monitor */ @@ -121,7 +127,9 @@ public class ClusterMonitor<T> { nodeManager.notifyAll(); } try { - monitorThread.join(); + if (monitorThread.isAlive()) { + monitorThread.join(); + } } catch (InterruptedException e) {} } diff --git a/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java index dd8b953e3d0..06cbf9a9706 100644 --- a/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java @@ -41,7 +41,7 @@ import java.util.concurrent.TimeoutException; public abstract class ClusterSearcher<T> extends PingableSearcher implements NodeManager<T> { private final Hasher<T> hasher; - private final ClusterMonitor<T> monitor = new ClusterMonitor<>(this); + private final ClusterMonitor<T> monitor; /** * Creates a new cluster searcher @@ -55,8 +55,13 @@ public abstract class ClusterSearcher<T> extends PingableSearcher implements Nod } public ClusterSearcher(ComponentId id, List<T> connections, Hasher<T> hasher, boolean internal) { + this(id, connections, hasher, internal, true); + } + + public ClusterSearcher(ComponentId id, List<T> connections, Hasher<T> hasher, boolean internal, boolean startPingThread) { super(id); this.hasher = hasher; + this.monitor = new ClusterMonitor<>(this, startPingThread); for (T connection : connections) { monitor.add(connection, internal); hasher.add(connection); diff --git a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java index aa57e7903f9..c90d2774bd1 100644 --- a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java @@ -8,6 +8,7 @@ import com.yahoo.prelude.Pong; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.cluster.ClusterSearcher; +import com.yahoo.search.cluster.Hasher; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; @@ -164,7 +165,7 @@ public class ClusteredConnectionTestCase { private static class MyBackend extends ClusterSearcher<Connection> { public MyBackend(ComponentId componentId, List<Connection> connections) { - super(componentId,connections, false); + super(componentId,connections, new Hasher<>(), false, false); } @Override |