Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/net/www/http/HttpClient/IsAvailable.java
38867 views
/*1* Copyright (c) 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/*24* @test25* @bug 800965026* @summary HttpClient available() check throws SocketException when connection27* has been closed28*/2930import java.net.URL;31import java.net.ServerSocket;32import sun.net.www.http.HttpClient;33import java.security.*;34import java.lang.reflect.Method;3536public class IsAvailable {3738public static void main(String[] args) throws Exception {39int readTimeout = 20;40ServerSocket ss = new ServerSocket(0);4142URL url1 = new URL("http://localhost:" + ss.getLocalPort());43HttpClient c1 = HttpClient.New(url1);4445Method available = HttpClient.class.46getDeclaredMethod("available", null);47available.setAccessible(true);4849c1.setReadTimeout(readTimeout);50boolean a = (boolean) available.invoke(c1);51if (!a) {52throw new RuntimeException("connection should be available");53}54if (c1.getReadTimeout() != readTimeout) {55throw new RuntimeException("read timeout has been altered");56}5758c1.closeServer();5960a = (boolean) available.invoke(c1);61if (a) {62throw new RuntimeException("connection shouldn't be available");63}6465ss.close();66}67}686970