8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC
authordfuchs
Thu, 28 Nov 2019 12:28:48 +0000
changeset 59305 219ec11136d9
parent 59304 643d9cf3d8fc
child 59306 bdf999e08a3a
8223196: java/nio/channels/spi/SelectorProvider/inheritedChannel/InheritedChannelTest.java fails on Solaris SPARC Summary: The test is fixed to use InetAddress.getLocalHost consistently, instead of a mix of getLocalHost/wildcard addresses. Reviewed-by: chegar, vtewari
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java
test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/StateTest.java
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java	Thu Nov 28 12:05:02 2019 +0100
+++ b/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/Launcher.java	Thu Nov 28 12:28:48 2019 +0000
@@ -1,3 +1,4 @@
+
 /*
  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -91,7 +92,7 @@
      */
     public static SocketChannel launchWithSocketChannel(String className, String options[], String args[]) throws IOException {
         ServerSocketChannel ssc = ServerSocketChannel.open();
-        ssc.socket().bind(new InetSocketAddress(0));
+        ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
         InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(),
                                                       ssc.socket().getLocalPort());
         SocketChannel sc1 = SocketChannel.open(isa);
@@ -120,7 +121,7 @@
         throws IOException
     {
         ServerSocketChannel ssc = ServerSocketChannel.open();
-        ssc.socket().bind(new InetSocketAddress(0));
+        ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
         int port = ssc.socket().getLocalPort();
         launch(className, options, args, Util.getFD(ssc));
         ssc.close();
@@ -147,18 +148,18 @@
     public static DatagramChannel launchWithDatagramChannel(String className, String options[], String args[])
         throws IOException
     {
+        InetAddress address = InetAddress.getLocalHost();
+        if (address.isLoopbackAddress()) {
+            address = InetAddress.getLoopbackAddress();
+        }
         DatagramChannel dc = DatagramChannel.open();
-        dc.socket().bind(new InetSocketAddress(0));
+        dc.socket().bind(new InetSocketAddress(address, 0));
 
         int port = dc.socket().getLocalPort();
         launch(className, options, args, Util.getFD(dc));
         dc.close();
 
         dc = DatagramChannel.open();
-        InetAddress address = InetAddress.getLocalHost();
-        if (address.isLoopbackAddress()) {
-            address = InetAddress.getLoopbackAddress();
-        }
         InetSocketAddress isa = new InetSocketAddress(address, port);
 
         dc.connect(isa);
--- a/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/StateTest.java	Thu Nov 28 12:05:02 2019 +0100
+++ b/test/jdk/java/nio/channels/spi/SelectorProvider/inheritedChannel/StateTest.java	Thu Nov 28 12:28:48 2019 +0000
@@ -35,6 +35,7 @@
  */
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.SelectionKey;
@@ -66,6 +67,7 @@
         /*
          * Wait for service to connect
          */
+        System.err.println("Waiting for the service to connect");
         ssc.configureBlocking(false);
         sk = ssc.register(sel, SelectionKey.OP_ACCEPT);
         long to = Utils.adjustTimeout(15*1000);
@@ -89,6 +91,7 @@
         /*
          * Wait for service to report test result
          */
+        System.err.println("Waiting for the service to report test result");
         sc.configureBlocking(false);
         sk = sc.register(sel, SelectionKey.OP_READ);
         to = Utils.adjustTimeout(5000);
@@ -111,6 +114,7 @@
                 throw new IOException("Timed out waiting for service to report test result");
             }
         }
+        System.err.println("Cleaning up");
         sk.cancel();
         sc.close();
         sel.close();
@@ -118,6 +122,7 @@
         /*
          * Examine the test result
          */
+        System.err.println("Examine test result");
         bb.flip();
         byte b = bb.get();
 
@@ -152,7 +157,8 @@
          * from the service.
          */
         ServerSocketChannel ssc = ServerSocketChannel.open();
-        ssc.socket().bind(new InetSocketAddress(0));
+        ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
+        System.err.println("Listener bound to: " + ssc.socket().getLocalSocketAddress());
 
         /*
          * The port is passed to the service as an argument.
@@ -164,7 +170,9 @@
         /*
          * Launch service with a SocketChannel (tcp nowait)
          */
+        System.err.println("launchWithSocketChannel");
         SocketChannel sc = Launcher.launchWithSocketChannel(TEST_SERVICE, options, arg);
+        System.err.println("Waiting for test results");
         waitForTestResult(ssc, expectFail);
         sc.close();
 
@@ -173,6 +181,7 @@
          * launchWithServerSocketChannel establishes a connection to the service
          * and the returned SocketChannel is connected to the service.
          */
+        System.err.println("launchWithServerSocketChannel");
         sc = Launcher.launchWithServerSocketChannel(TEST_SERVICE, options, arg);
         waitForTestResult(ssc, expectFail);
         sc.close();
@@ -180,10 +189,12 @@
         /*
          * Launch service with a DatagramChannel (udp wait)
          */
+        System.err.println("launchWithDatagramChannel");
         DatagramChannel dc = Launcher.launchWithDatagramChannel(TEST_SERVICE, options, arg);
         waitForTestResult(ssc, expectFail);
         dc.close();
 
+        System.err.println("done");
         if (failures > 0) {
             throw new RuntimeException("Test failed - see log for details");
         } else {