test/java/rmi/registry/reexport/Reexport.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1999, 2008, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 1999, 2012, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 47,89 ****
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class Reexport {
- static public final int regport = TestLibrary.REGISTRY_PORT;
-
static public void main(String[] argv) {
Registry reg = null;
try {
System.err.println("\nregression test for 4120329\n");
// establish the registry (we hope)
! System.err.println("Starting registry on port " + regport);
! Reexport.makeRegistry(regport);
// Get a handle to the registry
System.err.println("Creating duplicate registry, this should fail...");
! reg = createReg(true);
if (reg != null) {
TestLibrary.bomb("failed was able to duplicate the registry?!?");
}
// Kill the first registry.
System.err.println("Bringing down the first registry");
try {
! Reexport.killRegistry();
} catch (Exception foo) {
}
// start another registry now that the first is gone; this should work
System.err.println("Trying again to start our own " +
"registry... this should work");
! reg = createReg(false);
if (reg == null) {
TestLibrary.bomb("Could not create registry on second try");
}
--- 47,88 ----
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public class Reexport {
static public void main(String[] argv) {
Registry reg = null;
+ int regPort = TestLibrary.getUnusedRandomPort();
try {
System.err.println("\nregression test for 4120329\n");
// establish the registry (we hope)
! System.err.println("Starting registry on port " + regPort);
! Reexport.makeRegistry(regPort);
// Get a handle to the registry
System.err.println("Creating duplicate registry, this should fail...");
! reg = createReg(true, regPort);
if (reg != null) {
TestLibrary.bomb("failed was able to duplicate the registry?!?");
}
// Kill the first registry.
System.err.println("Bringing down the first registry");
try {
! Reexport.killRegistry(regPort);
} catch (Exception foo) {
}
// start another registry now that the first is gone; this should work
System.err.println("Trying again to start our own " +
"registry... this should work");
! reg = createReg(false, regPort);
if (reg == null) {
TestLibrary.bomb("Could not create registry on second try");
}
*** 91,111 ****
} catch (Exception e) {
TestLibrary.bomb(e);
} finally {
// dont leave the registry around to affect other tests.
! killRegistry();
reg = null;
}
}
! static Registry createReg(boolean remoteOk) {
Registry reg = null;
try {
! reg = LocateRegistry.createRegistry(regport);
} catch (Throwable e) {
if (remoteOk) {
System.err.println("EXPECTING PORT IN USE EXCEPTION:");
System.err.println(e.getMessage());
e.printStackTrace();
--- 90,110 ----
} catch (Exception e) {
TestLibrary.bomb(e);
} finally {
// dont leave the registry around to affect other tests.
! killRegistry(regPort);
reg = null;
}
}
! static Registry createReg(boolean remoteOk, int port) {
Registry reg = null;
try {
! reg = LocateRegistry.createRegistry(port);
} catch (Throwable e) {
if (remoteOk) {
System.err.println("EXPECTING PORT IN USE EXCEPTION:");
System.err.println(e.getMessage());
e.printStackTrace();
*** 138,151 ****
} catch (Exception whatever) {
}
}
private static Process subreg = null;
! public static void killRegistry() {
if (Reexport.subreg != null) {
! RegistryRunner.requestExit();
try {
Reexport.subreg.waitFor();
} catch (InterruptedException ie) {
}
--- 137,150 ----
} catch (Exception whatever) {
}
}
private static Process subreg = null;
! public static void killRegistry(int port) {
if (Reexport.subreg != null) {
! RegistryRunner.requestExit(port);
try {
Reexport.subreg.waitFor();
} catch (InterruptedException ie) {
}