mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
8225430: Replace wildcard address with loopback or local host in tests - part 14
Reviewed-by: dfuchs, chegar, vtewari
This commit is contained in:
parent
9f7cbf60e4
commit
4312f54e51
12 changed files with 108 additions and 52 deletions
|
@ -30,6 +30,9 @@ import java.net.SocketException;
|
|||
/*
|
||||
* @test
|
||||
* @bug 8153674
|
||||
* @key intermittent
|
||||
* @summary This test might fail intermittently as it needs a UDP socket that
|
||||
* binds to the wildcard address.
|
||||
* @summary Expected SocketException not thrown when calling bind() with
|
||||
* setReuseAddress(false)
|
||||
* @run main/othervm ReuseAddressTest
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -36,13 +36,16 @@ import java.io.IOException;
|
|||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class SendSize {
|
||||
static final int bufferLength = 512;
|
||||
static final int packetLength = 256;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DatagramSocket serverSocket = new DatagramSocket();
|
||||
DatagramSocket serverSocket = new DatagramSocket(
|
||||
new InetSocketAddress(InetAddress.getLocalHost(), 0)
|
||||
);
|
||||
Thread server = new ServerThread(serverSocket);
|
||||
server.start();
|
||||
Thread client = new ClientThread(serverSocket.getLocalPort());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -31,9 +31,10 @@
|
|||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class ADatagramSocket {
|
||||
public static void main(String[] args) throws IOException {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// testing out setDatagramSocketImplFactory
|
||||
System.err.println("setting DatagramSocketImplFactory...");
|
||||
try {
|
||||
|
@ -46,6 +47,8 @@ public class ADatagramSocket {
|
|||
int port = server.getPort();
|
||||
System.out.println("Server port is " + port);
|
||||
server.start();
|
||||
// Wait server thread to reach receive call
|
||||
server.readyToStart.await();
|
||||
|
||||
// get a datagram socket
|
||||
DatagramSocket socket = new DatagramSocket();
|
||||
|
@ -72,6 +75,7 @@ class QuoteServerThread extends Thread {
|
|||
|
||||
protected DatagramSocket socket = null;
|
||||
private final int port;
|
||||
final CountDownLatch readyToStart = new CountDownLatch(1);
|
||||
|
||||
public QuoteServerThread() throws IOException {
|
||||
this("QuoteServerThread");
|
||||
|
@ -79,7 +83,7 @@ class QuoteServerThread extends Thread {
|
|||
|
||||
public QuoteServerThread(String name) throws IOException {
|
||||
super(name);
|
||||
socket = new DatagramSocket(0);
|
||||
socket = new DatagramSocket(0, InetAddress.getLocalHost());
|
||||
port = socket.getLocalPort();
|
||||
}
|
||||
public int getPort(){
|
||||
|
@ -92,6 +96,8 @@ class QuoteServerThread extends Thread {
|
|||
|
||||
// receive request
|
||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||
// Notify client that server is ready to receive packet
|
||||
readyToStart.countDown();
|
||||
socket.receive(packet);
|
||||
|
||||
// figure out response
|
||||
|
|
|
@ -26,8 +26,11 @@
|
|||
*
|
||||
* @test
|
||||
* @bug 6368984
|
||||
* @key intermittent
|
||||
* @summary Configuring unconnected Socket before passing to implAccept
|
||||
* can cause fd leak
|
||||
* can cause fd leak.
|
||||
* This test may fail intermittently if foreign processes will
|
||||
* try to establish connection to the test server socket.
|
||||
* @requires (os.family != "windows")
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.Utils
|
||||
|
@ -43,6 +46,7 @@
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
|
@ -82,7 +86,7 @@ public class AcceptCauseFileDescriptorLeak {
|
|||
}
|
||||
}
|
||||
|
||||
final ServerSocket ss = new ServerSocket(0, 0, InetAddress.getLoopbackAddress()) {
|
||||
final ServerSocket ss = new ServerSocket() {
|
||||
public Socket accept() throws IOException {
|
||||
Socket s = new Socket() {
|
||||
};
|
||||
|
@ -91,23 +95,29 @@ public class AcceptCauseFileDescriptorLeak {
|
|||
return s;
|
||||
}
|
||||
};
|
||||
ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
int repsCompleted = 0;
|
||||
try {
|
||||
for (int i = 0; i < REPS; i++) {
|
||||
for (; repsCompleted < REPS; repsCompleted++) {
|
||||
(new Socket(InetAddress.getLoopbackAddress(), ss.getLocalPort())).close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
System.out.println("Client iterations completed:" + repsCompleted);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
int repsCompleted = 0;
|
||||
try {
|
||||
for (int i = 0; i < REPS; i++) {
|
||||
for (; repsCompleted < REPS; repsCompleted++) {
|
||||
ss.accept().close();
|
||||
}
|
||||
} finally {
|
||||
System.out.println("Server iterations completed:" + repsCompleted);
|
||||
ss.close();
|
||||
}
|
||||
t.join();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -36,7 +36,10 @@ public class NullHost {
|
|||
|
||||
public Server() throws IOException {
|
||||
svr = new ServerSocket();
|
||||
svr.bind(new InetSocketAddress(0));
|
||||
// The client side calls Socket((String) null, ...) which
|
||||
// resolves to InetAddress.getByName((String)null) which in
|
||||
// turns will resolve to the loopback address
|
||||
svr.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -64,12 +64,14 @@ public class ProxyCons {
|
|||
}
|
||||
|
||||
void test() throws Exception {
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
ServerSocket ss = new ServerSocket();
|
||||
ss.bind(new InetSocketAddress(localHost, 0));
|
||||
try {
|
||||
Server s = new Server(ss);
|
||||
s.start();
|
||||
Socket sock = new Socket(Proxy.NO_PROXY);
|
||||
sock.connect(new InetSocketAddress("localhost", ss.getLocalPort()));
|
||||
sock.connect(new InetSocketAddress(localHost, ss.getLocalPort()));
|
||||
s.done();
|
||||
sock.close();
|
||||
} catch (java.io.IOException e) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -53,7 +53,9 @@ public class SocksConnectTimeout {
|
|||
IPSupport.throwSkippedExceptionIfNonOperational();
|
||||
|
||||
try {
|
||||
serverSocket = new ServerSocket(0);
|
||||
serverSocket = new ServerSocket();
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
serverSocket.bind(new InetSocketAddress(localHost, 0));
|
||||
|
||||
(new Thread() {
|
||||
@Override
|
||||
|
@ -61,7 +63,7 @@ public class SocksConnectTimeout {
|
|||
}).start();
|
||||
|
||||
Proxy socksProxy = new Proxy(Proxy.Type.SOCKS,
|
||||
new InetSocketAddress(InetAddress.getLocalHost(), serverSocket.getLocalPort()));
|
||||
new InetSocketAddress(localHost, serverSocket.getLocalPort()));
|
||||
|
||||
test(socksProxy);
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -44,9 +44,11 @@ public class TestClose {
|
|||
InetAddress ad1, ad2;
|
||||
int port1, port2, serverport;
|
||||
|
||||
ss = new ServerSocket(0);
|
||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||
ss = new ServerSocket();
|
||||
ss.bind(new InetSocketAddress(loopback, 0));
|
||||
serverport = ss.getLocalPort();
|
||||
s = new Socket("localhost", serverport);
|
||||
s = new Socket(loopback, serverport);
|
||||
s.close();
|
||||
ss.close();
|
||||
ad1 = ss.getInetAddress();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,24 +25,29 @@
|
|||
* @test
|
||||
* @bug 4151665
|
||||
* @modules jdk.httpserver
|
||||
* @library /test/lib
|
||||
* @summary Test for FileNotFoundException when loading bogus class
|
||||
*/
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
|
||||
public class ClassLoad {
|
||||
public static void main(String[] args) throws Exception {
|
||||
boolean error = true;
|
||||
|
||||
// Start a dummy server to return 404
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
|
||||
HttpServer server = HttpServer.create();
|
||||
server.bind(new InetSocketAddress(
|
||||
InetAddress.getLoopbackAddress(), 0), 0);
|
||||
HttpHandler handler = new HttpHandler() {
|
||||
public void handle(HttpExchange t) throws IOException {
|
||||
InputStream is = t.getRequestBody();
|
||||
|
@ -56,7 +61,11 @@ public class ClassLoad {
|
|||
|
||||
// Client request
|
||||
try {
|
||||
URL url = new URL("http://localhost:" + server.getAddress().getPort());
|
||||
URL url = URIBuilder.newBuilder()
|
||||
.scheme("http")
|
||||
.loopback()
|
||||
.port(server.getAddress().getPort())
|
||||
.toURL();
|
||||
String name = args.length >= 2 ? args[1] : "foo.bar.Baz";
|
||||
ClassLoader loader = new URLClassLoader(new URL[] { url });
|
||||
System.out.println(url);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -168,7 +168,9 @@ public class CloseTest extends Common {
|
|||
}
|
||||
|
||||
static void startHttpServer(String docroot) throws Exception {
|
||||
httpServer = HttpServer.create(new InetSocketAddress(0), 10);
|
||||
httpServer = HttpServer.create(
|
||||
new InetSocketAddress(InetAddress.getLoopbackAddress(), 0),
|
||||
10);
|
||||
HttpContext ctx = httpServer.createContext(
|
||||
"/", new FileServerHandler(docroot)
|
||||
);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -24,8 +24,9 @@
|
|||
/*
|
||||
* @test
|
||||
* @bug 4160200
|
||||
* @summary Make sure URLConnection.getContnentHandler
|
||||
* @summary Make sure URLConnection.getContentHandler
|
||||
* can handle MIME types with attributes
|
||||
* @library /test/lib
|
||||
* @modules java.base/sun.net.www java.base/sun.net.www.content.text
|
||||
*/
|
||||
import java.net.*;
|
||||
|
@ -34,6 +35,8 @@ import sun.net.www.content.text.*;
|
|||
import sun.net.www.MessageHeader;
|
||||
import static java.net.Proxy.NO_PROXY;
|
||||
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
|
||||
public class HandleContentTypeWithAttrs {
|
||||
|
||||
URL url;
|
||||
|
@ -43,7 +46,12 @@ public class HandleContentTypeWithAttrs {
|
|||
// Request echo.html from myHttpServer.
|
||||
// In the header of the response, we make
|
||||
// the content type have some attributes.
|
||||
url = new URL("http://localhost:" + port + "/echo.html");
|
||||
url = URIBuilder.newBuilder()
|
||||
.scheme("http")
|
||||
.loopback()
|
||||
.port(port)
|
||||
.path("/echo.html")
|
||||
.toURL();
|
||||
URLConnection urlConn = url.openConnection(NO_PROXY);
|
||||
|
||||
// the method getContent() calls the method
|
||||
|
@ -135,7 +143,8 @@ class myHttpServer implements Runnable, Cloneable {
|
|||
/** Start a server on port <i>port</i>. It will call serviceRequest()
|
||||
for each new connection. */
|
||||
final public void startServer(int port) throws IOException {
|
||||
serverSocket = new ServerSocket(port, 50);
|
||||
serverSocket = new ServerSocket(port, 50,
|
||||
InetAddress.getLoopbackAddress());
|
||||
serverInstance = new Thread(this);
|
||||
serverInstance.start();
|
||||
}
|
||||
|
@ -219,10 +228,13 @@ class myHttpServer implements Runnable, Cloneable {
|
|||
|
||||
public myHttpServer () {
|
||||
try {
|
||||
defaultContext
|
||||
= new URL("http", InetAddress.getLocalHost().getHostName(), "/");
|
||||
defaultContext = URIBuilder.newBuilder()
|
||||
.scheme("http")
|
||||
.loopback()
|
||||
.path("/")
|
||||
.toURL();
|
||||
} catch(Exception e) {
|
||||
System.out.println("Failed to construct defauit URL context: "
|
||||
System.out.println("Failed to construct default URL context: "
|
||||
+ e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -35,11 +35,12 @@
|
|||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import jdk.test.lib.net.URIBuilder;
|
||||
|
||||
class RedirLimitServer extends Thread {
|
||||
static final int TIMEOUT = 10 * 1000;
|
||||
static final int TIMEOUT = 20 * 1000;
|
||||
static final int NUM_REDIRECTS = 9;
|
||||
|
||||
static final String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
|
||||
|
@ -59,6 +60,7 @@ class RedirLimitServer extends Thread {
|
|||
|
||||
final ServerSocket ss;
|
||||
final int port;
|
||||
final CountDownLatch readyToStart = new CountDownLatch(1);
|
||||
|
||||
RedirLimitServer(ServerSocket ss) throws IOException {
|
||||
this.ss = ss;
|
||||
|
@ -85,6 +87,7 @@ class RedirLimitServer extends Thread {
|
|||
|
||||
public void run() {
|
||||
try {
|
||||
readyToStart.countDown();
|
||||
for (int i=0; i<NUM_REDIRECTS; i++) {
|
||||
try (Socket s = ss.accept()) {
|
||||
s.setSoTimeout(TIMEOUT);
|
||||
|
@ -100,33 +103,32 @@ class RedirLimitServer extends Thread {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { ss.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public class RedirectLimit {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ServerSocket ss = new ServerSocket(0, 0, InetAddress.getLoopbackAddress());
|
||||
int port = ss.getLocalPort();
|
||||
RedirLimitServer server = new RedirLimitServer(ss);
|
||||
server.start();
|
||||
try (ServerSocket ss = new ServerSocket(0, 0, InetAddress.getLoopbackAddress())) {
|
||||
int port = ss.getLocalPort();
|
||||
RedirLimitServer server = new RedirLimitServer(ss);
|
||||
server.start();
|
||||
server.readyToStart.await();
|
||||
URL url = URIBuilder.newBuilder()
|
||||
.scheme("http")
|
||||
.loopback()
|
||||
.port(port)
|
||||
.toURL();
|
||||
URLConnection conURL = url.openConnection(Proxy.NO_PROXY);
|
||||
|
||||
URL url = URIBuilder.newBuilder()
|
||||
.scheme("http")
|
||||
.loopback()
|
||||
.port(port)
|
||||
.toURL();
|
||||
URLConnection conURL = url.openConnection();
|
||||
conURL.setDoInput(true);
|
||||
conURL.setAllowUserInteraction(false);
|
||||
conURL.setUseCaches(false);
|
||||
|
||||
conURL.setDoInput(true);
|
||||
conURL.setAllowUserInteraction(false);
|
||||
conURL.setUseCaches(false);
|
||||
|
||||
try (InputStream in = conURL.getInputStream()) {
|
||||
if ((in.read() != (int)'W') || (in.read()!=(int)'o')) {
|
||||
throw new RuntimeException("Unexpected string read");
|
||||
try (InputStream in = conURL.getInputStream()) {
|
||||
if ((in.read() != (int) 'W') || (in.read() != (int) 'o')) {
|
||||
throw new RuntimeException("Unexpected string read");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue