Code Review Request: 7044870: TEST_BUG: java/nio/channels/DatagramChannel/SelectWhenRefused.java failed on SUSE Linux 10
Kurchi Hazra
kurchi.subhra.hazra at oracle.com
Mon Aug 22 17:29:01 PDT 2011
Hi,
Test 1 in java/nio/channels/DatagramChannel/SelectWhenRefused.java
was failing on some Linux kernels. This is because the test assumes that
the kernel will not bind a socket to a port that has been closed
immediately.
However, some linux kernels (for example, 2.6.16.60-0.62.1-smp ) are
precisely doing this and the test throws a RunTime Exception.
The code has been changed to not to try binding the same socket that has
been immediately closed. In addition, we make sure that a port is not
bound to a service already (in between the port being closed before and
connected to later in the code) by checking before throwing the Exception.
Submitting hg diff since I do not have an openjdk account:
-bash-3.00$ hg diff
diff --git
a/test/java/nio/channels/DatagramChannel/SelectWhenRefused.java
b/test/java/nio/channels/DatagramChannel/SelectWhenRefused.java
--- a/test/java/nio/channels/DatagramChannel/SelectWhenRefused.java
+++ b/test/java/nio/channels/DatagramChannel/SelectWhenRefused.java
@@ -35,14 +35,14 @@ public class SelectWhenRefused {
public class SelectWhenRefused {
public static void main(String[] args) throws IOException {
- DatagramChannel dc = DatagramChannel.open().bind(new
InetSocketAddress(0));
- int port = dc.socket().getLocalPort();
- dc.close();
+ DatagramChannel dc1 = DatagramChannel.open().bind(new
InetSocketAddress(0));
+ int port = dc1.socket().getLocalPort();
+ dc1.close();
// datagram sent to this address should be refused
SocketAddress refuser = new
InetSocketAddress(InetAddress.getLocalHost(), port);
- dc = DatagramChannel.open().bind(new InetSocketAddress(0));
+ DatagramChannel dc = DatagramChannel.open().bind(new
InetSocketAddress(0));
Selector sel = Selector.open();
try {
dc.configureBlocking(false);
@@ -52,7 +52,15 @@ public class SelectWhenRefused {
sendDatagram(dc, refuser);
int n = sel.select(2000);
if (n > 0) {
+ try {
+ DatagramSocket dsBindCheck=new DatagramSocket(port);
+ dsBindCheck.close();
throw new RuntimeException("Unexpected wakeup");
+ }
+ catch(SocketException e)
+ {
+ //Do nothing,some other test may have used the port
+ }
}
/* Test 2: connected so ICMP port unreachable may be
received */
Thanks,
--
-Kurchi
More information about the nio-dev
mailing list