Skip to content

Commit c74eb2b

Browse files
committed
8292066: Convert TestInputArgument.sh and TestSystemLoadAvg.sh to java version
Backport-of: 032be168b5a6af6f9e82deb8c8cafcd2c44b5447
1 parent 78c6be2 commit c74eb2b

File tree

4 files changed

+80
-168
lines changed

4 files changed

+80
-168
lines changed

test/jdk/java/lang/management/OperatingSystemMXBean/GetSystemLoadAverage.java

+46-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,11 +22,14 @@
2222
*/
2323

2424
/*
25-
*
26-
*
27-
* @bug 6336608 6511738
25+
* @test
26+
* @bug 6336608 6511738 6367473
2827
* @summary Basic unit test of OperatingSystemMXBean.getSystemLoadAverage()
2928
* @author Mandy Chung
29+
*
30+
* @library /test/lib
31+
*
32+
* @run testng GetSystemLoadAverage
3033
*/
3134

3235
/*
@@ -42,8 +45,13 @@
4245
* running on Windows.
4346
*/
4447

45-
import java.lang.management.*;
46-
import java.io.*;
48+
import jdk.test.lib.Platform;
49+
import org.testng.annotations.Test;
50+
51+
import java.io.InputStreamReader;
52+
import java.io.Reader;
53+
import java.lang.management.ManagementFactory;
54+
import java.lang.management.OperatingSystemMXBean;
4755

4856
public class GetSystemLoadAverage {
4957

@@ -52,31 +60,41 @@ public class GetSystemLoadAverage {
5260

5361
// The system load average may be changing due to other jobs running.
5462
// Allow some delta.
55-
private static double DELTA = 0.05;
56-
57-
public static void main(String args[]) throws Exception {
58-
if (args.length > 1) {
59-
throw new IllegalArgumentException("Unexpected number of args " + args.length);
60-
}
61-
62-
if (args.length == 0) {
63-
// On Linux or Solaris
64-
checkLoadAvg();
65-
} else {
66-
// On Windows, the system load average is expected to be -1.0
67-
if (!args[0].equals("-1.0")) {
68-
throw new IllegalArgumentException("Invalid argument: " + args[0]);
69-
} else {
70-
double loadavg = mbean.getSystemLoadAverage();
71-
if (loadavg != -1.0) {
72-
throw new RuntimeException("Expected load average : -1.0" +
73-
" but getSystemLoadAverage returned: " +
74-
loadavg);
63+
private static final double DELTA = 0.05;
64+
65+
private static final int MAX_RETRIES = 5;
66+
private static final int WAIT_TIME_MS = 5000;
67+
68+
@Test(timeOut = (300 + WAIT_TIME_MS) * MAX_RETRIES)
69+
void testSystemLoadAvg() throws Exception {
70+
for (int i = 1; i <= MAX_RETRIES; i++) {
71+
try {
72+
System.out.println(String.format("Run %d: TestSystemLoadAvg", i));
73+
if (!Platform.isWindows()) {
74+
// On Linux or Mac
75+
checkLoadAvg();
76+
} else {
77+
// On Windows, the system load average is expected to be -1.0
78+
double loadavg = mbean.getSystemLoadAverage();
79+
if (loadavg != -1.0) {
80+
throw new RuntimeException("Expected load average : -1.0" +
81+
" but getSystemLoadAverage returned: " + loadavg);
82+
}
83+
}
84+
System.out.println(String.format("Run %d: TestSystemLoadAvg test passed", i));
85+
return;
86+
} catch (Exception e) {
87+
System.out.println(
88+
String.format("TEST FAILED: TestSystemLoadAvg test " + "failed %d runs",
89+
i));
90+
if (i == MAX_RETRIES) {
91+
throw e;
7592
}
93+
94+
System.out.println("Wait for 5 seconds");
95+
Thread.sleep(WAIT_TIME_MS);
7696
}
7797
}
78-
79-
System.out.println("Test passed.");
8098
}
8199

82100
private static String LOAD_AVERAGE_TEXT
@@ -132,5 +150,4 @@ private static String commandOutput(Process p) throws Exception {
132150
p.exitValue();
133151
return output;
134152
}
135-
136153
}

test/jdk/java/lang/management/OperatingSystemMXBean/TestSystemLoadAvg.sh

-83
This file was deleted.

test/jdk/java/lang/management/RuntimeMXBean/InputArgument.java

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,11 +22,44 @@
2222
*/
2323

2424
/*
25+
* @test
2526
* @bug 4530538
2627
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
2728
*
2829
* @author Mandy Chung
2930
*
31+
* @run main InputArgument
32+
*/
33+
34+
/*
35+
* @test
36+
* @bug 4530538
37+
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
38+
*
39+
* @author Mandy Chung
40+
*
41+
* @run main/othervm -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument
42+
*/
43+
44+
/*
45+
* @test
46+
* @bug 4530538
47+
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
48+
*
49+
* @author Mandy Chung
50+
*
51+
* @run main/othervm -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument
52+
* -XX:+UseFastJNIAccessors
53+
*/
54+
55+
/*
56+
* @test
57+
* @bug 4530538
58+
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
59+
*
60+
* @author Mandy Chung
61+
*
62+
* @run main/othervm -Dprops=something InputArgument -Dprops=something
3063
*/
3164

3265
import java.lang.management.*;

test/jdk/java/lang/management/RuntimeMXBean/TestInputArgument.sh

-55
This file was deleted.

0 commit comments

Comments
 (0)