/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
*
*
* @author Adrian Colley
* @author Laird Dornin
* @author Peter Jones
* @author Ann Wollrath
*
* The rmi library directory contains a set of simple utiltity classes
* for use in rmi regression tests.
*
* NOTE: The JavaTest group has recommended that regression tests do
* not make use of packages.
*/
/**
* the writing and maintainance of rmi regression tests.
*/
public class TestLibrary {
/**
* IMPORTANT!
*
* RMI tests are run concurrently and port conflicts result when a single
* port number is used by multiple tests. When needing a port, use
* getUnusedRandomPort() wherever possible. If getUnusedRandomPort() cannot
* be used, reserve and specify a port to use for your test here. This
* will ensure there are no port conflicts amongst the RMI tests. The
* port numbers specified here may also be specified in the respective
* tests. Do not change the reserved port numbers here without also
* changing the port numbers in the respective tests.
*
* When needing an instance of the RMIRegistry, use
* createRegistryOnUnusedPort wherever possible to prevent port conflicts.
*
* Reserved port range: FIXED_PORT_MIN to FIXED_PORT_MAX (inclusive) for
* tests which cannot use a random port. If new fixed ports are added below
* FIXED_PORT_MIN or above FIXED_PORT_MAX, then adjust
* FIXED_PORT_MIN/MAX appropriately.
*/
}
/**
* Routines that enable rmi tests to fail in a uniformly
* informative fashion.
*/
testFailed += " No relevant information";
} else if (e == null) {
testFailed += message;
}
if (e != null) {
e.getMessage());
}
throw new TestFailedException(testFailed, e);
}
}
}
}
});
}
/**
* Property mutators
*/
}
}
return null;
}
});
}
/**
* Routines to print out a test's properties environment.
*/
public static void printEnvironment() {
}
"---------");
keys.hasMoreElements();) {
}
"---------");
}
/**
* Routine that "works-around" a limitation in jtreg.
* Currently it is not possible for a test to specify that the
* test harness should build a given source file and install the
* resulting class in a location that is not accessible from the
* test's classpath. This method enables a test to move a
* compiled test class file from the test's class directory into a
* given "codebase" directory. As a result the test can only
* access the class file for <code>className</code>if the test loads
* it from a classloader (e.g. RMIClassLoader).
*
* Tests that use this routine must have the following permissions
* granted to them:
*
* getProperty user.dir
* getProperty etc.
*/
throws MalformedURLException
{
}
boolean delete)
throws MalformedURLException
{
/*
* NOTES/LIMITATIONS: The class must not be in a named package,
* and the codebase must be a relative path (it's created relative
* to the working directory).
*/
/*
* Specify the file to contain the class definition. Make sure
* that the codebase directory exists (underneath the working
* directory).
*/
throw new RuntimeException(
"could not create codebase directory");
}
}
/*
* Obtain the URL for the codebase.
*/
/*
* Specify where we will copy the class definition from, if
* necessary. After the test is built, the class file can be
* found in the "test.classes" directory.
*/
/*
* If the class definition is not already located at the codebase,
* copy it there from the test build area.
*/
throw new RuntimeException(
"could not find class file to install in codebase " +
"(try rebuilding the test): " + srcFile);
}
try {
} catch (IOException e) {
throw new RuntimeException(
"could not install class file in codebase");
}
"\" in codebase " + codebaseURL);
}
/*
* After the class definition is successfully installed at the
* codebase, delete it from the test's CLASSPATH, so that it will
* not be found there first before the codebase is searched.
*/
throw new RuntimeException(
"could not delete duplicate class file in CLASSPATH");
}
}
return codebaseURL;
}
throws IOException
{
byte[] buf = new byte[32768];
while (true) {
if (count < 0) {
break;
}
}
}
/** routine to unexport an object */
try {
mesg("unexporting object...");
} catch (NoSuchObjectException munch) {
} catch (Exception e) {
e.getMessage();
e.printStackTrace();
}
}
}
/**
* Allow test framework to control the security manager set in
* each test.
*
* @param managerClassName The class name of the security manager
* to be instantiated and set if no security
* manager has already been set.
*/
try {
if (managerClassName == null) {
}
} catch (ClassNotFoundException cnfe) {
bomb("Security manager could not be found: " +
} catch (Exception e) {
bomb("Error creating security manager. ", e);
}
}
}
/**
* Creates an RMI {@link Registry} on a random, un-reserved port.
*
* @returns an RMI Registry, using a random port.
* @throws RemoteException if there was a problem creating a Registry.
*/
}
/**
* Returns the port number the RMI {@link Registry} is running on.
*
* @param registry the registry to find the port of.
* @return the port number the registry is using.
* @throws RuntimeException if there was a problem getting the port number.
*/
int port = -1;
try {
}
return port;
}
/**
* Returns an unused random port number which is not a reserved port. Will
* try up to 10 times to get a random port before giving up and throwing a
* RuntimeException.
*
* @return an unused random port number.
* @throws RuntimeException if there was a problem getting a port.
*/
public static int getUnusedRandomPort() {
int numTries = 0;
while (numTries++ < MAX_SERVER_SOCKET_TRIES) {
int unusedRandomPort = -1;
} catch (IOException e) {
ex = e;
// temporarily print stack trace here until we find out why
// tests are failing.
+ "exception on iteration " + numTries
: "."));
}
if (unusedRandomPort >= 0) {
if (isReservedPort(unusedRandomPort)) {
+ " ServerSocket(0) returned the reserved port "
+ " in TestLibrary.getUnusedRandomPort() ");
} else {
return unusedRandomPort;
}
}
}
// If we're here, then either an exception was thrown or the port is
// a reserved port.
throw new RuntimeException("Error getting unused random port. The"
+" last port returned by ServerSocket(0) was a reserved port");
} else {
}
}
/**
* Determines if a port is one of the reserved port numbers.
*
* @param port the port to test.
* @return {@code true} if the port is a reserved port, otherwise
* {@code false}.
*/
(port == 1099));
}
/**
* Method to capture the stack trace of an exception and return it
* as a string.
*/
e.printStackTrace(ps);
}
/** extra properties */
/**
* Returns extra test properties. Looks for the file "../../test.props"
* and reads it in as a Properties file. Assuming the working directory
* is "<path>/JTwork/scratch", this will find "<path>/test.props".
*/
return props;
}
props = new Properties();
"test.props");
if (!f.exists()) {
return props;
}
try {
try {
} finally {
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("extra property setup failed", e);
}
return props;
}
/**
* Returns an extra test property. Looks for the file "../../test.props"
* and reads it in as a Properties file. Assuming the working directory
* is "<path>/JTwork/scratch", this will find "<path>/test.props".
* If the property isn't found, defaultVal is returned.
*/
}
}