Update monitor probe tests for java 9: this stuff is no longer accessible

This commit is contained in:
Robert Muir 2015-09-10 23:18:58 -04:00
parent 6ba4d132df
commit af2df9aef6
3 changed files with 28 additions and 15 deletions

View File

@ -227,6 +227,7 @@ public class OsStats implements Streamable, ToXContent {
} }
} }
// TODO: if values are -1, this should return -1 to show its unsupported?
private static short calculatePercentage(long used, long max) { private static short calculatePercentage(long used, long max) {
return max <= 0 ? 0 : (short) (Math.round((100d * used) / max)); return max <= 0 ? 0 : (short) (Math.round((100d * used) / max));
} }

View File

@ -54,11 +54,14 @@ public class OsProbeTests extends ESTestCase {
} }
assertNotNull(stats.getMem()); assertNotNull(stats.getMem());
assertThat(stats.getMem().getTotal().bytes(), greaterThan(0L)); // TODO: once java 9 is sorted out make these hard checks (currently 9-ea and 9-ea-jigsaw will differ)
assertThat(stats.getMem().getFree().bytes(), greaterThan(0L)); if (!Constants.JRE_IS_MINIMUM_JAVA9) {
assertThat(stats.getMem().getFreePercent(), allOf(greaterThanOrEqualTo((short) 0), lessThanOrEqualTo((short) 100))); assertThat(stats.getMem().getTotal().bytes(), greaterThan(0L));
assertThat(stats.getMem().getUsed().bytes(), greaterThan(0L)); assertThat(stats.getMem().getFree().bytes(), greaterThan(0L));
assertThat(stats.getMem().getUsedPercent(), allOf(greaterThanOrEqualTo((short) 0), lessThanOrEqualTo((short) 100))); assertThat(stats.getMem().getFreePercent(), allOf(greaterThanOrEqualTo((short) 0), lessThanOrEqualTo((short) 100)));
assertThat(stats.getMem().getUsed().bytes(), greaterThan(0L));
assertThat(stats.getMem().getUsedPercent(), allOf(greaterThanOrEqualTo((short) 0), lessThanOrEqualTo((short) 100)));
}
assertNotNull(stats.getSwap()); assertNotNull(stats.getSwap());
assertNotNull(stats.getSwap().getTotal()); assertNotNull(stats.getSwap().getTotal());
@ -70,9 +73,12 @@ public class OsProbeTests extends ESTestCase {
assertThat(stats.getSwap().getUsed().bytes(), greaterThanOrEqualTo(0L)); assertThat(stats.getSwap().getUsed().bytes(), greaterThanOrEqualTo(0L));
} else { } else {
// On platforms with no swap // On platforms with no swap
assertThat(stats.getSwap().getTotal().bytes(), equalTo(0L)); // TODO: one java 9 is sorted out make these hard checks (currently 9-ea and 9-ea-jigsaw will differ)
assertThat(stats.getSwap().getFree().bytes(), equalTo(0L)); if (!Constants.JRE_IS_MINIMUM_JAVA9) {
assertThat(stats.getSwap().getUsed().bytes(), equalTo(0L)); assertThat(stats.getSwap().getTotal().bytes(), equalTo(0L));
assertThat(stats.getSwap().getFree().bytes(), equalTo(0L));
assertThat(stats.getSwap().getUsed().bytes(), equalTo(0L));
}
} }
} }
} }

View File

@ -51,8 +51,11 @@ public class ProcessProbeTests extends ESTestCase {
assertThat(stats.getOpenFileDescriptors(), equalTo(-1L)); assertThat(stats.getOpenFileDescriptors(), equalTo(-1L));
assertThat(stats.getMaxFileDescriptors(), equalTo(-1L)); assertThat(stats.getMaxFileDescriptors(), equalTo(-1L));
} else { } else {
assertThat(stats.getOpenFileDescriptors(), greaterThan(0L)); // TODO: once java 9 is sorted out make these hard checks (currently 9-ea and 9-ea-jigsaw will differ)
assertThat(stats.getMaxFileDescriptors(), greaterThan(0L)); if (!Constants.JRE_IS_MINIMUM_JAVA9) {
assertThat(stats.getOpenFileDescriptors(), greaterThan(0L));
assertThat(stats.getMaxFileDescriptors(), greaterThan(0L));
}
} }
ProcessStats.Cpu cpu = stats.getCpu(); ProcessStats.Cpu cpu = stats.getCpu();
@ -62,11 +65,14 @@ public class ProcessProbeTests extends ESTestCase {
assertThat(cpu.getPercent(), anyOf(lessThan((short) 0), allOf(greaterThanOrEqualTo((short) 0), lessThanOrEqualTo((short) 100)))); assertThat(cpu.getPercent(), anyOf(lessThan((short) 0), allOf(greaterThanOrEqualTo((short) 0), lessThanOrEqualTo((short) 100))));
// CPU time can return -1 if the the platform does not support this operation, let's see which platforms fail // CPU time can return -1 if the the platform does not support this operation, let's see which platforms fail
assertThat(cpu.total, greaterThan(0L)); if (!Constants.JRE_IS_MINIMUM_JAVA9) {
// TODO: once java 9 is sorted out make these hard checks (currently 9-ea and 9-ea-jigsaw will differ)
assertThat(cpu.total, greaterThan(0L));
ProcessStats.Mem mem = stats.getMem(); ProcessStats.Mem mem = stats.getMem();
assertNotNull(mem); assertNotNull(mem);
// Commited total virtual memory can return -1 if not supported, let's see which platforms fail // Commited total virtual memory can return -1 if not supported, let's see which platforms fail
assertThat(mem.totalVirtual, greaterThan(0L)); assertThat(mem.totalVirtual, greaterThan(0L));
}
} }
} }