Path: blob/master/test/jdk/java/net/Socket/asyncClose/AsyncClose.java
41153 views
/*1* Copyright (c) 2001, 2019, 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*/2223import java.util.ArrayList;24import java.util.List;25import java.util.concurrent.CompletableFuture;26import jdk.test.lib.net.IPSupport;27import static java.util.concurrent.CompletableFuture.*;2829/*30* @test31* @bug 434413532* @library /test/lib33* @summary Check that {Socket,ServerSocket,DatagramSocket}.close will34* cause any thread blocked on the socket to throw a SocketException.35* @run main AsyncClose36* @run main/othervm -Djava.net.preferIPv4Stack=true AsyncClose37* @run main/othervm -Djdk.net.usePlainSocketImpl AsyncClose38*/3940public class AsyncClose {4142public static void main(String args[]) throws Exception {43IPSupport.throwSkippedExceptionIfNonOperational();4445AsyncCloseTest tests[] = {46new Socket_getInputStream_read(),47new Socket_getInputStream_read(20000),48new Socket_getOutputStream_write(),49new DatagramSocket_receive(),50new DatagramSocket_receive(20000),51new ServerSocket_accept(),52new ServerSocket_accept(20000),53};5455int failures = 0;5657List<CompletableFuture<AsyncCloseTest>> cfs = new ArrayList<>();58for (AsyncCloseTest test : tests)59cfs.add( supplyAsync(() -> test.go()));6061for (CompletableFuture<AsyncCloseTest> cf : cfs) {62AsyncCloseTest test = cf.get();6364System.out.println("******************************");65System.out.println("Test: " + test.description());66if (test.hasPassed()) {67System.out.println("Passed.");68} else {69System.out.println("Failed: " + test.failureReason());70failures++;71}72System.out.println("");73}7475if (failures > 0)76throw new Exception(failures + " sub-tests failed - see log.");77}78}798081