8168613: CORBA ObjectStreamTest fails with address in use

Reviewed-by: psandoz
This commit is contained in:
Roger Riggs 2016-10-26 09:38:16 -04:00
parent 39b8573bcf
commit baba77c4cc

View File

@ -42,13 +42,8 @@ import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
import java.util.PropertyPermission; import java.util.PropertyPermission;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.atomic.LongAdder;
import javax.naming.CommunicationException;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.rmi.CORBA.Util; import javax.rmi.CORBA.Util;
import javax.rmi.PortableRemoteObject; import javax.rmi.PortableRemoteObject;
@ -56,11 +51,9 @@ import org.omg.CORBA_2_3.ORB;
import org.omg.CORBA_2_3.portable.OutputStream; import org.omg.CORBA_2_3.portable.OutputStream;
import org.omg.CORBA_2_3.portable.InputStream; import org.omg.CORBA_2_3.portable.InputStream;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.JDKToolLauncher;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.AfterSuite; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.TestNG; import org.testng.TestNG;
@ -69,15 +62,13 @@ import org.testng.TestNG;
* @test * @test
* @library /test/lib * @library /test/lib
* @build jdk.test.lib.* * @build jdk.test.lib.*
* @compile ObjectStreamTest.java ObjectStreamTest$_Echo_Stub.java ObjectStreamTest$_Server_Tie.java * @compile ObjectStreamTest.java ObjectStreamTest$_Echo_Stub.java
* @modules java.corba/com.sun.corba.se.impl.io java.base/java.io java.corba/com.sun.corba.se.impl.activation * ObjectStreamTest$_Server_Tie.java
* @modules java.corba/com.sun.corba.se.impl.io java.base/java.io
* java.corba/com.sun.corba.se.impl.activation
* @summary Tests of ReflectionFactory use in IIOP Serialization * @summary Tests of ReflectionFactory use in IIOP Serialization
* @run testng/othervm * @run testng/othervm ObjectStreamTest
* -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory * @run testng/othervm/policy=security.policy ObjectStreamTest
* -Djava.naming.provider.url=iiop://localhost:1050 ObjectStreamTest
* @run testng/othervm/policy=security.policy
* -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
* -Djava.naming.provider.url=iiop://localhost:1050 ObjectStreamTest
*/ */
@Test @Test
@ -92,12 +83,6 @@ public class ObjectStreamTest {
colorSet.add(Colors.GREEN); colorSet.add(Colors.GREEN);
} }
/**
* The process spawned to run orbd.
*/
static Process orbdProcess;
static Thread orbThread;
@DataProvider(name = "Objects") @DataProvider(name = "Objects")
static Object[][] patterns() { static Object[][] patterns() {
BigInteger bigInteger = new BigInteger("8943892002309239"); BigInteger bigInteger = new BigInteger("8943892002309239");
@ -141,7 +126,7 @@ public class ObjectStreamTest {
* @param value * @param value
*/ */
@Test(dataProvider = "Objects") @Test(dataProvider = "Objects")
static void factCheck(Serializable value) { void factCheck(Serializable value) {
Class<?> clazz = value.getClass(); Class<?> clazz = value.getClass();
java.io.ObjectStreamClass sOSC = java.io.ObjectStreamClass.lookup(clazz); java.io.ObjectStreamClass sOSC = java.io.ObjectStreamClass.lookup(clazz);
java.io.ObjectStreamField[] sFields = sOSC.getFields(); java.io.ObjectStreamField[] sFields = sOSC.getFields();
@ -150,25 +135,33 @@ public class ObjectStreamTest {
Assert.assertEquals(sFields.length, cFields.length, "Different number of fields"); Assert.assertEquals(sFields.length, cFields.length, "Different number of fields");
for (int i = 0; i < sFields.length; i++) { for (int i = 0; i < sFields.length; i++) {
Assert.assertEquals(sFields[i].getName(), cFields[i].getName(), "different field names " + cFields[i].getName()); Assert.assertEquals(sFields[i].getName(), cFields[i].getName(),
Assert.assertEquals(sFields[i].getType(), cFields[i].getType(), "different field types " + cFields[i].getName()); "different field names " + cFields[i].getName());
Assert.assertEquals(sFields[i].getTypeString(), cFields[i].getTypeString(), "different field typestrings " + cFields[i].getName()); Assert.assertEquals(sFields[i].getType(), cFields[i].getType(),
"different field types " + cFields[i].getName());
Assert.assertEquals(sFields[i].getTypeString(), cFields[i].getTypeString(),
"different field typestrings " + cFields[i].getName());
} }
Assert.assertEquals(baseMethod("hasReadObjectMethod", sOSC, (Class<?>[]) null), Assert.assertEquals(baseMethod("hasReadObjectMethod", sOSC, (Class<?>[]) null),
corbaMethod("hasReadObject", cOSC, (Class<?>[]) null), "hasReadObject: " + value.getClass()); corbaMethod("hasReadObject", cOSC, (Class<?>[]) null),
"hasReadObject: " + value.getClass());
Assert.assertEquals(baseMethod("hasWriteObjectMethod", sOSC, (Class<?>[]) null), Assert.assertEquals(baseMethod("hasWriteObjectMethod", sOSC, (Class<?>[]) null),
corbaMethod("hasWriteObject", cOSC, (Class<?>[]) null), "hasWriteObject: " + value.getClass()); corbaMethod("hasWriteObject", cOSC, (Class<?>[]) null),
"hasWriteObject: " + value.getClass());
Assert.assertEquals(baseMethod("hasWriteReplaceMethod", sOSC, (Class<?>[]) null), Assert.assertEquals(baseMethod("hasWriteReplaceMethod", sOSC, (Class<?>[]) null),
corbaMethod("hasWriteReplaceMethod", cOSC, (Class<?>[]) null), "hasWriteReplace: " + value.getClass()); corbaMethod("hasWriteReplaceMethod", cOSC, (Class<?>[]) null),
"hasWriteReplace: " + value.getClass());
Assert.assertEquals(baseMethod("hasReadResolveMethod", sOSC, (Class<?>[]) null), Assert.assertEquals(baseMethod("hasReadResolveMethod", sOSC, (Class<?>[]) null),
corbaMethod("hasReadResolveMethod", cOSC, (Class<?>[]) null), "hasReadResolve: " + value.getClass()); corbaMethod("hasReadResolveMethod", cOSC, (Class<?>[]) null),
"hasReadResolve: " + value.getClass());
Assert.assertEquals(baseMethod("getSerialVersionUID", sOSC, (Class<?>[]) null), Assert.assertEquals(baseMethod("getSerialVersionUID", sOSC, (Class<?>[]) null),
corbaMethod("getSerialVersionUID", cOSC, (Class<?>[]) null), "getSerialVersionUID: " + value.getClass()); corbaMethod("getSerialVersionUID", cOSC, (Class<?>[]) null),
"getSerialVersionUID: " + value.getClass());
} }
@ -178,7 +171,7 @@ public class ObjectStreamTest {
* and deserialized using Util.readAny to equivalent objects. * and deserialized using Util.readAny to equivalent objects.
*/ */
@Test(dataProvider = "Objects", enabled = true, dependsOnMethods = {"factCheck"}) @Test(dataProvider = "Objects", enabled = true, dependsOnMethods = {"factCheck"})
static void WriteValueObjectStreamTest01(Serializable value) throws Exception { void WriteValueObjectStreamTest01(Serializable value) throws Exception {
ORB orb = (ORB) ORB.init(new String[0], null); ORB orb = (ORB) ORB.init(new String[0], null);
OutputStream out = (OutputStream) orb.create_output_stream(); OutputStream out = (OutputStream) orb.create_output_stream();
@ -193,15 +186,43 @@ public class ObjectStreamTest {
/** /**
* Test that objects can be echoed to a server and come back equivalent. * Test that objects can be echoed to a server and come back equivalent.
*/ */
@Test(dataProvider = "Objects", enabled = false, dependsOnMethods = {"factCheck"}) @Test(dataProvider = "Objects", enabled = true, dependsOnMethods = {"factCheck"})
static void echoObjects(Serializable value) throws Exception { void echoObjects(Serializable value) throws Exception {
Context initialNamingContext = Server.init(); Echo echo = getEchoStub();
Echo echo = (Echo) PortableRemoteObject.narrow(
initialNamingContext.lookup(Server.serverID), Echo.class);
Object actual = echo.echo(value); Object actual = echo.echo(value);
checkEquals(actual, value); checkEquals(actual, value);
} }
/**
* Initialize the ORB and the singleton Echo server stub.
* @return the stub for the Echo server.
* @throws RemoteException if an error occurs
*/
synchronized Echo getEchoStub() throws RemoteException {
if (echoStub == null) {
ORB orb = (ORB) ORB.init(new String[0], null);
Echo server = new Server();
echoStub = (javax.rmi.CORBA.Stub) PortableRemoteObject.toStub(server);
echoStub.connect(orb);
}
return (Echo)echoStub;
}
/**
* The stub for the Echo Server class. Initialized on first use.
*/
private javax.rmi.CORBA.Stub echoStub;
/**
* After all the tests run shutdown the orb.
*/
@AfterClass
void shutdownOrb() {
ORB orb = (ORB) ORB.init(new String[0], null);
orb.shutdown(true);
}
/** /**
* Check if the value and result are equals, with some tests depending on the type. * Check if the value and result are equals, with some tests depending on the type.
* @param expected the expected value * @param expected the expected value
@ -209,15 +230,18 @@ public class ObjectStreamTest {
*/ */
static void checkEquals(Object actual, Object expected) { static void checkEquals(Object actual, Object expected) {
Class<?> cl = expected.getClass(); Class<?> cl = expected.getClass();
Assert.assertEquals(actual.getClass(), cl, "type of value not equal to class of result"); Assert.assertEquals(actual.getClass(), cl,
"type of value not equal to class of result");
try { try {
if (cl.isArray() || !(cl.getDeclaredMethod("equals", cl) == null)) { if (cl.isArray() || !(cl.getDeclaredMethod("equals", cl) == null)) {
Assert.assertEquals(actual, expected, "echo'd object not equal"); Assert.assertEquals(actual, expected, "echo'd object not equal");
} else { } else {
Assert.assertEquals(toString(actual), toString(expected), "toString values not equal"); Assert.assertEquals(toString(actual), toString(expected),
"toString values not equal");
} }
} catch (NoSuchMethodException ex) { } catch (NoSuchMethodException ex) {
Assert.assertEquals(toString(actual), toString(expected), "toString values not equal"); Assert.assertEquals(toString(actual), toString(expected),
"toString values not equal");
} }
} }
@ -301,7 +325,9 @@ public class ObjectStreamTest {
* @param argClasses method arguments * @param argClasses method arguments
* @return the value returned from invoking the method * @return the value returned from invoking the method
*/ */
static Object corbaMethod(String methodName, com.sun.corba.se.impl.io.ObjectStreamClass osc, Class<?>... argClasses) { static Object corbaMethod(String methodName,
com.sun.corba.se.impl.io.ObjectStreamClass osc,
Class<?>... argClasses) {
Class<?> oscClass = com.sun.corba.se.impl.io.ObjectStreamClass.class; Class<?> oscClass = com.sun.corba.se.impl.io.ObjectStreamClass.class;
try { try {
@ -325,7 +351,8 @@ public class ObjectStreamTest {
* @param argClasses method arguments * @param argClasses method arguments
* @return the value returned from invoking the method * @return the value returned from invoking the method
*/ */
static Object baseMethod(String methodName, java.io.ObjectStreamClass osc, Class<?>... argClasses) { static Object baseMethod(String methodName, java.io.ObjectStreamClass osc,
Class<?>... argClasses) {
Class<?> oscClass = java.io.ObjectStreamClass.class; Class<?> oscClass = java.io.ObjectStreamClass.class;
try { try {
@ -342,7 +369,7 @@ public class ObjectStreamTest {
} }
/** /**
* Simple echo interface to check serialization/deserialization. * Simple echo interface to check IIOP serialization/deserialization.
*/ */
interface Echo extends Remote { interface Echo extends Remote {
Object echo(Object obj) throws RemoteException; Object echo(Object obj) throws RemoteException;
@ -350,12 +377,6 @@ public class ObjectStreamTest {
static class Server extends PortableRemoteObject implements Echo { static class Server extends PortableRemoteObject implements Echo {
public static final String serverID = "ObjectStreamTestServer";
private static Context initialNamingContext;
private static Server server;
public Server() throws RemoteException { public Server() throws RemoteException {
super(); super();
} }
@ -363,62 +384,7 @@ public class ObjectStreamTest {
public Object echo(Object obj) { public Object echo(Object obj) {
return obj; return obj;
} }
public static Context init() {
if (initialNamingContext == null) {
try {
startOrbd();
Thread.sleep(5000L); // Give it 5 seconds
} catch (Exception eex) {
throw new RuntimeException("Orbd", eex);
} }
for (int i = 0; i < 1; i++) {
try {
Thread.sleep(1L);
initialNamingContext = new InitialContext();
server = new Server();
initialNamingContext.rebind(serverID, server);
} catch (CommunicationException | InterruptedException cex) {
System.out.printf("retry #%d sec: ex: %s%n", i, cex);
} catch (NamingException ex) {
throw new RuntimeException("can't initialize naming context", ex);
} catch (RemoteException rex) {
throw new RuntimeException("can't initialize server", rex);
}
}
}
if (initialNamingContext == null) {
Assert.fail("Can't initialize the Orb, no naming context");
}
return initialNamingContext;
}
}
static void startOrbd() throws Exception {
System.out.println("\nStarting orbd with NS port 1050 ");
JDKToolLauncher orbdLauncher = JDKToolLauncher.create("orbd")
.addToolArg("-ORBInitialHost").addToolArg("localhost")
.addToolArg("-ORBInitialPort").addToolArg("1050");
System.out.println("ObjectStreamTest: Executing: " + Arrays.asList(orbdLauncher.getCommand()));
ProcessBuilder pb = new ProcessBuilder(orbdLauncher.getCommand());
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
orbdProcess = pb.start();
}
@AfterSuite
static void killOrbd() throws Exception {
if (orbdProcess != null) {
orbdProcess.destroyForcibly();
orbdProcess.waitFor();
System.out.printf("destroyed orbd, pid: %d, exitValue: %d%n",
orbdProcess.getPid(), orbdProcess.exitValue());
}
}
// Main can be used to run the tests from the command line with only testng.jar. // Main can be used to run the tests from the command line with only testng.jar.
@SuppressWarnings("raw_types") @SuppressWarnings("raw_types")