1 /*
2 * Copyright (c) 2001, 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 */
60 *
61 * 1. If using java.util.logging, turn on client call logger using
62 * system property, "sun.rmi.client.logCalls". Collect client call
63 * output using a custom stream handler. Verify client call output is
64 * generated and contains the string "outbound call".
65 *
66 * 2. Turn on server call using
67 * RemoteServer.setLog(ByteArrayOutputStream). Invoke some remote
68 * method calls verify logger output is non-null.
69 *
70 * Turn off server call log by doing setLog(null), verify output is
71 * zero length. Verify that RemoteServer.getLog == null
72 *
73 * Use setLog to turn call log back on. Invoke remote method that
74 * throws an exception and contains the string "exception".
75 *
76 * 3. Print directly to return value of RemoteServer.getLog(), verify
77 * logger output is non-null.
78 */
79 public class CheckLogging {
80 private static final String LOCATION =
81 "rmi://localhost:" + TestLibrary.REGISTRY_PORT + "/";
82 private static final ByteArrayOutputStream clientCallOut =
83 new ByteArrayOutputStream();
84
85 private static final boolean usingOld =
86 Boolean.getBoolean("sun.rmi.log.useOld");
87
88 static {
89 System.setProperty("sun.rmi.client.logCalls", "true");
90 if (usingOld) {
91 System.err.println("set default stream");
92 LogStream.setDefaultStream(new PrintStream(clientCallOut));
93 } else {
94 Logger.getLogger("sun.rmi.client.call").
95 addHandler(new InternalStreamHandler(clientCallOut));
96 }
97 }
98
99 /* use registry to generate client & server call log info */
100 private static Registry registry;
101 static {
102 try {
103 registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);
104 } catch (Exception e) {
105 TestLibrary.bomb("could not create registry");
106 }
107 }
108
109 /**
110 * Used to collect output from specific loggers
111 */
112 private static class InternalStreamHandler extends StreamHandler {
113 private InternalStreamHandler(OutputStream out) {
114 super(out, new SimpleFormatter());
115 setLevel(Level.ALL);
116 }
117
118 public void publish(LogRecord record) {
119 super.publish(record);
120 flush();
121 }
122
123 public void close() {
|
1 /*
2 * Copyright (c) 2001, 2012, 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 */
60 *
61 * 1. If using java.util.logging, turn on client call logger using
62 * system property, "sun.rmi.client.logCalls". Collect client call
63 * output using a custom stream handler. Verify client call output is
64 * generated and contains the string "outbound call".
65 *
66 * 2. Turn on server call using
67 * RemoteServer.setLog(ByteArrayOutputStream). Invoke some remote
68 * method calls verify logger output is non-null.
69 *
70 * Turn off server call log by doing setLog(null), verify output is
71 * zero length. Verify that RemoteServer.getLog == null
72 *
73 * Use setLog to turn call log back on. Invoke remote method that
74 * throws an exception and contains the string "exception".
75 *
76 * 3. Print directly to return value of RemoteServer.getLog(), verify
77 * logger output is non-null.
78 */
79 public class CheckLogging {
80 private static int REGISTRY_PORT = -1;
81 private static String LOCATION;
82
83 private static final ByteArrayOutputStream clientCallOut =
84 new ByteArrayOutputStream();
85
86 private static final boolean usingOld =
87 Boolean.getBoolean("sun.rmi.log.useOld");
88
89 static {
90 System.setProperty("sun.rmi.client.logCalls", "true");
91 if (usingOld) {
92 System.err.println("set default stream");
93 LogStream.setDefaultStream(new PrintStream(clientCallOut));
94 } else {
95 Logger.getLogger("sun.rmi.client.call").
96 addHandler(new InternalStreamHandler(clientCallOut));
97 }
98 }
99
100 /* use registry to generate client & server call log info */
101 private static Registry registry;
102 static {
103 try {
104 registry = TestLibrary.createRegistryOnUnusedPort();
105 REGISTRY_PORT = TestLibrary.getRegistryPort(registry);
106 LOCATION = "rmi://localhost:" + REGISTRY_PORT + "/";
107 } catch (Exception e) {
108 TestLibrary.bomb("could not create registry");
109 }
110 }
111
112 /**
113 * Used to collect output from specific loggers
114 */
115 private static class InternalStreamHandler extends StreamHandler {
116 private InternalStreamHandler(OutputStream out) {
117 super(out, new SimpleFormatter());
118 setLevel(Level.ALL);
119 }
120
121 public void publish(LogRecord record) {
122 super.publish(record);
123 flush();
124 }
125
126 public void close() {
|