Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.java
38867 views
/*1* Copyright (c) 2013, 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*/2223import java.io.File;24import java.lang.reflect.Method;25import java.net.URL;26import java.net.URLClassLoader;27import java.util.Arrays;2829/**30* @test31* @summary Tests for the RMI unmarshalling errors not to cause silent failure.32* @author Jaroslav Bachorik33* @bug 6937053 800547234*35* @run clean TestSerializationMismatch36* @run main/othervm TestSerializationMismatch37*38*/39public class TestSerializationMismatch {40static final String clientDir = "Client";41static final String serverDir = "Server";42static final String testSrc = System.getProperty("test.src");43static final String testSrcDir = testSrc != null ? testSrc : ".";44static final String testSrcClientDir = testSrcDir + File.separator + clientDir + File.separator;45static final String testSrcServerDir = testSrcDir + File.separator + serverDir + File.separator;46static final String testClasses = System.getProperty("test.classes");47static final String testClassesDir = testClasses != null ? testClasses : ".";48static final String testClassesClientDir = testClassesDir + File.separator + clientDir + File.separator;49static final String testClassesServerDir = testClassesDir + File.separator + serverDir + File.separator;5051static final boolean debug = true;5253public static void main(String[] args) throws Exception {54setup();5556compileClient();57compileServer();5859debug("starting server");60String url = startServer();61debug("server started and listening on " + url);62debug("starting client");63startClient(url);64}6566static void setup() {67debug("setting up the output dirs");68cleanupDir(testClassesClientDir);69cleanupDir(testClassesServerDir);70}7172static void cleanupDir(String path) {73debug("cleaning " + path);74File dir = new File(path);75if (dir.exists()) {76for(File src : dir.listFiles()) {77boolean rslt = src.delete();78debug((rslt == false ? "not " : "") + "deleted " + src);79}80} else {81dir.mkdirs();82}83}8485static void compileClient() {86debug("compiling client");87compile("-d" , testClassesClientDir,88"-sourcepath", testSrcClientDir,89testSrcClientDir + "Client.java",90testSrcClientDir + "ConfigKey.java",91testSrcClientDir + "TestNotification.java");92}9394static void compileServer() {95debug("compiling server");96compile("-d" , testClassesServerDir,97"-sourcepath", testSrcServerDir,98testSrcServerDir + "Server.java",99testSrcServerDir + "ConfigKey.java",100testSrcServerDir + "TestNotification.java",101testSrcServerDir + "Ste.java",102testSrcServerDir + "SteMBean.java");103}104105static String startServer() throws Exception {106ClassLoader serverCL = customCL(testClassesServerDir);107108Class serverClz = serverCL.loadClass("Server");109Method startMethod = serverClz.getMethod("start");110return (String)startMethod.invoke(null);111}112113static void startClient(String url) throws Exception {114ClassLoader clientCL = customCL(testClassesClientDir);115116Thread.currentThread().setContextClassLoader(clientCL);117Class clientClz = clientCL.loadClass("Client");118Method runMethod = clientClz.getMethod("run", String.class);119runMethod.invoke(null, url);120}121122static ClassLoader customCL(String classDir) throws Exception {123return new URLClassLoader(124new URL[]{125new File(classDir).toURI().toURL()126},127TestSerializationMismatch.class.getClassLoader()128);129}130131static void debug(Object message) {132if (debug) {133System.out.println(message);134}135}136137/* run javac <args> */138static void compile(String... args) {139debug("Running: javac " + Arrays.toString(args));140if (com.sun.tools.javac.Main.compile(args) != 0) {141throw new RuntimeException("javac failed: args=" + Arrays.toString(args));142}143}144}145146147