Path: blob/master/test/jdk/java/nio/channels/Selector/LotsOfChannels.java
41153 views
/*1* Copyright (c) 2002, 2021, 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 4503092 802488325* @summary Tests that Windows Selector can use more than 63 channels26* @run main LotsOfChannels27* @run main/othervm -Dsun.nio.ch.maxUpdateArraySize=64 LotsOfChannels28* @author kladko29*/3031/* @test32* @requires (os.family == "windows")33* @run main/othervm -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.WindowsSelectorProvider LotsOfChannels34*/3536import java.net.*;37import java.io.*;38import java.nio.*;39import java.nio.channels.*;4041public class LotsOfChannels {4243private final static int PIPES_COUNT = 256;44private final static int BUF_SIZE = 8192;45private final static int LOOPS = 10;4647public static void main(String[] argv) throws Exception {48Pipe[] pipes = new Pipe[PIPES_COUNT];49Pipe pipe = Pipe.open();50Pipe.SinkChannel sink = pipe.sink();51Pipe.SourceChannel source = pipe.source();52Selector sel = Selector.open();53source.configureBlocking(false);54source.register(sel, SelectionKey.OP_READ);5556for (int i = 0; i< PIPES_COUNT; i++ ) {57pipes[i]= Pipe.open();58Pipe.SourceChannel sc = pipes[i].source();59sc.configureBlocking(false);60sc.register(sel, SelectionKey.OP_READ);61Pipe.SinkChannel sc2 = pipes[i].sink();62sc2.configureBlocking(false);63sc2.register(sel, SelectionKey.OP_WRITE);64}6566for (int i = 0 ; i < LOOPS; i++ ) {67sink.write(ByteBuffer.allocate(BUF_SIZE));68int x = sel.selectNow();69sel.selectedKeys().clear();70source.read(ByteBuffer.allocate(BUF_SIZE));71}7273for (int i = 0; i < PIPES_COUNT; i++ ) {74pipes[i].sink().close();75pipes[i].source().close();76}77pipe.sink().close();78pipe.source().close();79sel.close();80}81}828384