diff --git a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.java b/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.java index ec775b4b6ca..a996cd31293 100644 --- a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.java +++ b/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.java @@ -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 @@ -22,18 +22,13 @@ */ /* - * + * @test * @bug 4858522 * @summary Basic unit test of UnixOperatingSystemMXBean.getMaxFileDescriptorCount() * @author Steve Bohne - */ - -/* - * This test is just a sanity check and does not check for the correct - * value. The correct value should be checked manually: - * Solaris/Linux: - * 1. In a shell, as user who started java process, enter the command - * "limit -h descriptors" + * @requires os.family != "windows" + * + * @run main GetMaxFileDescriptorCount */ import com.sun.management.UnixOperatingSystemMXBean; @@ -42,35 +37,26 @@ import java.lang.management.*; public class GetMaxFileDescriptorCount { private static UnixOperatingSystemMXBean mbean = - (UnixOperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean(); + (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); - // Careful with these values. - // Min count for pass dynamically determined below. - private static long min_count_for_pass = 1; + private static long minCountForPass = 1; private static final long MAX_COUNT_FOR_PASS = Long.MAX_VALUE; - private static boolean trace = false; - public static void main(String args[]) throws Exception { - if (args.length > 0 && args[0].equals("trace")) { - trace = true; - } - long min_count = mbean.getOpenFileDescriptorCount(); - if (min_count > 0) { - min_count_for_pass = min_count; + long minCount = mbean.getOpenFileDescriptorCount(); + if (minCount > 0) { + minCountForPass = minCount; } long count = mbean.getMaxFileDescriptorCount(); - if (trace) { - System.out.println("Max file descriptor count: " + count); - } + System.out.println("Max file descriptor count: " + count); - if (count < min_count_for_pass || count > MAX_COUNT_FOR_PASS) { + if (count < minCountForPass || count > MAX_COUNT_FOR_PASS) { throw new RuntimeException("Max file descriptor count " + "illegal value: " + count + " bytes " + - "(MIN = " + min_count_for_pass + "; " + + "(MIN = " + minCountForPass + "; " + "MAX = " + MAX_COUNT_FOR_PASS + ")"); } diff --git a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.sh b/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.sh deleted file mode 100644 index 606e2e4c651..00000000000 --- a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.sh +++ /dev/null @@ -1,60 +0,0 @@ -# -# Copyright (c) 2003, 2020, 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 -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# - -# -# @test -# @bug 4858522 -# @summary -# @author Steve Bohne -# -# @run shell GetMaxFileDescriptorCount.sh -# - -if [ "${TESTJAVA}" = "" ] ; then - echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test." - exit 1 -fi -if [ "${COMPILEJAVA}" = "" ]; then - COMPILEJAVA="${TESTJAVA}" -fi - -runOne() -{ - echo "runOne $@" - $COMPILEJAVA/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d $TESTCLASSES \ - $TESTSRC/$@.java || exit 2 - $TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES $@ || exit 3 -} - -# Test GetMaxFileDescriptorCount if we are running on Unix -case `uname -s` in - Linux ) - runOne GetMaxFileDescriptorCount - ;; - * ) - echo "Ignore test when not run on Linux" - exit 0 - ;; -esac - -exit 0 diff --git a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.java b/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.java index 9f3a066c9a2..ab17c2123cd 100644 --- a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.java +++ b/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.java @@ -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 @@ -22,17 +22,13 @@ */ /* + * @test * @bug 4858522 * @summary Basic unit test of UnixOperatingSystemMXBean.getOpenFileDescriptorCount() * @author Steve Bohne - */ - -/* - * This test is just a sanity check and does not check for the correct - * value. The correct value should be checked manually: - * Solaris/Linux: - * 1. Find the pid of the java process. - * 2. In a shell, enter the command: "ls -1 /proc//fd | wc -l" + * @requires os.family != "windows" + * + * @run main GetOpenFileDescriptorCount */ import com.sun.management.UnixOperatingSystemMXBean; @@ -41,36 +37,27 @@ import java.lang.management.*; public class GetOpenFileDescriptorCount { private static UnixOperatingSystemMXBean mbean = - (UnixOperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean(); + (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); - // Careful with these values. private static final long MIN_COUNT_FOR_PASS = 1; - // Max count for pass dynamically determined below - private static long max_count_for_pass = Long.MAX_VALUE; - - private static boolean trace = false; + private static long maxCountForPass = Long.MAX_VALUE; public static void main(String args[]) throws Exception { - if (args.length > 0 && args[0].equals("trace")) { - trace = true; - } - long max_count = mbean.getMaxFileDescriptorCount(); - if (max_count > 0) { - max_count_for_pass = max_count; + long maxCount = mbean.getMaxFileDescriptorCount(); + if (maxCount > 0) { + maxCountForPass = maxCount; } long count = mbean.getOpenFileDescriptorCount(); - if (trace) { - System.out.println("Open file descriptor count: " + count); - } + System.out.println("Open file descriptor count: " + count); - if (count < MIN_COUNT_FOR_PASS || count > max_count_for_pass) { + if (count < MIN_COUNT_FOR_PASS || count > maxCountForPass) { throw new RuntimeException("Open file descriptor count " + "illegal value: " + count + " bytes " + "(MIN = " + MIN_COUNT_FOR_PASS + "; " + - "MAX = " + max_count_for_pass + ")"); + "MAX = " + maxCountForPass + ")"); } System.out.println("Test passed."); diff --git a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.sh b/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.sh deleted file mode 100644 index cd2081a54d6..00000000000 --- a/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetOpenFileDescriptorCount.sh +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright (c) 2003, 2020, 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 -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# - -# -# @test -# @bug 4858522 -# @summary -# @author Steve Bohne -# -# @run shell GetOpenFileDescriptorCount.sh -# - -if [ "${TESTJAVA}" = "" ] ; then - echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test." - exit 1 -fi -if [ "${COMPILEJAVA}" = "" ]; then - COMPILEJAVA="${TESTJAVA}" -fi -runOne() -{ - echo "runOne $@" - $COMPILEJAVA/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d $TESTCLASSES \ - $TESTSRC/$@.java || exit 2 - $TESTJAVA/bin/java ${TESTVMOPTS} -classpath $TESTCLASSES $@ || exit 3 -} - -# Test GetOpenFileDescriptorCount if we are running on Unix -case `uname -s` in - Linux ) - runOne GetOpenFileDescriptorCount - ;; - * ) - echo "Ignore test when not run on Linux" - exit 0 - ;; -esac - -exit 0