From 3a1fa20efeef5ba7304d5dc542ef180364922e3a Mon Sep 17 00:00:00 2001 From: Jonathan Dowland Date: Fri, 4 Nov 2022 10:27:32 +0000 Subject: [PATCH] 8240189: [TESTBUG] Some cgroup tests are failing after JDK-8231111 Reviewed-by: mdoerr Backport-of: c92adf41587767e9c5c8e116cfaeb375d36928aa --- .../platform/docker/MetricsCpuTester.java | 5 +- .../platform/docker/MetricsMemoryTester.java | 2 +- .../cgroup/CgroupMetricsTester.java | 24 +++- .../cgroup/MetricsTesterCgroupV1.java | 123 +++++++++--------- .../cgroup/MetricsTesterCgroupV2.java | 62 ++++----- 5 files changed, 117 insertions(+), 99 deletions(-) diff --git a/jdk/test/jdk/internal/platform/docker/MetricsCpuTester.java b/jdk/test/jdk/internal/platform/docker/MetricsCpuTester.java index 1ecbf1b25a1..ff5d52d95a6 100644 --- a/jdk/test/jdk/internal/platform/docker/MetricsCpuTester.java +++ b/jdk/test/jdk/internal/platform/docker/MetricsCpuTester.java @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.stream.IntStream; import java.util.stream.Stream; + import jdk.internal.platform.Metrics; public class MetricsCpuTester { @@ -96,7 +97,7 @@ private static void testCpuSets(String cpuset) { } // Check to see if this metric is supported on this platform - if (effectiveCpus.length != 0) { + if (effectiveCpus != null) { if (!Arrays.equals(ipCpuSet, effectiveCpus)) { throw new RuntimeException("Effective Cpusets not equal, expected : " + Arrays.toString(ipCpuSet) + ", got : " @@ -131,7 +132,7 @@ private static void testCpuSetMemNodes(String cpusetMems) { } // Check to see if this metric is supported on this platform - if (effectiveMems.length != 0) { + if (effectiveMems != null) { if (!Arrays.equals(ipCpuSet, effectiveMems)) { throw new RuntimeException("Effective mem nodes not equal, expected : " + Arrays.toString(ipCpuSet) + ", got : " diff --git a/jdk/test/jdk/internal/platform/docker/MetricsMemoryTester.java b/jdk/test/jdk/internal/platform/docker/MetricsMemoryTester.java index 79b7e37a3f5..62216b51994 100644 --- a/jdk/test/jdk/internal/platform/docker/MetricsMemoryTester.java +++ b/jdk/test/jdk/internal/platform/docker/MetricsMemoryTester.java @@ -135,7 +135,7 @@ private static void testKernelMemoryLimit(String value) { + kmemlimit + "]"); } } else { - throw new RuntimeException("oomKillFlag test not supported for cgroups v2"); + throw new RuntimeException("kernel memory limit test not supported for cgroups v2"); } } diff --git a/jdk/test/lib/jdk/test/lib/containers/cgroup/CgroupMetricsTester.java b/jdk/test/lib/jdk/test/lib/containers/cgroup/CgroupMetricsTester.java index 5e3695dbaa3..768a6c04e30 100644 --- a/jdk/test/lib/jdk/test/lib/containers/cgroup/CgroupMetricsTester.java +++ b/jdk/test/lib/jdk/test/lib/containers/cgroup/CgroupMetricsTester.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.math.BigInteger; +import java.util.Arrays; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -41,9 +42,9 @@ interface CgroupMetricsTester { public void testMemoryUsage() throws Exception; public void testMisc(); - public static long convertStringToLong(String strval, long overflowRetval) { - long retval = 0; - if (strval == null) return 0L; + public static long convertStringToLong(String strval, long initialVal, long overflowRetval) { + long retval = initialVal; + if (strval == null) return retval; try { retval = Long.parseLong(strval); @@ -93,7 +94,7 @@ public static void warn(String controller, String metric, long oldVal, long test public static Integer[] convertCpuSetsToArray(String cpusstr) { if (cpusstr == null || EMPTY_STR.equals(cpusstr)) { - return new Integer[0]; + return null; } // Parse range string in the format 1,2-6,7 Integer[] cpuSets = Stream.of(cpusstr.split(",")).flatMap(a -> { @@ -108,4 +109,19 @@ public static Integer[] convertCpuSetsToArray(String cpusstr) { return cpuSets; } + public static Integer[] boxedArrayOrNull(int[] primitiveArray) { + if (primitiveArray == null) { + return null; + } + return Arrays.stream(primitiveArray).boxed().toArray(Integer[]::new); + } + + public static Integer[] sortAllowNull(Integer[] array) { + if (array == null) { + return null; + } + Arrays.sort(array); + return array; + } + } diff --git a/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java b/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java index f618ee2b1e1..ac998f7e609 100644 --- a/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java +++ b/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java @@ -38,11 +38,15 @@ import java.util.stream.LongStream; import java.util.stream.Stream; -import jdk.internal.platform.Metrics; +import jdk.internal.platform.CgroupSubsystem; import jdk.internal.platform.CgroupV1Metrics; +import jdk.internal.platform.Metrics; +import jdk.test.lib.Asserts; public class MetricsTesterCgroupV1 implements CgroupMetricsTester { + // Aliased for readability + private static final long RETVAL_UNAVAILABLE = CgroupSubsystem.LONG_RETVAL_UNLIMITED; private static long unlimited_minimum = 0x7FFFFFFFFF000000L; long startSysVal; long startUserVal; @@ -127,9 +131,6 @@ public void setup() { startUserVal = metrics.getCpuUserUsage(); startUsage = metrics.getCpuUsage(); startPerCpu = metrics.getPerCpuUsage(); - if (startPerCpu == null) { - startPerCpu = new long[0]; - } try { Stream lines = Files.lines(Paths.get("/proc/self/mountinfo")); @@ -159,11 +160,11 @@ private static String getFileContents(Controller subSystem, String fileName) { private static long getLongValueFromFile(Controller subSystem, String fileName) { String data = getFileContents(subSystem, fileName); - return (data == null || data.isEmpty()) ? 0L : convertStringToLong(data); + return (data == null || data.isEmpty()) ? RETVAL_UNAVAILABLE : convertStringToLong(data); } private static long convertStringToLong(String strval) { - return CgroupMetricsTester.convertStringToLong(strval, Long.MAX_VALUE); + return CgroupMetricsTester.convertStringToLong(strval, RETVAL_UNAVAILABLE, Long.MAX_VALUE); } private static long getLongValueFromFile(Controller subSystem, String metric, String subMetric) { @@ -175,12 +176,12 @@ private static long getLongValueFromFile(Controller subSystem, String metric, St return convertStringToLong(strval); } } - return 0L; + return RETVAL_UNAVAILABLE; } private static double getDoubleValueFromFile(Controller subSystem, String fileName) { String data = getFileContents(subSystem, fileName); - return data.isEmpty() ? 0.0 : Double.parseDouble(data); + return data == null || data.isEmpty() ? RETVAL_UNAVAILABLE : Double.parseDouble(data); } private static void fail(Controller system, String metric, long oldVal, long testVal) { @@ -203,6 +204,13 @@ private static void warn(Controller system, String metric, long oldVal, long tes CgroupMetricsTester.warn(system.value, metric, oldVal, testVal); } + private Long[] boxedArrayOrNull(long[] primitiveArray) { + if (primitiveArray == null) { + return null; + } + return LongStream.of(primitiveArray).boxed().toArray(Long[]::new); + } + public void testMemorySubsystem() { CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); @@ -215,7 +223,7 @@ public void testMemorySubsystem() { oldVal = metrics.getMemoryLimit(); newVal = getLongValueFromFile(Controller.MEMORY, "memory.limit_in_bytes"); - newVal = newVal > unlimited_minimum ? -1L : newVal; + newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { fail(Controller.MEMORY, "memory.limit_in_bytes", oldVal, newVal); } @@ -241,7 +249,7 @@ public void testMemorySubsystem() { oldVal = metrics.getKernelMemoryLimit(); newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.limit_in_bytes"); - newVal = newVal > unlimited_minimum ? -1L : newVal; + newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { fail(Controller.MEMORY, "memory.kmem.limit_in_bytes", oldVal, newVal); } @@ -267,7 +275,7 @@ public void testMemorySubsystem() { oldVal = metrics.getTcpMemoryLimit(); newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes"); - newVal = newVal > unlimited_minimum ? -1L : newVal; + newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED: newVal; if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { fail(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes", oldVal, newVal); } @@ -295,7 +303,7 @@ public void testMemorySubsystem() { oldVal = metrics.getMemoryAndSwapLimit(); newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes"); - newVal = newVal > unlimited_minimum ? -1L : newVal; + newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal); } @@ -318,7 +326,7 @@ public void testMemorySubsystem() { oldVal = metrics.getMemorySoftLimit(); newVal = getLongValueFromFile(Controller.MEMORY, "memory.soft_limit_in_bytes"); - newVal = newVal > unlimited_minimum ? -1L : newVal; + newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { fail(Controller.MEMORY, "memory.soft_limit_in_bytes", oldVal, newVal); } @@ -343,20 +351,22 @@ public void testCpuAccounting() { } String newValsStr = getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu"); - Long[] newVals = new Long[0]; + Long[] newVals = null; if (newValsStr != null) { newVals = Stream.of(newValsStr .split("\\s+")) .map(Long::parseLong) .toArray(Long[]::new); } - long[] oldValsPrim = metrics.getPerCpuUsage(); - Long[] oldVals = LongStream.of(oldValsPrim == null ? new long[0] : oldValsPrim) - .boxed().toArray(Long[]::new); - for (int i = 0; i < oldVals.length; i++) { - if (!CgroupMetricsTester.compareWithErrorMargin(oldVals[i], newVals[i])) { - warn(Controller.CPUACCT, "cpuacct.usage_percpu", oldVals[i], newVals[i]); + Long[] oldVals = boxedArrayOrNull(metrics.getPerCpuUsage()); + if (oldVals != null) { + for (int i = 0; i < oldVals.length; i++) { + if (!CgroupMetricsTester.compareWithErrorMargin(oldVals[i], newVals[i])) { + warn(Controller.CPUACCT, "cpuacct.usage_percpu", oldVals[i], newVals[i]); + } } + } else { + Asserts.assertNull(newVals, Controller.CPUACCT.value() + "cpuacct.usage_percpu not both null"); } oldVal = metrics.getCpuUserUsage(); @@ -414,13 +424,13 @@ public void testCpuSchedulingMetrics() { public void testCpuSets() { CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics(); - Integer[] oldVal = Arrays.stream(metrics.getCpuSetCpus()).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); + Integer[] oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getCpuSetCpus()); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); String cpusstr = getFileContents(Controller.CPUSET, "cpuset.cpus"); // Parse range string in the format 1,2-6,7 Integer[] newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); + newVal = CgroupMetricsTester.sortAllowNull(newVal); if (!Arrays.equals(oldVal, newVal)) { fail(Controller.CPUSET, "cpuset.cpus", Arrays.toString(oldVal), Arrays.toString(newVal)); @@ -428,24 +438,21 @@ public void testCpuSets() { int [] cpuSets = metrics.getEffectiveCpuSetCpus(); - // Skip this test if this metric is not supported on this platform - if (cpuSets.length != 0) { - oldVal = Arrays.stream(cpuSets).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); - cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_cpus"); - newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); - if (!Arrays.equals(oldVal, newVal)) { - fail(Controller.CPUSET, "cpuset.effective_cpus", Arrays.toString(oldVal), - Arrays.toString(newVal)); - } + oldVal = CgroupMetricsTester.boxedArrayOrNull(cpuSets); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); + cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_cpus"); + newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); + newVal = CgroupMetricsTester.sortAllowNull(newVal); + if (!Arrays.equals(oldVal, newVal)) { + fail(Controller.CPUSET, "cpuset.effective_cpus", Arrays.toString(oldVal), + Arrays.toString(newVal)); } - oldVal = Arrays.stream(metrics.getCpuSetMems()).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); + oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getCpuSetMems()); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); cpusstr = getFileContents(Controller.CPUSET, "cpuset.mems"); newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); + newVal = CgroupMetricsTester.sortAllowNull(newVal); if (!Arrays.equals(oldVal, newVal)) { fail(Controller.CPUSET, "cpuset.mems", Arrays.toString(oldVal), Arrays.toString(newVal)); @@ -453,17 +460,14 @@ public void testCpuSets() { int [] cpuSetMems = metrics.getEffectiveCpuSetMems(); - // Skip this test if this metric is not supported on this platform - if (cpuSetMems.length != 0) { - oldVal = Arrays.stream(cpuSetMems).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); - cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_mems"); - newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); - if (!Arrays.equals(oldVal, newVal)) { - fail(Controller.CPUSET, "cpuset.effective_mems", Arrays.toString(oldVal), - Arrays.toString(newVal)); - } + oldVal = CgroupMetricsTester.boxedArrayOrNull(cpuSetMems); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); + cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_mems"); + newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); + newVal = CgroupMetricsTester.sortAllowNull(newVal); + if (!Arrays.equals(oldVal, newVal)) { + fail(Controller.CPUSET, "cpuset.effective_mems", Arrays.toString(oldVal), + Arrays.toString(newVal)); } double oldValue = metrics.getCpuSetMemoryPressure(); @@ -504,9 +508,6 @@ public void testCpuConsumption() throws IOException, InterruptedException { long newUserVal = metrics.getCpuUserUsage(); long newUsage = metrics.getCpuUsage(); long[] newPerCpu = metrics.getPerCpuUsage(); - if (newPerCpu == null) { - newPerCpu = new long[0]; - } // system/user CPU usage counters may be slowly increasing. // allow for equal values for a pass @@ -524,16 +525,22 @@ public void testCpuConsumption() throws IOException, InterruptedException { fail(Controller.CPU, "getCpuUsage", newUsage, startUsage); } - boolean success = false; - for (int i = 0; i < startPerCpu.length; i++) { - if (newPerCpu[i] > startPerCpu[i]) { - success = true; - break; + if (startPerCpu != null) { + boolean success = false; + for (int i = 0; i < startPerCpu.length; i++) { + if (newPerCpu[i] > startPerCpu[i]) { + success = true; + break; + } + } + if (!success) { + fail(Controller.CPU, "getPerCpuUsage", Arrays.toString(newPerCpu), + Arrays.toString(startPerCpu)); } + } else { + Asserts.assertNull(newPerCpu, Controller.CPU.value() + " getPerCpuUsage not both null"); } - if(!success) fail(Controller.CPU, "getPerCpuUsage", Arrays.toString(newPerCpu), - Arrays.toString(startPerCpu)); } public void testMemoryUsage() throws Exception { diff --git a/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java b/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java index 821bce939dd..bd8d71e3e27 100644 --- a/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java +++ b/jdk/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java @@ -32,12 +32,12 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import jdk.internal.platform.CgroupSubsystem; import jdk.internal.platform.Metrics; public class MetricsTesterCgroupV2 implements CgroupMetricsTester { private static final long UNLIMITED = -1; + private static final long NOT_AVAILABLE = -1; private static final UnifiedController UNIFIED = new UnifiedController(); private static final String MAX = "max"; private static final int PER_CPU_SHARES = 1024; @@ -125,7 +125,7 @@ private long getLongValueEntryFromFile(String file, String metric) { String value = keyValues[1]; return convertStringToLong(value); } catch (IOException e) { - return 0; + return NOT_AVAILABLE; } } @@ -152,7 +152,7 @@ private void warn(String metric, long oldVal, long newVal) { private long getCpuShares(String file) { long rawVal = getLongValueFromFile(file); - if (rawVal == 0 || rawVal == 100) { + if (rawVal == NOT_AVAILABLE || rawVal == 100) { return UNLIMITED; } int shares = (int)rawVal; @@ -200,7 +200,14 @@ private long getCpuValueFromFile(String file, int index) { } private long convertStringToLong(String val) { - return CgroupMetricsTester.convertStringToLong(val, UNLIMITED); + return CgroupMetricsTester.convertStringToLong(val, NOT_AVAILABLE, UNLIMITED); + } + + private long nanosOrUnlimited(long micros) { + if (micros < 0) { + return UNLIMITED; + } + return TimeUnit.MICROSECONDS.toNanos(micros); } @Override @@ -265,20 +272,20 @@ public void testMemorySubsystem() { public void testCpuAccounting() { Metrics metrics = Metrics.systemMetrics(); long oldVal = metrics.getCpuUsage(); - long newVal = TimeUnit.MICROSECONDS.toNanos(getLongValueEntryFromFile("cpu.stat", "usage_usec")); + long newVal = nanosOrUnlimited(getLongValueEntryFromFile("cpu.stat", "usage_usec")); if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { warn("cpu.stat[usage_usec]", oldVal, newVal); } oldVal = metrics.getCpuUserUsage(); - newVal = TimeUnit.MICROSECONDS.toNanos(getLongValueEntryFromFile("cpu.stat", "user_usec")); + newVal = nanosOrUnlimited(getLongValueEntryFromFile("cpu.stat", "user_usec")); if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { warn("cpu.stat[user_usec]", oldVal, newVal); } oldVal = metrics.getCpuSystemUsage(); - newVal = TimeUnit.MICROSECONDS.toNanos(getLongValueEntryFromFile("cpu.stat", "system_usec")); + newVal = nanosOrUnlimited(getLongValueEntryFromFile("cpu.stat", "system_usec")); if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { warn("cpu.stat[system_usec]", oldVal, newVal); } @@ -318,7 +325,7 @@ public void testCpuSchedulingMetrics() { } oldVal = metrics.getCpuThrottledTime(); - newVal = TimeUnit.MICROSECONDS.toNanos(getLongValueEntryFromFile("cpu.stat", "throttled_usec")); + newVal = nanosOrUnlimited(getLongValueEntryFromFile("cpu.stat", "throttled_usec")); if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { fail("cpu.stat[throttled_usec]", oldVal, newVal); } @@ -327,62 +334,49 @@ public void testCpuSchedulingMetrics() { @Override public void testCpuSets() { Metrics metrics = Metrics.systemMetrics(); - int[] cpus = mapNullToEmpty(metrics.getCpuSetCpus()); - Integer[] oldVal = Arrays.stream(cpus).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); + Integer[] oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getCpuSetCpus()); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); String cpusstr = getStringVal("cpuset.cpus"); // Parse range string in the format 1,2-6,7 Integer[] newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); + newVal = CgroupMetricsTester.sortAllowNull(newVal); if (!Arrays.equals(oldVal, newVal)) { fail("cpuset.cpus", Arrays.toString(oldVal), Arrays.toString(newVal)); } - cpus = mapNullToEmpty(metrics.getEffectiveCpuSetCpus()); - oldVal = Arrays.stream(cpus).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); + oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getEffectiveCpuSetCpus()); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); cpusstr = getStringVal("cpuset.cpus.effective"); newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); + newVal = CgroupMetricsTester.sortAllowNull(newVal); if (!Arrays.equals(oldVal, newVal)) { fail("cpuset.cpus.effective", Arrays.toString(oldVal), Arrays.toString(newVal)); } - cpus = mapNullToEmpty(metrics.getCpuSetMems()); - oldVal = Arrays.stream(cpus).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); + oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getCpuSetMems()); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); cpusstr = getStringVal("cpuset.mems"); newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); + newVal = CgroupMetricsTester.sortAllowNull(newVal); if (!Arrays.equals(oldVal, newVal)) { fail("cpuset.mems", Arrays.toString(oldVal), Arrays.toString(newVal)); } - cpus = mapNullToEmpty(metrics.getEffectiveCpuSetMems()); - oldVal = Arrays.stream(cpus).boxed().toArray(Integer[]::new); - Arrays.sort(oldVal); + oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getEffectiveCpuSetMems()); + oldVal = CgroupMetricsTester.sortAllowNull(oldVal); cpusstr = getStringVal("cpuset.mems.effective"); newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr); - Arrays.sort(newVal); + newVal = CgroupMetricsTester.sortAllowNull(newVal); if (!Arrays.equals(oldVal, newVal)) { fail("cpuset.mems.effective", Arrays.toString(oldVal), Arrays.toString(newVal)); } } - private int[] mapNullToEmpty(int[] cpus) { - if (cpus == null) { - // Not available. For sake of testing continue with an - // empty array. - cpus = new int[0]; - } - return cpus; - } - @Override public void testCpuConsumption() { Metrics metrics = Metrics.systemMetrics(); @@ -471,7 +465,7 @@ private long getIoStatAccumulate(String[] matchNames) { return accumulator; }).collect(Collectors.summingLong(e -> e)); } catch (IOException e) { - return CgroupSubsystem.LONG_RETVAL_UNLIMITED; + return NOT_AVAILABLE; } } }