Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/channels/SocketChannel/Open.java
38828 views
/*1* Copyright (c) 2002, 2007, 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/* @test24* @bug 461406525* @summary Test SocketChannel gc after running out of fds26* @build Open27* @run shell Open.sh28*/2930import java.net.*;31import java.nio.*;32import java.nio.channels.*;33import java.nio.channels.spi.SelectorProvider;3435public class Open {3637static void test1() {38for (int i=0; i<11000; i++) {39try {40SocketChannel sc = SocketChannel.open();41} catch (Exception e) {42// Presumably "Too many open files"43}44}45}46static void test2() {47for (int i=0; i<11000; i++) {48try {49DatagramChannel sc = DatagramChannel.open();50} catch (Exception e) {51// Presumably "Too many open files"52}53}54}55static void test3() {56SelectorProvider sp = SelectorProvider.provider();57for (int i=0; i<11000; i++) {58try {59Pipe p = sp.openPipe();60} catch (Exception e) {61// Presumably "Too many open files"62}63}64}65static void test4() {66for (int i=0; i<11000; i++) {67try {68ServerSocketChannel sc = ServerSocketChannel.open();69} catch (Exception e) {70// Presumably "Too many open files"71}72}73}7475public static void main(String[] args) throws Exception {7677// Load necessary classes ahead of time78DatagramChannel dc = DatagramChannel.open();79Exception se = new SocketException();80SelectorProvider sp = SelectorProvider.provider();81Pipe p = sp.openPipe();82ServerSocketChannel ssc = ServerSocketChannel.open();8384test1();85test2();86test3();87test4();88}8990}919293