1/*
2 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/* @test
25 * @bug 4504153
26 * @summary RMI implementation should not log to two loggers where one is
27 * an ancestor of the other, to avoid unintended or duplicate logging
28 * @author Peter Jones
29 *
30 * @library ../../../../../java/rmi/testlibrary
31 * @modules java.rmi/sun.rmi.registry
32 *          java.rmi/sun.rmi.server
33 *          java.rmi/sun.rmi.transport
34 *          java.rmi/sun.rmi.transport.tcp
35 * @build JavaVM
36 * @run main/othervm Test4504153
37 */
38
39import java.io.ByteArrayOutputStream;
40import java.rmi.registry.LocateRegistry;
41import java.rmi.server.RemoteServer;
42
43public class Test4504153 {
44
45    private final static String DONE = "Done!";
46
47    public static void main(String[] args) throws Exception {
48
49        System.err.println("\nRegression test for bug 4504153\n");
50
51        ByteArrayOutputStream out = new ByteArrayOutputStream();
52        ByteArrayOutputStream err = new ByteArrayOutputStream();
53        JavaVM vm = new JavaVM(StartRegistry.class.getName(),
54                               "-Dsun.rmi.transport.logLevel=v", "", out, err);
55        try {
56            vm.execute();
57        } finally {
58            vm.destroy();
59        }
60
61        String errString = err.toString();
62
63        System.err.println(
64            "child process's standard error output:\n\n" + err + "\n");
65
66        if (errString.indexOf(DONE) < 0) {
67            throw new RuntimeException("TEST FAILED: " +
68                "failed to collect expected child process output");
69        }
70
71        if (errString.indexOf("TCPEndpoint") >= 0) {
72            throw new RuntimeException("TEST FAILED: " +
73                "unrequested logging output detected");
74        }
75
76        System.err.println("TEST PASSED");
77    }
78
79    public static class StartRegistry {
80        public static void main(String[] args) throws Exception {
81            LocateRegistry.createRegistry(0);
82            System.err.println(DONE);
83        }
84    }
85}
86