ClusterStats tests should allow for open file descriptors to be -1 (which they are on windows)

Also made some other small tweaks for that case.
This commit is contained in:
Boaz Leskes 2014-01-10 17:42:11 +01:00
parent 6be2066bd3
commit b0f73d2625
2 changed files with 13 additions and 6 deletions

View File

@ -397,8 +397,8 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
int count; int count;
int cpuPercent; int cpuPercent;
long totalOpenFileDescriptors; long totalOpenFileDescriptors;
long minOpenFileDescriptors = Integer.MAX_VALUE; long minOpenFileDescriptors = Long.MAX_VALUE;
long maxOpenFileDescriptors = Integer.MIN_VALUE; long maxOpenFileDescriptors = Long.MIN_VALUE;
public void addNodeStats(NodeStats nodeStats) { public void addNodeStats(NodeStats nodeStats) {
if (nodeStats.getProcess() == null) { if (nodeStats.getProcess() == null) {
@ -410,7 +410,11 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
cpuPercent += nodeStats.getProcess().cpu().getPercent(); cpuPercent += nodeStats.getProcess().cpu().getPercent();
} }
long fd = nodeStats.getProcess().openFileDescriptors(); long fd = nodeStats.getProcess().openFileDescriptors();
totalOpenFileDescriptors += fd; if (fd > 0) {
// fd can be -1 if not supported on platform
totalOpenFileDescriptors += fd;
}
// we still do min max calc on -1, so we'll have an indication of it not being supported on one of the nodes.
minOpenFileDescriptors = Math.min(minOpenFileDescriptors, fd); minOpenFileDescriptors = Math.min(minOpenFileDescriptors, fd);
maxOpenFileDescriptors = Math.max(maxOpenFileDescriptors, fd); maxOpenFileDescriptors = Math.max(maxOpenFileDescriptors, fd);
} }

View File

@ -136,9 +136,12 @@ public class ClusterStatsTests extends ElasticsearchIntegrationTest {
assertThat(response.nodesStats.getVersions().contains(Version.CURRENT), Matchers.equalTo(true)); assertThat(response.nodesStats.getVersions().contains(Version.CURRENT), Matchers.equalTo(true));
assertThat(response.nodesStats.getPlugins().size(), Matchers.greaterThanOrEqualTo(0)); assertThat(response.nodesStats.getPlugins().size(), Matchers.greaterThanOrEqualTo(0));
assertThat(response.nodesStats.getProcess().getAvgOpenFileDescriptors(), Matchers.greaterThan(0L)); assertThat(response.nodesStats.getProcess().count, Matchers.greaterThan(0));
assertThat(response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThan(0L)); // 0 happens when not supported on platform
assertThat(response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThan(0L)); assertThat(response.nodesStats.getProcess().getAvgOpenFileDescriptors(), Matchers.greaterThanOrEqualTo(0L));
// these can be -1 if not supported
assertThat(response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThan(-1L));
assertThat(response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThan(-1L));
} }
} }