8078221: java/rmi/Naming/DefaultRegistryPort.java fails intermittently
Reviewed-by: rriggs
This commit is contained in:
parent
f5a681373f
commit
0ee5e92ddd
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -39,10 +39,7 @@
|
|||||||
/*
|
/*
|
||||||
* Ensure that the default registry port for java.rmi.Naming URLs
|
* Ensure that the default registry port for java.rmi.Naming URLs
|
||||||
* is 1099. Test creates a registry on port 1099 and then does a
|
* is 1099. Test creates a registry on port 1099 and then does a
|
||||||
* lookup with a Naming URL that uses the default port. Test fails
|
* lookup with a Naming URL that uses the default port.
|
||||||
* if the lookup yields a NotBoundException. If the registry could
|
|
||||||
* not be created, a fallback strategy of using an existing one is
|
|
||||||
* tried.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.rmi.Naming;
|
import java.rmi.Naming;
|
||||||
@ -52,67 +49,37 @@ import java.rmi.registry.Registry;
|
|||||||
|
|
||||||
public class DefaultRegistryPort {
|
public class DefaultRegistryPort {
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) throws Exception {
|
||||||
|
|
||||||
Registry registry = null;
|
Registry registry = null;
|
||||||
try {
|
System.err.println("Starting registry on default port REGISTRY_PORT="
|
||||||
|
+ Registry.REGISTRY_PORT);
|
||||||
System.err.println(
|
final int NUM = 10;
|
||||||
"Starting registry on default port REGISTRY_PORT=" +
|
for (int loop = 0; loop < NUM; loop++) {
|
||||||
Registry.REGISTRY_PORT);
|
System.err.println("in loop: " + loop);
|
||||||
|
|
||||||
registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
|
|
||||||
|
|
||||||
System.err.println("Created registry=" + registry);
|
|
||||||
|
|
||||||
} catch(java.rmi.RemoteException e) {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
|
||||||
System.err.println(
|
System.err.println("Created registry=" + registry);
|
||||||
"Failed to create a registry, try using existing one");
|
break;
|
||||||
registry = LocateRegistry.getRegistry();
|
} catch(java.rmi.RemoteException e) {
|
||||||
|
String err = e.getMessage();
|
||||||
System.err.println("Found registry=" + registry);
|
if (err.contains("Address already in use")
|
||||||
|
|| err.contains("Port already in use")) {
|
||||||
} catch (Exception ge) {
|
try {
|
||||||
|
Thread.sleep((long)(TestLibrary.getTimeoutFactor() * 100));
|
||||||
TestLibrary.bomb(
|
} catch (InterruptedException ignore) { }
|
||||||
"Test Failed: cound not find or create a registry");
|
continue;
|
||||||
|
}
|
||||||
|
TestLibrary.bomb(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
if (registry == null) {
|
||||||
|
throw new RuntimeException("can not create registry at "
|
||||||
try {
|
+ Registry.REGISTRY_PORT + " after trying " + NUM + "times");
|
||||||
|
|
||||||
if (registry != null) {
|
|
||||||
|
|
||||||
registry.rebind("myself", registry);
|
|
||||||
|
|
||||||
Remote myself = Naming.lookup("rmi://localhost/myself");
|
|
||||||
|
|
||||||
System.err.println("Test PASSED");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
TestLibrary.bomb(
|
|
||||||
"Test Failed: cound not find or create a registry");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch(java.rmi.NotBoundException e) {
|
|
||||||
|
|
||||||
TestLibrary.bomb(
|
|
||||||
"Test Failed: could not find myself");
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
TestLibrary.bomb(
|
|
||||||
"Test failed: unexpected exception");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registry.rebind("myself", registry);
|
||||||
|
Remote myself = Naming.lookup("rmi://localhost/myself");
|
||||||
|
System.err.println("Test PASSED");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user