Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/channels/Selector/SelectorLimit.java
38828 views
/*1* Copyright (c) 2002, 2013, 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 4777504 802488325* @summary Ensure that a Selector can return at least 100 selected keys26* @author Mark Reinhold27* @library ..28* @build SelectorLimit29* @run main/othervm SelectorLimit30* @run main/othervm -Dsun.nio.ch.maxUpdateArraySize=128 SelectorLimit31*/3233import java.io.*;34import java.net.*;35import java.nio.*;36import java.nio.channels.*;37import java.util.*;383940public class SelectorLimit {4142static PrintStream log = System.err;4344static class Listener45extends TestThread46{47volatile int count = 0;48private ServerSocketChannel ssc;4950Listener(ServerSocketChannel ssc) {51super("Listener");52this.ssc = ssc;53}5455void go() throws IOException {56for (;;) {57ssc.accept();58count++;59}60}6162}6364static final int N_KEYS = 500;65static final int MIN_KEYS = 100;6667public static void main(String[] args) throws Exception {68// win9X can't handle many connections at once69String osName = System.getProperty("os.name");70if (osName.toLowerCase().startsWith("win")) {71if (!(osName.equals("Windows NT")72|| osName.equals("Windows 2000")73|| osName.equals("Windows XP")))74return;75}7677ServerSocketChannel ssc = ServerSocketChannel.open();78TestUtil.bind(ssc);79Listener lth = new Listener(ssc);80lth.start();8182Selector sel = Selector.open();83SocketChannel[] sca = new SocketChannel[N_KEYS];84for (int i = 0; i < N_KEYS; i++) {85SocketChannel sc = SocketChannel.open();86sc.configureBlocking(false);87sc.register(sel, SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE);88sc.connect(ssc.socket().getLocalSocketAddress());89}9091for (int i = 0; i < 10; i++) {92if (lth.count >= MIN_KEYS)93break;94Thread.sleep(1000);95}96log.println(lth.count + " connections accepted");97Thread.sleep(500);9899int n = sel.select();100log.println(n + " keys selected");101if (n < MIN_KEYS)102throw new Exception("Only selected " + n + " keys");103104}105106}107108109