use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class readTest method main.
public static void main(String[] args) throws Exception {
try {
testPkg.Server obj = new testPkg.Server();
testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT);
registry.bind("Hello", stub);
System.err.println("Server ready");
// now, let's test client
testPkg.Client client = new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT);
String testStubReturn = client.testStub();
if (!testStubReturn.equals(obj.hello)) {
throw new RuntimeException("Test Fails : unexpected string from stub call");
} else {
System.out.println("Test passed");
}
registry.unbind("Hello");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class InvalidName method main.
public static void main(String[] args) {
String testName;
// ensure that an exception is thrown for Naming URL with '#'
try {
System.err.println("\nRegression test for bugs " + "4136563 and 4208801\n");
testName = new String("rmi://#/MyRMI");
Naming.lookup(testName);
System.err.println("no exception thrown for URL: " + testName);
throw new RuntimeException("test failed");
} catch (MalformedURLException e) {
// should have received malformed URL exception
System.err.println("Correctly received instance of " + "MalformedURLException:");
System.err.println(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
TestLibrary.bomb(e);
}
// the local host's ip address are .equals()
try {
String localAddress = InetAddress.getLocalHost().getHostAddress();
Registry registry = (Registry) Naming.lookup("rmi:///");
if (registry.toString().indexOf(localAddress) >= 0) {
System.err.println("verified registry endpoint contains ipaddress");
} else {
TestLibrary.bomb("registry endpoint does not contain ipaddress");
}
} catch (Exception e) {
TestLibrary.bomb(e);
}
System.err.println("test passed");
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class TestLibrary method checkIfRegistryRunning.
/**
* Helper method to determine if registry has started
*
* @param port The port number to check
* @param msTimeout The amount of milliseconds to spend checking
*/
public static boolean checkIfRegistryRunning(int port, int msTimeout) {
long stopTime = System.currentTimeMillis() + msTimeout;
do {
try {
Registry r = LocateRegistry.getRegistry(port);
String[] s = r.list();
// no exception. We're now happy that registry is running
return true;
} catch (RemoteException e) {
// problem - not ready ? Try again
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
// not expected
}
}
} while (stopTime > System.currentTimeMillis());
return false;
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class ShutdownImpl method main.
public static void main(String[] args) {
try {
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
Registry registry = LocateRegistry.getRegistry("", registryPort);
ShutdownMonitor monitor = (ShutdownMonitor) registry.lookup(KeepAliveDuringCall.BINDING);
System.err.println("(ShutdownImpl) retrieved shutdown monitor");
impl = new ShutdownImpl(monitor);
Shutdown stub = (Shutdown) UnicastRemoteObject.exportObject(impl);
System.err.println("(ShutdownImpl) exported shutdown object");
monitor.submitShutdown(stub);
System.err.println("(ShutdownImpl) submitted shutdown object");
} catch (Exception e) {
System.err.println("(ShutdownImpl) TEST SUBPROCESS FAILURE:");
e.printStackTrace();
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class UnbindIdempotent method main.
public static void main(String[] args) throws Exception {
Registry registry = TestLibrary.createRegistryOnUnusedPort();
int registryPort = TestLibrary.getRegistryPort(registry);
InitialContext ictx = new InitialContext();
Context rctx;
try {
rctx = (Context) ictx.lookup("rmi://localhost:" + Integer.toString(registryPort));
} catch (NamingException e) {
// Unable to set up for test.
return;
}
// Attempt to unbind a name that is not already bound.
try {
rctx.unbind("_bogus_4278121_");
} catch (NameNotFoundException e) {
throw new Exception("Test failed: unbind() call not idempotent");
}
}
Aggregations