Path: blob/master/test/jdk/com/sun/management/UnixOperatingSystemMXBean/GetMaxFileDescriptorCount.java
41154 views
/*1* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24*25* @bug 485852226* @summary Basic unit test of UnixOperatingSystemMXBean.getMaxFileDescriptorCount()27* @author Steve Bohne28*/2930/*31* This test is just a sanity check and does not check for the correct32* value. The correct value should be checked manually:33* Solaris/Linux:34* 1. In a shell, as user who started java process, enter the command35* "limit -h descriptors"36*/3738import com.sun.management.UnixOperatingSystemMXBean;39import java.lang.management.*;4041public class GetMaxFileDescriptorCount {4243private static UnixOperatingSystemMXBean mbean =44(UnixOperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();4546// Careful with these values.47// Min count for pass dynamically determined below.48private static long min_count_for_pass = 1;49private static final long MAX_COUNT_FOR_PASS = Long.MAX_VALUE;5051private static boolean trace = false;5253public static void main(String args[]) throws Exception {54if (args.length > 0 && args[0].equals("trace")) {55trace = true;56}5758long min_count = mbean.getOpenFileDescriptorCount();59if (min_count > 0) {60min_count_for_pass = min_count;61}6263long count = mbean.getMaxFileDescriptorCount();6465if (trace) {66System.out.println("Max file descriptor count: " + count);67}6869if (count < min_count_for_pass || count > MAX_COUNT_FOR_PASS) {70throw new RuntimeException("Max file descriptor count " +71"illegal value: " + count + " bytes " +72"(MIN = " + min_count_for_pass + "; " +73"MAX = " + MAX_COUNT_FOR_PASS + ")");74}7576System.out.println("Test passed.");77}78}798081