1 /* 2 * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4111507 26 * @summary retryServerSocket should not retry on BindException 27 * @author Ann Wollrath 28 * 29 * @build AddrInUse 30 * @run main/othervm AddrInUse 31 */ 32 33 import java.net.ServerSocket; 34 import java.rmi.registry.LocateRegistry; 35 import java.rmi.server.ExportException; 36 37 public class AddrInUse implements Runnable { 38 39 private static final int PORT = 9999; 40 private static final long TIMEOUT = 10000; 41 42 private boolean exportSucceeded = false; 43 private Throwable exportException = null; 44 45 public void run() { 46 47 /* 48 * Attempt to create (i.e. export) a registry on the port that 49 * has already been bound, and record the result. 50 */ 51 try { 52 LocateRegistry.createRegistry(PORT); 53 synchronized (this) { 54 exportSucceeded = true; 55 notifyAll(); 56 } 57 } catch (Throwable t) { 58 synchronized (this) { 59 exportException = t; 60 notifyAll(); 61 } 62 } 63 } 64 65 public static void main(String[] args) throws Exception { 66 System.err.println("\nRegression test for bug 4111507\n"); 67 68 /* 69 * Bind a server socket to a port. 70 */ 71 System.err.println("create a ServerSocket on port " + PORT + "..."); 72 ServerSocket server = new ServerSocket(PORT); 73 74 /* 75 * Start a thread that creates a registry on the same port, 76 * and analyze the result. 77 */ 78 System.err.println("create a registry on the same port..."); 79 System.err.println("(should cause an ExportException)"); 80 AddrInUse obj = new AddrInUse(); 81 synchronized (obj) { 82 (new Thread(obj, "AddrInUse")).start(); 83 84 /* 85 * Don't wait forever (original bug is that the export 86 * hangs). 87 */ 88 obj.wait(TIMEOUT); 89 90 if (obj.exportSucceeded) { 91 throw new RuntimeException( 92 "TEST FAILED: export on already-bound port succeeded"); | 1 /* 2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4111507 26 * @summary retryServerSocket should not retry on BindException 27 * @author Ann Wollrath 28 * 29 * @library ../../testlibrary 30 * @build AddrInUse 31 * @run main/othervm AddrInUse 32 */ 33 34 import java.net.ServerSocket; 35 import java.rmi.registry.LocateRegistry; 36 import java.rmi.server.ExportException; 37 38 public class AddrInUse implements Runnable { 39 40 private static int port = -1; 41 private static final long TIMEOUT = 10000; 42 43 private boolean exportSucceeded = false; 44 private Throwable exportException = null; 45 46 public void run() { 47 48 /* 49 * Attempt to create (i.e. export) a registry on the port that 50 * has already been bound, and record the result. 51 */ 52 try { 53 LocateRegistry.createRegistry(port); 54 synchronized (this) { 55 exportSucceeded = true; 56 notifyAll(); 57 } 58 } catch (Throwable t) { 59 synchronized (this) { 60 exportException = t; 61 notifyAll(); 62 } 63 } 64 } 65 66 public static void main(String[] args) throws Exception { 67 System.err.println("\nRegression test for bug 4111507\n"); 68 69 /* 70 * Bind a server socket to a port. 71 */ 72 ServerSocket server = new ServerSocket(0); 73 port = server.getLocalPort(); 74 System.err.println("Created a ServerSocket on port " + port + "..."); 75 76 /* 77 * Start a thread that creates a registry on the same port, 78 * and analyze the result. 79 */ 80 System.err.println("create a registry on the same port..."); 81 System.err.println("(should cause an ExportException)"); 82 AddrInUse obj = new AddrInUse(); 83 synchronized (obj) { 84 (new Thread(obj, "AddrInUse")).start(); 85 86 /* 87 * Don't wait forever (original bug is that the export 88 * hangs). 89 */ 90 obj.wait(TIMEOUT); 91 92 if (obj.exportSucceeded) { 93 throw new RuntimeException( 94 "TEST FAILED: export on already-bound port succeeded"); |