Skip to content

Commit f1c1d03

Browse files
Finish monitor -- use mockito spy to check that the new monitor is called (and thus that it is set up properly).
1 parent 7aef577 commit f1c1d03

File tree

3 files changed

+19
-50
lines changed

3 files changed

+19
-50
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/NodeUsageStatsForThreadPoolsMonitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void onNewInfo(ClusterInfo clusterInfo) {
7575
String explanation = "";
7676
final long currentTimeMillis = currentTimeMillisSupplier.getAsLong();
7777

78+
// TODO (ES-11992): implement
79+
7880
if (reroute) {
7981
logger.debug("rerouting shards: [{}]", explanation);
8082
rerouteService.reroute("disk threshold monitor", Priority.NORMAL, ActionListener.wrap(ignored -> {

server/src/test/java/org/elasticsearch/cluster/InternalClusterInfoServiceSchedulingTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
import org.elasticsearch.cluster.node.DiscoveryNode;
2222
import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
2323
import org.elasticsearch.cluster.node.DiscoveryNodes;
24+
import org.elasticsearch.cluster.routing.RerouteService;
25+
import org.elasticsearch.cluster.routing.allocation.NodeUsageStatsForThreadPoolsMonitor;
2426
import org.elasticsearch.cluster.routing.allocation.WriteLoadConstraintSettings;
2527
import org.elasticsearch.cluster.service.ClusterApplierService;
2628
import org.elasticsearch.cluster.service.ClusterService;
2729
import org.elasticsearch.cluster.service.FakeThreadPoolMasterService;
2830
import org.elasticsearch.cluster.service.MasterService;
31+
import org.elasticsearch.common.Priority;
2932
import org.elasticsearch.common.settings.ClusterSettings;
3033
import org.elasticsearch.common.settings.Settings;
3134
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
@@ -95,6 +98,18 @@ protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor() {
9598
mockEstimatedHeapUsageCollector,
9699
nodeUsageStatsForThreadPoolsCollector
97100
);
101+
final NodeUsageStatsForThreadPoolsMonitor usageMonitor = spy(
102+
new NodeUsageStatsForThreadPoolsMonitor(
103+
clusterService.getClusterSettings(),
104+
threadPool.relativeTimeInMillisSupplier(),
105+
clusterService::state,
106+
new RerouteService() {
107+
@Override
108+
public void reroute(String reason, Priority priority, ActionListener<Void> listener) {}
109+
}
110+
)
111+
);
112+
clusterInfoService.addListener(usageMonitor::onNewInfo);
98113
clusterService.addListener(clusterInfoService);
99114
clusterInfoService.addListener(ignored -> {});
100115

@@ -132,13 +147,15 @@ protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor() {
132147
for (int i = 0; i < 3; i++) {
133148
Mockito.clearInvocations(mockEstimatedHeapUsageCollector);
134149
Mockito.clearInvocations(nodeUsageStatsForThreadPoolsCollector);
150+
Mockito.clearInvocations(usageMonitor);
135151
final int initialRequestCount = client.requestCount;
136152
final long duration = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings).millis();
137153
runFor(deterministicTaskQueue, duration);
138154
deterministicTaskQueue.runAllRunnableTasks();
139155
assertThat(client.requestCount, equalTo(initialRequestCount + 2)); // should have run two client requests per interval
140156
verify(mockEstimatedHeapUsageCollector).collectClusterHeapUsage(any()); // Should poll for heap usage once per interval
141157
verify(nodeUsageStatsForThreadPoolsCollector).collectUsageStats(any(), any(), any());
158+
verify(usageMonitor).onNewInfo(any());
142159
}
143160

144161
final AtomicBoolean failMaster2 = new AtomicBoolean();

server/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeUsageStatsForThreadPoolsMonitorTests.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)