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