Path: blob/master/test/jdk/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java
41161 views
/*1* Copyright (c) 2006, 2017, 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/* @test24* @bug 640919425* @summary There should be no console output caused by the RMI26* implementation's logging, except as explicitly configured in the27* logging properties file, if none of the legacy sun.rmi.*.logLevel28* system properties are set.29*30* @author Peter Jones31*32* @library ../../../../../java/rmi/testlibrary33* @modules java.rmi/sun.rmi.registry34* java.rmi/sun.rmi.server35* java.rmi/sun.rmi.transport36* java.rmi/sun.rmi.transport.tcp37* @build JavaVM38* @run main/othervm NoConsoleOutput39*/4041import java.io.ByteArrayOutputStream;42import java.io.File;43import java.rmi.Remote;44import java.rmi.RemoteException;45import java.rmi.server.UnicastRemoteObject;4647public class NoConsoleOutput {4849public static void main(String[] args) throws Exception {50System.err.println("\nRegression test for bug 6409194\n");5152/*53* Execute a subprocess VM that does a bunch of RMI activity54* with a logging configuration file that does not specify a55* ConsoleHandler and with no legacy sun.rmi.*.logLevel system56* properties set.57*/58String loggingPropertiesFile =59System.getProperty("test.src", ".") +60File.separatorChar + "logging.properties";61ByteArrayOutputStream out = new ByteArrayOutputStream();62ByteArrayOutputStream err = new ByteArrayOutputStream();6364// We instantiate a JavaVM that should not produce any console output65// on standard err streams, where RMI logging messages are sent to.66JavaVM vm = new JavaVM(67DoRMIStuff.class.getName(),68"--add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED"69+ " --add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED"70+ " --add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED"71+ " --add-exports=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED"72+ " -Djava.util.logging.config.file="73+ loggingPropertiesFile, "", out, err);74try {75vm.execute();76} finally {77vm.destroy();78}7980/*81* Verify that the subprocess had no System.err output.82*/83String outString = out.toString();84String errString = err.toString();8586System.err.println("-------- subprocess standard output: --------");87System.err.print(out);88System.err.println("-------- subprocess standard error: --------");89System.err.print(err);90System.err.println("---------------------------------------------");9192if (errString.length() > 0) {93throw new Error("TEST FAILED: unexpected subprocess output");94}9596System.err.println("TEST PASSED");97}9899public static class DoRMIStuff {100private interface Foo extends Remote {101Object echo(Object obj) throws RemoteException;102}103private static class FooImpl implements Foo {104FooImpl() { }105public Object echo(Object obj) { return obj; }106}107public static void main(String[] args) throws Exception {108FooImpl fooimpl = new FooImpl();109Foo foostub = (Foo) UnicastRemoteObject.exportObject(fooimpl, 0);110FooImpl fooimpl2 = new FooImpl();111UnicastRemoteObject.exportObject(fooimpl2, 0);112foostub.echo(fooimpl2);113UnicastRemoteObject.unexportObject(fooimpl, true);114UnicastRemoteObject.unexportObject(fooimpl2, true);115}116}117}118119120