8130657: com/sun/net/httpserver/Test5.java failed with java.lang.RuntimeException: wrong string result

8085575: java/net/Socket/InheritHandle.java fails intermittently with "Address already in use"

Reviewed-by: dfuchs
This commit is contained in:
Felix Yang 2016-09-26 08:19:07 -07:00
parent d427383905
commit 2d35d5bfc3
3 changed files with 41 additions and 24 deletions
jdk/test
com/sun/net/httpserver
java/net

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2016, 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
@ -145,6 +145,7 @@ public class Test5 extends Test {
socket.close();
s = new String (b,0,count, "ISO8859_1");
if (!compare (s, result)) {
System.err.println(" Expected [" + result + "]\n actual [" + s + "]");
throw new RuntimeException ("wrong string result");
}
}

@ -37,26 +37,27 @@ public class TimeToLive {
static int[] bad_ttls = { -1, 256 };
public static void main(String[] args) throws Exception {
MulticastSocket socket = new MulticastSocket();
int ttl = socket.getTimeToLive();
System.out.println("default ttl: " + ttl);
for (int i = 0; i < new_ttls.length; i++) {
socket.setTimeToLive(new_ttls[i]);
if (!(new_ttls[i] == socket.getTimeToLive())) {
throw new RuntimeException("test failure, set/get differ: " +
new_ttls[i] + " / " +
socket.getTimeToLive());
try (MulticastSocket socket = new MulticastSocket()) {
int ttl = socket.getTimeToLive();
System.out.println("default ttl: " + ttl);
for (int i = 0; i < new_ttls.length; i++) {
socket.setTimeToLive(new_ttls[i]);
if (!(new_ttls[i] == socket.getTimeToLive())) {
throw new RuntimeException("test failure, set/get differ: " +
new_ttls[i] + " / " +
socket.getTimeToLive());
}
}
}
for (int j = 0; j < bad_ttls.length; j++) {
boolean exception = false;
try {
socket.setTimeToLive(bad_ttls[j]);
} catch (IllegalArgumentException e) {
exception = true;
}
if (!exception) {
throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
for (int j = 0; j < bad_ttls.length; j++) {
boolean exception = false;
try {
socket.setTimeToLive(bad_ttls[j]);
} catch (IllegalArgumentException e) {
exception = true;
}
if (!exception) {
throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
}
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2016, 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
@ -27,6 +27,7 @@
@author Chris Hegarty
*/
import java.net.BindException;
import java.net.ServerSocket;
import java.io.File;
import java.io.IOException;
@ -74,6 +75,11 @@ public class InheritHandle
} catch (IOException ioe) {
System.out.println("Cannot create process");
ioe.printStackTrace();
try {
ss.close();
} catch (IOException e) {
e.printStackTrace();
}
return;
}
@ -85,9 +91,18 @@ public class InheritHandle
System.out.println("Now close the socket and try to create another" +
" one listening on the same port");
ss.close();
ss = new ServerSocket(port);
System.out.println("Second ServerSocket created successfully");
ss.close();
int retries = 0;
while (retries < 5) {
try (ServerSocket s = new ServerSocket(port);) {
System.out.println("Second ServerSocket created successfully");
break;
} catch (BindException e) {
System.out.println("BindException \"" + e.getMessage() + "\", retrying...");
Thread.sleep(100L);
retries ++;
continue;
}
}
} catch (InterruptedException ie) {
} catch (IOException ioe) {