8350818: Improve OperatingSystemMXBean cpu load tests to not accept -1.0 by default

Reviewed-by: kevinw
This commit is contained in:
Leonid Mesnik 2025-02-28 22:37:41 +00:00
parent 6b719eeebc
commit 3c72c04de7
2 changed files with 5 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,7 +39,7 @@ public class GetProcessCpuLoad {
double load; double load;
for(int i=0; i<10; i++) { for(int i=0; i<10; i++) {
load = mbean.getProcessCpuLoad(); load = mbean.getProcessCpuLoad();
if((load<0.0 || load>1.0) && load != -1.0) { if(load<0.0 || load>1.0) {
throw new RuntimeException("getProcessCpuLoad() returns " + load throw new RuntimeException("getProcessCpuLoad() returns " + load
+ " which is not in the [0.0,1.0] interval"); + " which is not in the [0.0,1.0] interval");
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/* /*
* @test * @test
* @bug 7028071 * @bug 7028071
* @summary Basic unit test of OperatingSystemMXBean.getProcessCpuLoad() * @summary Basic unit test of OperatingSystemMXBean.getSystemCpuLoad()
* *
* @run main GetSystemCpuLoad * @run main GetSystemCpuLoad
*/ */
@ -39,7 +39,7 @@ public class GetSystemCpuLoad {
double load; double load;
for(int i=0; i<10; i++) { for(int i=0; i<10; i++) {
load = mbean.getSystemCpuLoad(); load = mbean.getSystemCpuLoad();
if((load<0.0 || load>1.0) && load != -1.0) { if(load<0.0 || load>1.0) {
throw new RuntimeException("getSystemCpuLoad() returns " + load throw new RuntimeException("getSystemCpuLoad() returns " + load
+ " which is not in the [0.0,1.0] interval"); + " which is not in the [0.0,1.0] interval");
} }