Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java
38867 views
/*1* Copyright (c) 2006, 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*/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* @build TestLibrary JavaVM34* @run main/othervm NoConsoleOutput35*/3637import java.io.ByteArrayOutputStream;38import java.io.File;39import java.rmi.Remote;40import java.rmi.RemoteException;41import java.rmi.registry.LocateRegistry;42import java.rmi.registry.Registry;43import java.rmi.server.UnicastRemoteObject;4445public class NoConsoleOutput {4647public static void main(String[] args) throws Exception {48System.err.println("\nRegression test for bug 6409194\n");4950/*51* Exdecute a subprocess VM that does a bunch of RMI activity52* with a logging configuration file that does not specify a53* ConsoleHandler and with no legacy sun.rmi.*.logLevel system54* properties set.55*/56String loggingPropertiesFile =57System.getProperty("test.src", ".") +58File.separatorChar + "logging.properties";59ByteArrayOutputStream out = new ByteArrayOutputStream();60ByteArrayOutputStream err = new ByteArrayOutputStream();6162// We instantiate a JavaVM that should not produce any console output63// (neither on standard output, nor on standard err streams).64JavaVM vm = new JavaVM(DoRMIStuff.class.getName(),65"-Djava.util.logging.config.file=" + loggingPropertiesFile,66"", out, err);67vm.execute();6869/*70* Verify that the subprocess had no System.out or System.err71* output.72*/73String outString = out.toString();74String errString = err.toString();7576System.err.println("-------- subprocess standard output: --------");77System.err.print(out);78System.err.println("-------- subprocess standard error: --------");79System.err.print(err);80System.err.println("---------------------------------------------");8182if (outString.length() > 0 || errString.length() > 0) {83throw new Error("TEST FAILED: unexpected subprocess output");84}8586System.err.println("TEST PASSED");87}8889public static class DoRMIStuff {90private interface Foo extends Remote {91Object echo(Object obj) throws RemoteException;92}93private static class FooImpl implements Foo {94FooImpl() { }95public Object echo(Object obj) { return obj; }96}97public static void main(String[] args) throws Exception {98Registry registry = TestLibrary.createRegistryOnUnusedPort();99int registryPort = TestLibrary.getRegistryPort(registry);100Registry reg = LocateRegistry.getRegistry("", registryPort);101FooImpl fooimpl = new FooImpl();102UnicastRemoteObject.exportObject(fooimpl, 0);103reg.rebind("foo", fooimpl);104Foo foostub = (Foo) reg.lookup("foo");105FooImpl fooimpl2 = new FooImpl();106UnicastRemoteObject.exportObject(fooimpl2, 0);107foostub.echo(fooimpl2);108UnicastRemoteObject.unexportObject(fooimpl, true);109UnicastRemoteObject.unexportObject(fooimpl2, true);110}111}112}113114115