Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/rmi/PortableRemoteObject/ConcurrentHashMapTest.java
38838 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 806872126* @summary test RMI-IIOP call with ConcurrentHashMap as an argument27* @library /lib/testlibrary28* @build jdk.testlibrary.*29* @build Test HelloInterface HelloServer HelloClient HelloImpl _HelloImpl_Tie _HelloInterface_Stub ConcurrentHashMapTest30* @run main/othervm -Djava.naming.provider.url=iiop://localhost:105031* -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory ConcurrentHashMapTest32* @run main/othervm/secure=java.lang.SecurityManager/policy=jtreg.test.policy33* -Djava.naming.provider.url=iiop://localhost:105034* -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory ConcurrentHashMapTest35*/363738import java.io.DataInputStream;39import java.io.File;40import java.util.ArrayList;41import java.util.Arrays;42import java.util.List;43import java.util.concurrent.TimeUnit;44import java.util.concurrent.CountDownLatch;45import jdk.testlibrary.JDKToolFinder;46import jdk.testlibrary.JDKToolLauncher;4748public class ConcurrentHashMapTest {4950static final String ORBD = JDKToolFinder.getTestJDKTool("orbd");51static final String JAVA = JDKToolFinder.getTestJDKTool("java");52static final JDKToolLauncher orbdLauncher = JDKToolLauncher.createUsingTestJDK("orbd");53static final String CLASSPATH = System.getProperty("java.class.path");54static final int FIVE_SECONDS = 5000;5556private static Exception clientException;57private static boolean exceptionInClient;58private static Process orbdProcess;59private static Process rmiServerProcess;6061public static void main(String[] args) throws Exception {62startTestComponents();63stopTestComponents();64System.err.println("Test completed OK ");65}6667static void startTestComponents () throws Exception {68startOrbd();69Thread.sleep(FIVE_SECONDS);70startRmiIiopServer();71Thread.sleep(FIVE_SECONDS);72executeRmiIiopClient();73}7475private static void stopTestComponents() throws Exception {76stopRmiIiopServer();77stopOrbd();78if (exceptionInClient) {79throw new RuntimeException(clientException);80} else if (!isResponseReceived()) {81throw new RuntimeException("Expected Response not received");82}83}8485static void startOrbd() throws Exception {86System.out.println("\nStarting orbd on port 1050 ");8788//orbd -ORBInitialHost localhost -ORBInitialPort 105089orbdLauncher.addToolArg("-ORBInitialHost").addToolArg("localhost")90.addToolArg("-ORBInitialPort").addToolArg("1050");9192System.out.println("ConcurrentHashMapTest: Executing: " + Arrays.asList(orbdLauncher.getCommand()));93ProcessBuilder pb = new ProcessBuilder(orbdLauncher.getCommand());94pb.redirectError(ProcessBuilder.Redirect.INHERIT);95orbdProcess = pb.start();96}979899static void startRmiIiopServer() throws Exception {100System.out.println("\nStarting RmiServer");101// java -cp .102// -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory103// -Djava.naming.provider.url=iiop://localhost:1050 HelloServer104List<String> commands = new ArrayList<>();105commands.add(ConcurrentHashMapTest.JAVA);106commands.add("-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory");107commands.add("-Djava.naming.provider.url=iiop://localhost:1050");108commands.add("-cp");109commands.add(ConcurrentHashMapTest.CLASSPATH);110commands.add("HelloServer");111112System.out.println("ConcurrentHashMapTest: Executing: " + commands);113ProcessBuilder pb = new ProcessBuilder(commands);114pb.redirectError(ProcessBuilder.Redirect.INHERIT);115rmiServerProcess = pb.start();116}117118static boolean isResponseReceived() {119return HelloClient.isResponseReceived();120}121122static void stopRmiIiopServer() throws Exception {123rmiServerProcess.destroy();124rmiServerProcess.waitFor();125//rmiServerProcess.waitFor(30, TimeUnit.SECONDS);126System.out.println("serverProcess exitCode:"127+ rmiServerProcess.exitValue());128}129130static void stopOrbd() throws Exception {131orbdProcess.destroy();132orbdProcess.waitFor();133//orbdProcess.waitFor(30, TimeUnit.SECONDS);134System.out.println("orbd exitCode:"135+ orbdProcess.exitValue());136}137138static void executeRmiIiopClient() throws Exception {139try {140HelloClient.executeRmiClientCall();141} catch (Exception ex) {142clientException = ex;143exceptionInClient = true;144}145}146}147148149