Code Review Request: 7044870: TEST_BUG: java/nio/channels/DatagramChannel/SelectWhenRefused.java failed on SUSE Linux 10

Chris Hegarty chris.hegarty at oracle.com
Tue Aug 23 08:08:09 PDT 2011


Hi Kurchi,

I see your change is checking if another service is using the expected 
refuser port, and then ignoring any data since the test cannot be 
successfully run. I think this is good, but it may also be useful to 
defer closing of dc1 until after creation of dc. That way this issue 
shouldn't happen as often since dc will not reuse the refusers port. 
Make sense? Also, doesn't this impact on the rest of the test too?

Would just catch BindException be sufficient? That's what you're 
expecting, right, "Address already in use"?

-Chris.

On 23/08/2011 01:29, Kurchi Hazra wrote:
> 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,
>


More information about the nio-dev mailing list