8171072: java/rmi/transport/handshake*/Handshake*.java, exception is not thrown when reach failure test case
authormli
Tue, 13 Dec 2016 17:40:53 -0800
changeset 42673 a77d756bf2f5
parent 42672 92a8c56354ab
child 42674 c4534cdc2384
8171072: java/rmi/transport/handshake*/Handshake*.java, exception is not thrown when reach failure test case Reviewed-by: rriggs
jdk/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java
jdk/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java
--- a/jdk/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java	Tue Dec 13 12:35:59 2016 -0800
+++ b/jdk/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java	Tue Dec 13 17:40:53 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -30,12 +30,10 @@
  * java.rmi.ConnectException or ConnectIOException, not a MarshalException.
  * @author Peter Jones
  *
- * @library ../../testlibrary
  * @modules java.rmi/sun.rmi.registry
  *          java.rmi/sun.rmi.server
  *          java.rmi/sun.rmi.transport
  *          java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary
  * @run main/othervm HandshakeFailure
  */
 
@@ -49,7 +47,6 @@
 
 public class HandshakeFailure {
 
-    private static final int PORT = TestLibrary.getUnusedRandomPort();
     private static final int TIMEOUT = 10000;
 
     public static void main(String[] args) throws Exception {
@@ -57,12 +54,13 @@
         /*
          * Listen on port...
          */
-        ServerSocket serverSocket = new ServerSocket(PORT);
+        ServerSocket serverSocket = new ServerSocket(0);
+        int port = serverSocket.getLocalPort();
 
         /*
          * (Attempt RMI call to port in separate thread.)
          */
-        Registry registry = LocateRegistry.getRegistry(PORT);
+        Registry registry = LocateRegistry.getRegistry(port);
         Connector connector = new Connector(registry);
         Thread t = new Thread(connector);
         t.setDaemon(true);
@@ -93,7 +91,7 @@
                 System.err.println();
 
                 if (connector.exception instanceof MarshalException) {
-                    System.err.println(
+                    throw new RuntimeException(
                         "TEST FAILED: MarshalException thrown, expecting " +
                         "java.rmi.ConnectException or ConnectIOException");
                 } else if (connector.exception instanceof ConnectException ||
--- a/jdk/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java	Tue Dec 13 12:35:59 2016 -0800
+++ b/jdk/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java	Tue Dec 13 17:40:53 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -33,12 +33,10 @@
  * this point (because no data for the invocation has yet been written).
  * @author Peter Jones
  *
- * @library ../../testlibrary
  * @modules java.rmi/sun.rmi.registry
  *          java.rmi/sun.rmi.server
  *          java.rmi/sun.rmi.transport
  *          java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary
  * @run main/othervm HandshakeTimeout
  */
 
@@ -51,7 +49,6 @@
 
 public class HandshakeTimeout {
 
-    private static final int PORT = TestLibrary.getUnusedRandomPort();
     private static final int TIMEOUT = 10000;
 
     public static void main(String[] args) throws Exception {
@@ -62,12 +59,13 @@
         /*
          * Listen on port, but never process connections made to it.
          */
-        ServerSocket serverSocket = new ServerSocket(PORT);
+        ServerSocket serverSocket = new ServerSocket(0);
+        int port = serverSocket.getLocalPort();
 
         /*
          * Attempt RMI call to port in separate thread.
          */
-        Registry registry = LocateRegistry.getRegistry(PORT);
+        Registry registry = LocateRegistry.getRegistry(port);
         Connector connector = new Connector(registry);
         Thread t = new Thread(connector);
         t.setDaemon(true);
@@ -91,7 +89,7 @@
                 System.err.println();
 
                 if (connector.exception instanceof MarshalException) {
-                    System.err.println(
+                    throw new RuntimeException(
                         "TEST FAILED: MarshalException thrown, expecting " +
                         "java.rmi.ConnectException or ConnectIOException");
                 } else if (connector.exception instanceof ConnectException ||