1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8146975 27 * @summary test RMI-IIOP with value object return 28 * @library /lib/testlibrary 29 * @build jdk.testlibrary.* 30 * @compile -addmods java.corba Test.java Test3.java Test4.java 31 * HelloInterface.java HelloServer.java 32 * HelloClient.java HelloImpl.java _HelloImpl_Tie.java _HelloInterface_Stub.java 33 * RmiIiopReturnValueTest.java 34 * @run main/othervm -addmods java.corba 35 * -Djava.naming.provider.url=iiop://localhost:5050 36 * -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 37 * RmiIiopReturnValueTest -port 5049 38 * @run main/othervm/secure=java.lang.SecurityManager/policy=jtreg.test.policy 39 * -addmods java.corba -Djava.naming.provider.url=iiop://localhost:5050 40 * -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 41 * RmiIiopReturnValueTest -port 5049 42 */ 43 44 45 import java.util.ArrayList; 46 import java.util.Arrays; 47 import java.util.List; 48 import jdk.testlibrary.JDKToolFinder; 49 import jdk.testlibrary.JDKToolLauncher; 50 51 public class RmiIiopReturnValueTest { 52 53 static final String ORBD = JDKToolFinder.getTestJDKTool("orbd"); 54 static final String JAVA = JDKToolFinder.getTestJDKTool("java"); 55 static final JDKToolLauncher orbdLauncher = JDKToolLauncher.createUsingTestJDK("orbd"); 56 static final String CLASSPATH = System.getProperty("java.class.path"); 57 static final int FIVE_SECONDS = 5000; 58 59 private static Throwable clientException; 60 private static boolean exceptionInClient; 61 private static Process orbdProcess; 62 private static Process rmiServerProcess; 63 64 public static void main(String[] args) throws Exception { 65 startTestComponents(); 66 stopTestComponents(); 67 System.err.println("Test completed OK "); 68 } 69 70 static void startTestComponents () throws Exception { 71 startOrbd(); 72 Thread.sleep(FIVE_SECONDS); 73 startRmiIiopServer(); 74 Thread.sleep(FIVE_SECONDS); 75 executeRmiIiopClient(); 76 } 77 78 private static void stopTestComponents() throws Exception { 79 stopRmiIiopServer(); 80 stopOrbd(); 81 if (exceptionInClient) { 82 throw new RuntimeException(clientException); 83 } else if (!isResponseReceived()) { 84 throw new RuntimeException("Expected Response not received"); 85 } 86 } 87 88 static void startOrbd() throws Exception { 89 System.out.println("\nStarting orbd with NS port 5050 and activation port 5049 "); 90 91 //orbd -ORBInitialHost localhost -ORBInitialPort 5050 -port 5049 92 orbdLauncher.addToolArg("-ORBInitialHost").addToolArg("localhost") 93 .addToolArg("-ORBInitialPort").addToolArg("5050") 94 .addToolArg("-port").addToolArg("5049"); 95 96 System.out.println("RmiIiopReturnValueTest: Executing: " + Arrays.asList(orbdLauncher.getCommand())); 97 ProcessBuilder pb = new ProcessBuilder(orbdLauncher.getCommand()); 98 pb.redirectError(ProcessBuilder.Redirect.INHERIT); 99 orbdProcess = pb.start(); 100 } 101 102 103 static void startRmiIiopServer() throws Exception { 104 System.out.println("\nStarting RmiIiopServer"); 105 // java -addmods java.corba -cp . 106 // -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 107 // -Djava.naming.provider.url=iiop://localhost:5050 HelloServer -port 5049 108 List<String> commands = new ArrayList<>(); 109 commands.add(RmiIiopReturnValueTest.JAVA); 110 commands.add("-addmods"); 111 commands.add("java.corba"); 112 commands.add("-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory"); 113 commands.add("-Djava.naming.provider.url=iiop://localhost:5050"); 114 commands.add("-cp"); 115 commands.add(RmiIiopReturnValueTest.CLASSPATH); 116 commands.add("HelloServer"); 117 commands.add("-port"); 118 commands.add("5049"); 119 120 System.out.println("RmiIiopReturnValueTest: Executing: " + commands); 121 ProcessBuilder pb = new ProcessBuilder(commands); 122 pb.redirectError(ProcessBuilder.Redirect.INHERIT); 123 rmiServerProcess = pb.start(); 124 } 125 126 static boolean isResponseReceived() { 127 return HelloClient.isResponseReceived(); 128 } 129 130 static void stopRmiIiopServer() throws Exception { 131 if (rmiServerProcess != null) { 132 System.out.println("RmiIiopReturnValueTest.stopRmiIiopServer: destroy rmiServerProcess"); 133 rmiServerProcess.destroyForcibly(); 134 rmiServerProcess.waitFor(); 135 System.out.println("serverProcess exitCode:" 136 + rmiServerProcess.exitValue()); 137 } 138 } 139 140 static void stopOrbd() throws Exception { 141 System.out.println("RmiIiopReturnValueTest.stopOrbd: destroy orbdProcess "); 142 orbdProcess.destroyForcibly(); 143 orbdProcess.waitFor(); 144 System.out.println("orbd exitCode:" 145 + orbdProcess.exitValue()); 146 } 147 148 static void executeRmiIiopClient() throws Exception { 149 System.out.println("RmiIiopReturnValueTest.executeRmiIiopClient: HelloClient.executeRmiClientCall"); 150 try { 151 HelloClient.executeRmiClientCall(); 152 } catch (Throwable t) { 153 clientException = t; 154 exceptionInClient = true; 155 } 156 } 157 }