Skip to content

Commit

Permalink
8292066: Convert TestInputArgument.sh and TestSystemLoadAvg.sh to jav…
Browse files Browse the repository at this point in the history
…a version

Reviewed-by: lmesnik, amenkov
  • Loading branch information
bwhuang-us authored and lmesnik committed Sep 1, 2022
1 parent e393973 commit 032be16
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,11 +22,14 @@
*/

/*
*
*
* @bug 6336608 6511738
* @test
* @bug 6336608 6511738 6367473
* @summary Basic unit test of OperatingSystemMXBean.getSystemLoadAverage()
* @author Mandy Chung
*
* @library /test/lib
*
* @run testng GetSystemLoadAverage
*/

/*
Expand All @@ -42,8 +45,13 @@
* running on Windows.
*/

import java.lang.management.*;
import java.io.*;
import jdk.test.lib.Platform;
import org.testng.annotations.Test;

import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;

public class GetSystemLoadAverage {

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

// The system load average may be changing due to other jobs running.
// Allow some delta.
private static double DELTA = 0.05;

public static void main(String args[]) throws Exception {
if (args.length > 1) {
throw new IllegalArgumentException("Unexpected number of args " + args.length);
}

if (args.length == 0) {
// On Linux or Solaris
checkLoadAvg();
} else {
// On Windows, the system load average is expected to be -1.0
if (!args[0].equals("-1.0")) {
throw new IllegalArgumentException("Invalid argument: " + args[0]);
} else {
double loadavg = mbean.getSystemLoadAverage();
if (loadavg != -1.0) {
throw new RuntimeException("Expected load average : -1.0" +
" but getSystemLoadAverage returned: " +
loadavg);
private static final double DELTA = 0.05;

private static final int MAX_RETRIES = 5;
private static final int WAIT_TIME_MS = 5000;

@Test(timeOut = (300 + WAIT_TIME_MS) * MAX_RETRIES)
void testSystemLoadAvg() throws Exception {
for (int i = 1; i <= MAX_RETRIES; i++) {
try {
System.out.println(String.format("Run %d: TestSystemLoadAvg", i));
if (!Platform.isWindows()) {
// On Linux or Mac
checkLoadAvg();
} else {
// On Windows, the system load average is expected to be -1.0
double loadavg = mbean.getSystemLoadAverage();
if (loadavg != -1.0) {
throw new RuntimeException("Expected load average : -1.0" +
" but getSystemLoadAverage returned: " + loadavg);
}
}
System.out.println(String.format("Run %d: TestSystemLoadAvg test passed", i));
return;
} catch (Exception e) {
System.out.println(
String.format("TEST FAILED: TestSystemLoadAvg test " + "failed %d runs",
i));
if (i == MAX_RETRIES) {
throw e;
}

System.out.println("Wait for 5 seconds");
Thread.sleep(WAIT_TIME_MS);
}
}

System.out.println("Test passed.");
}

private static String LOAD_AVERAGE_TEXT
Expand Down Expand Up @@ -132,5 +150,4 @@ private static String commandOutput(Process p) throws Exception {
p.exitValue();
return output;
}

}

This file was deleted.

35 changes: 34 additions & 1 deletion test/jdk/java/lang/management/RuntimeMXBean/InputArgument.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,11 +22,44 @@
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main InputArgument
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main/othervm -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main/othervm -XX:+UseFastJNIAccessors -Xlog:gc*=debug InputArgument
* -XX:+UseFastJNIAccessors
*/

/*
* @test
* @bug 4530538
* @summary Basic unit test of RuntimeMXBean.getInputArguments().
*
* @author Mandy Chung
*
* @run main/othervm -Dprops=something InputArgument -Dprops=something
*/

import java.lang.management.*;
Expand Down
55 changes: 0 additions & 55 deletions test/jdk/java/lang/management/RuntimeMXBean/TestInputArgument.sh

This file was deleted.

3 comments on commit 032be16

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 032be16 Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 032be16 Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-032be168 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 032be168 from the openjdk/jdk repository.

The commit being backported was authored by Bill Huang on 1 Sep 2022 and was reviewed by Leonid Mesnik and Alex Menkov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-032be168:GoeLin-backport-032be168
$ git checkout GoeLin-backport-032be168
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-032be168

Please sign in to comment.