J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 6409194 |
| 26 | * @summary There should be no console output caused by the RMI |
| 27 | * implementation's logging, except as explicitly configured in the |
| 28 | * logging properties file, if none of the legacy sun.rmi.*.logLevel |
| 29 | * system properties are set. |
| 30 | * |
| 31 | * @author Peter Jones |
| 32 | * |
| 33 | * @library ../../../../../java/rmi/testlibrary |
| 34 | * @build JavaVM |
| 35 | * @build NoConsoleOutput |
| 36 | * @run main/othervm NoConsoleOutput |
| 37 | */ |
| 38 | |
| 39 | import java.io.ByteArrayOutputStream; |
| 40 | import java.io.File; |
| 41 | import java.rmi.Remote; |
| 42 | import java.rmi.RemoteException; |
| 43 | import java.rmi.registry.LocateRegistry; |
| 44 | import java.rmi.registry.Registry; |
| 45 | import java.rmi.server.UnicastRemoteObject; |
| 46 | |
| 47 | public class NoConsoleOutput { |
| 48 | |
| 49 | public static void main(String[] args) throws Exception { |
| 50 | System.err.println("\nRegression test for bug 6409194\n"); |
| 51 | |
| 52 | /* |
| 53 | * Exdecute a subprocess VM that does a bunch of RMI activity |
| 54 | * with a logging configuration file that does not specify a |
| 55 | * ConsoleHandler and with no legacy sun.rmi.*.logLevel system |
| 56 | * properties set. |
| 57 | */ |
| 58 | String loggingPropertiesFile = |
| 59 | System.getProperty("test.src", ".") + |
| 60 | File.separatorChar + "logging.properties"; |
| 61 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 62 | ByteArrayOutputStream err = new ByteArrayOutputStream(); |
| 63 | JavaVM vm = new JavaVM(DoRMIStuff.class.getName(), |
| 64 | "-Djava.util.logging.config.file=" + loggingPropertiesFile, |
| 65 | "", out, err); |
| 66 | vm.start(); |
| 67 | vm.getVM().waitFor(); |
| 68 | |
| 69 | /* |
| 70 | * Verify that the subprocess had no System.out or System.err |
| 71 | * output. |
| 72 | */ |
| 73 | String outString = out.toString(); |
| 74 | String errString = err.toString(); |
| 75 | |
| 76 | System.err.println("-------- subprocess standard output: --------"); |
| 77 | System.err.print(out); |
| 78 | System.err.println("-------- subprocess standard error: --------"); |
| 79 | System.err.print(err); |
| 80 | System.err.println("---------------------------------------------"); |
| 81 | |
| 82 | if (outString.length() > 0 || errString.length() > 0) { |
| 83 | throw new Error("TEST FAILED: unexpected subprocess output"); |
| 84 | } |
| 85 | |
| 86 | System.err.println("TEST PASSED"); |
| 87 | } |
| 88 | |
| 89 | public static class DoRMIStuff { |
| 90 | private static final int PORT = 2020; |
| 91 | private interface Foo extends Remote { |
| 92 | Object echo(Object obj) throws RemoteException; |
| 93 | } |
| 94 | private static class FooImpl implements Foo { |
| 95 | FooImpl() { } |
| 96 | public Object echo(Object obj) { return obj; } |
| 97 | } |
| 98 | public static void main(String[] args) throws Exception { |
| 99 | LocateRegistry.createRegistry(PORT); |
| 100 | Registry reg = LocateRegistry.getRegistry("", PORT); |
| 101 | FooImpl fooimpl = new FooImpl(); |
| 102 | UnicastRemoteObject.exportObject(fooimpl, 0); |
| 103 | reg.rebind("foo", fooimpl); |
| 104 | Foo foostub = (Foo) reg.lookup("foo"); |
| 105 | FooImpl fooimpl2 = new FooImpl(); |
| 106 | UnicastRemoteObject.exportObject(fooimpl2, 0); |
| 107 | foostub.echo(fooimpl2); |
| 108 | UnicastRemoteObject.unexportObject(fooimpl, true); |
| 109 | UnicastRemoteObject.unexportObject(fooimpl2, true); |
| 110 | } |
| 111 | } |
| 112 | } |