jdk/test/java/nio/channels/Selector/LotsOfChannels.java
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25  * @bug 4503092
       
    26  * @summary Tests that Windows Selector can use more than 63 channels
       
    27  * @run main/timeout=300 LotsOfChannels
       
    28  * @author kladko
       
    29  */
       
    30 
       
    31 import java.net.*;
       
    32 import java.io.*;
       
    33 import java.nio.*;
       
    34 import java.nio.channels.*;
       
    35 
       
    36 public class LotsOfChannels {
       
    37 
       
    38     private final static int PIPES_COUNT = 1900;
       
    39     private final static int BUF_SIZE = 8192;
       
    40     private final static int LOOPS = 10;
       
    41 
       
    42     public static void main(String[] argv) throws Exception {
       
    43 
       
    44 
       
    45         String os = System.getProperty("os.name");
       
    46         if (!(os.equals("Windows NT")
       
    47            || os.equals("Windows 2000")
       
    48            || os.equals("Windows XP")))
       
    49             return;
       
    50 
       
    51         Pipe[] pipes = new Pipe[PIPES_COUNT];
       
    52         Pipe pipe = Pipe.open();
       
    53         Pipe.SinkChannel sink = pipe.sink();
       
    54         Pipe.SourceChannel source = pipe.source();
       
    55         Selector sel = Selector.open();
       
    56         source.configureBlocking(false);
       
    57         source.register(sel, SelectionKey.OP_READ);
       
    58 
       
    59         for (int i = 0; i< PIPES_COUNT; i++ ) {
       
    60             pipes[i]= Pipe.open();
       
    61             Pipe.SourceChannel sc = pipes[i].source();
       
    62             sc.configureBlocking(false);
       
    63             sc.register(sel, SelectionKey.OP_READ);
       
    64             Pipe.SinkChannel sc2 = pipes[i].sink();
       
    65             sc2.configureBlocking(false);
       
    66             sc2.register(sel, SelectionKey.OP_WRITE);
       
    67         }
       
    68 
       
    69         for (int i = 0 ; i < LOOPS; i++ ) {
       
    70             sink.write(ByteBuffer.allocate(BUF_SIZE));
       
    71             int x = sel.selectNow();
       
    72             sel.selectedKeys().clear();
       
    73             source.read(ByteBuffer.allocate(BUF_SIZE));
       
    74         }
       
    75         sel.close();
       
    76     }
       
    77 }