Path: blob/master/test/jdk/java/nio/channels/Selector/Close.java
41153 views
/*1* Copyright (c) 2002, 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 474405225* @summary Test for keys remaining in selector after channel closed26*/2728import java.nio.*;29import java.nio.channels.*;3031public class Close {3233public static void main(String args[]) throws Exception {34Selector sa = Selector.open();35Selector sb = Selector.open();36SocketChannel sc = SocketChannel.open();37sc.configureBlocking(false);38SelectionKey sk = sc.register(sa, SelectionKey.OP_READ);39sc.register(sb, SelectionKey.OP_READ);40sc.keyFor(sa).cancel();41sa.select(1);42sc.close();43sa.select(1);44sb.select(1);45if (sa.keys().size() > 0)46throw new RuntimeException("Keys remain in selector a");47if (sb.keys().size() > 0)48throw new RuntimeException("Keys remain in selector b");49sa.close();50sb.close();51}52}535455