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 Test.java Test2.java Test3.java Test4.java 31 * HelloInterface.java HelloServer.java HelloClient.java 32 * HelloImpl.java _HelloImpl_Tie.java _HelloInterface_Stub.java 33 * RmiIiopReturnValueTest.java 34 * @run main/othervm -Djava.naming.provider.url=iiop://localhost:5050 35 * -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 36 * RmiIiopReturnValueTest -port 5049 37 * @run main/othervm/secure=java.lang.SecurityManager/policy=jtreg.test.policy 38 * -Djava.naming.provider.url=iiop://localhost:5050 39 * -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 40 * RmiIiopReturnValueTest -port 5049 41 */ 42 43 44 import java.io.DataInputStream; 45 import java.io.File; 46 import java.util.ArrayList; 47 import java.util.Arrays; 48 import java.util.List; 49 import java.util.concurrent.TimeUnit; 50 import java.util.concurrent.CountDownLatch; 51 import jdk.testlibrary.JDKToolFinder; 52 import jdk.testlibrary.JDKToolLauncher; 53 54 public class RmiIiopReturnValueTest { 55 56 static final String ORBD = JDKToolFinder.getTestJDKTool("orbd"); 57 static final String JAVA = JDKToolFinder.getTestJDKTool("java"); 58 static final JDKToolLauncher orbdLauncher = JDKToolLauncher.createUsingTestJDK("orbd"); 59 static final String CLASSPATH = System.getProperty("java.class.path"); 60 static final int FIVE_SECONDS = 5000; 61 62 private static Throwable clientException; 63 private static boolean exceptionInClient; 64 private static Process orbdProcess; 65 private static Process rmiServerProcess; 66 main(String[] args)67 public static void main(String[] args) throws Exception { 68 startTestComponents(); 69 stopTestComponents(); 70 System.err.println("Test completed OK "); 71 } 72 startTestComponents()73 static void startTestComponents () throws Exception { 74 startOrbd(); 75 Thread.sleep(FIVE_SECONDS); 76 startRmiIiopServer(); 77 Thread.sleep(FIVE_SECONDS); 78 executeRmiIiopClient(); 79 } 80 stopTestComponents()81 private static void stopTestComponents() throws Exception { 82 stopRmiIiopServer(); 83 stopOrbd(); 84 if (exceptionInClient) { 85 throw new RuntimeException(clientException); 86 } else if (!isResponseReceived()) { 87 throw new RuntimeException("Expected Response not received"); 88 } 89 } 90 startOrbd()91 static void startOrbd() throws Exception { 92 System.out.println("\nStarting orbd with NS port 5050 and activation port 5049 "); 93 94 //orbd -ORBInitialHost localhost -ORBInitialPort 5050 -port 5049 95 orbdLauncher.addToolArg("-ORBInitialHost").addToolArg("localhost") 96 .addToolArg("-ORBInitialPort").addToolArg("5050") 97 .addToolArg("-port").addToolArg("5049"); 98 99 System.out.println("RmiIiopReturnValueTest: Executing: " + Arrays.asList(orbdLauncher.getCommand())); 100 ProcessBuilder pb = new ProcessBuilder(orbdLauncher.getCommand()); 101 pb.redirectError(ProcessBuilder.Redirect.INHERIT); 102 orbdProcess = pb.start(); 103 } 104 105 startRmiIiopServer()106 static void startRmiIiopServer() throws Exception { 107 System.out.println("\nStarting RmiIiopServer"); 108 // java -cp . 109 // -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory 110 // -Djava.naming.provider.url=iiop://localhost:5050 HelloServer -port 5049 111 List<String> commands = new ArrayList<>(); 112 commands.add(RmiIiopReturnValueTest.JAVA); 113 commands.add("-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory"); 114 commands.add("-Djava.naming.provider.url=iiop://localhost:5050"); 115 commands.add("-cp"); 116 commands.add(RmiIiopReturnValueTest.CLASSPATH); 117 commands.add("HelloServer"); 118 commands.add("-port"); 119 commands.add("5049"); 120 121 System.out.println("RmiIiopReturnValueTest: Executing: " + commands); 122 ProcessBuilder pb = new ProcessBuilder(commands); 123 pb.redirectError(ProcessBuilder.Redirect.INHERIT); 124 rmiServerProcess = pb.start(); 125 } 126 isResponseReceived()127 static boolean isResponseReceived() { 128 return HelloClient.isResponseReceived(); 129 } 130 stopRmiIiopServer()131 static void stopRmiIiopServer() throws Exception { 132 if (rmiServerProcess != null) { 133 System.out.println("RmiIiopReturnValueTest.stopRmiIiopServer: destroy rmiServerProcess"); 134 rmiServerProcess.destroyForcibly(); 135 rmiServerProcess.waitFor(); 136 System.out.println("serverProcess exitCode:" 137 + rmiServerProcess.exitValue()); 138 } 139 } 140 stopOrbd()141 static void stopOrbd() throws Exception { 142 System.out.println("RmiIiopReturnValueTest.stopOrbd: destroy orbdProcess "); 143 orbdProcess.destroyForcibly(); 144 orbdProcess.waitFor(); 145 System.out.println("orbd exitCode:" 146 + orbdProcess.exitValue()); 147 } 148 executeRmiIiopClient()149 static void executeRmiIiopClient() throws Exception { 150 System.out.println("RmiIiopReturnValueTest.executeRmiIiopClient: HelloClient.executeRmiClientCall"); 151 try { 152 HelloClient.executeRmiClientCall(); 153 } catch (Throwable t) { 154 clientException = t; 155 exceptionInClient = true; 156 } 157 } 158 } 159