author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 309 | bda219d843f6 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
1 |
/* |
715 | 2 |
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
25 |
* @bug 4118600 |
2 | 26 |
* @summary RMI UnmarshallException, interaction on stopping a thread. |
27 |
* |
|
28 |
* @bug 4177704 |
|
29 |
* @summary RuntimeExceptions can corrupt call connections that may be reused. |
|
30 |
* |
|
31 |
* @author Laird Dornin |
|
32 |
* |
|
33 |
* @library ../../../testlibrary |
|
34 |
* @build TestLibrary RMID JavaVM StreamPipe |
|
35 |
* @build CheckUnmarshall PoisonPill RuntimeExceptionParameter |
|
36 |
* @build CheckUnmarshalOnStopThread |
|
37 |
* @build CheckUnmarshalOnStopThread_Stub |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
38 |
* @run main/othervm/timeout=480 CheckUnmarshalOnStopThread |
2 | 39 |
*/ |
40 |
||
41 |
import java.rmi.*; |
|
42 |
import java.rmi.server.*; |
|
43 |
import java.io.*; |
|
44 |
import java.rmi.registry.*; |
|
45 |
||
46 |
/** |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
47 |
* Description for 4118600: |
2 | 48 |
* |
49 |
* If an rmi call thread is stopped while unmarshalling a return |
|
50 |
* value), java.lang.ThreadDeath will be thrown during |
|
51 |
* UnicastRef.invoke(...). If rmi handles the Error properly, the |
|
52 |
* remote method connection will not be reused. Otherwise the |
|
53 |
* connection can be freed and reused in a corrupted state, which will |
|
54 |
* lead to the throwing of an UnmarshalException the next time the |
|
55 |
* connection is used. |
|
56 |
* |
|
57 |
* To test RMI Error handling, the test invokes the remote call, |
|
58 |
* getPoisonPill, a number of times. This method returns an object |
|
59 |
* which throws an Error on return value deserialization (from its |
|
60 |
* readObject method). If RMI handles the error correctly, another |
|
61 |
* remote call, ping, should execute correctly (i.e. with no |
|
62 |
* exceptions). The test fails if the ping method throws an |
|
63 |
* UnmarshalException. |
|
64 |
* |
|
65 |
* The old way that the test used to operate: |
|
66 |
* |
|
67 |
* Iterate a large number of times: each iteration spawns a thread |
|
68 |
* that makes multiple rmi calls, sleep for 10 milliseconds, then stop |
|
69 |
* the thread that is making the rmi calls (hopefully during return |
|
70 |
* value Unmarshalling). |
|
71 |
* |
|
72 |
* Count the number of UnmarshalExceptions that occur during test |
|
73 |
* iterations. If this number is > 10, then the test fails. |
|
74 |
* |
|
75 |
* Note: Even if rmi is catching java.lang.ThreadDeath properly, other |
|
76 |
* types of exceptions (often related to monitor state, etc.) can |
|
77 |
* occur. This test is only written to track UnmarshalExceptions; |
|
78 |
* success/failure does not depend on other types of problems. |
|
79 |
* |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
80 |
* Description for 4177704: |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
81 |
* |
2 | 82 |
* Similar situation as for 4177704 except that instead of just |
83 |
* ensuring that RMI properly handles Errors, the second part of the |
|
84 |
* test ensures that RMI deals with RuntimeExceptions correctly. |
|
85 |
* |
|
86 |
* Test also ensures that call connections are freed without reuse |
|
87 |
* when RuntimeExceptions are thrown during the marshalling of call |
|
88 |
* parameters. An object that throws a RuntimeException in its |
|
89 |
* writeObject method helps to carry out this part of the test. |
|
90 |
*/ |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
91 |
public class CheckUnmarshalOnStopThread |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
92 |
extends UnicastRemoteObject |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
93 |
implements CheckUnmarshal |
2 | 94 |
{ |
95 |
final static int RUNTIME_PILL = 1; |
|
96 |
public static int typeToThrow = 0; |
|
97 |
||
98 |
/* |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
99 |
* remote object implementation |
2 | 100 |
*/ |
101 |
||
102 |
CheckUnmarshalOnStopThread() throws RemoteException { } |
|
103 |
||
104 |
public PoisonPill getPoisonPill() throws RemoteException { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
105 |
return new PoisonPill(new Integer(0)); |
2 | 106 |
} |
107 |
||
108 |
public Object ping() throws RemoteException { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
109 |
return (Object) new Integer(0); |
2 | 110 |
} |
111 |
||
112 |
public void passRuntimeExceptionParameter( |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
113 |
RuntimeExceptionParameter rep) throws RemoteException |
2 | 114 |
{ |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
115 |
// will never be called |
2 | 116 |
} |
117 |
||
118 |
public static void main(String [] args) { |
|
119 |
||
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
120 |
Object dummy = new Object(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
121 |
CheckUnmarshal cu = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
122 |
CheckUnmarshalOnStopThread cuonst = null; |
2 | 123 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
124 |
System.err.println("\nregression test for bugs: " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
125 |
"4118600 and 4177704\n"); |
2 | 126 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
127 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
128 |
cuonst = new CheckUnmarshalOnStopThread(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
129 |
cu = (CheckUnmarshal) UnicastRemoteObject.toStub(cuonst); |
2 | 130 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
131 |
// make sure that RMI will free connections appropriately |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
132 |
// under several situations: |
2 | 133 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
134 |
// when Errors are thrown during parameter unmarshalling |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
135 |
System.err.println("testing to see if RMI will handle errors"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
136 |
ensureConnectionsAreFreed(cu, true); |
2 | 137 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
138 |
// when RuntimeExceptions are thrown during parameter unmarshalling |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
139 |
System.err.println("testing to see if RMI will handle " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
140 |
"runtime exceptions"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
141 |
typeToThrow = RUNTIME_PILL; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
142 |
ensureConnectionsAreFreed(cu, true); |
2 | 143 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
144 |
// when RuntimeExceptions are thrown during parameter marshalling |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
145 |
System.err.println("testing to see if RMI will handle " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
146 |
"runtime exceptions thrown during " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
147 |
"parameter marshalling"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
148 |
ensureConnectionsAreFreed(cu, false); |
2 | 149 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
150 |
System.err.println |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
151 |
("\nsuccess: CheckUnmarshalOnStopThread test passed "); |
2 | 152 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
153 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
154 |
TestLibrary.bomb(e); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
155 |
} finally { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
156 |
cu = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
157 |
deactivate(cuonst); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
158 |
} |
2 | 159 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
160 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
161 |
static void ensureConnectionsAreFreed(CheckUnmarshal cu, boolean getPill) |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
162 |
throws Exception |
2 | 163 |
{ |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
164 |
// invoke a remote call that will corrupt a call connection |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
165 |
// that will not be freed (if the bug is not fixed) |
2 | 166 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
167 |
for (int i = 0 ; i < 250 ; i++) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
168 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
169 |
Object test = cu.ping(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
170 |
if (getPill) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
171 |
cu.getPoisonPill(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
172 |
} else { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
173 |
cu.passRuntimeExceptionParameter( |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
174 |
new RuntimeExceptionParameter()); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
175 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
176 |
} catch (Error e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
177 |
// expect an Error from call unmarshalling, ignore it |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
178 |
} catch (RuntimeException e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
179 |
// " RuntimeException " |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
180 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
181 |
} |
2 | 182 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
183 |
System.err.println("remote calls passed, received no " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
184 |
"unmarshal exceptions\n\n"); |
2 | 185 |
} |
186 |
||
187 |
static void deactivate(RemoteServer r) { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
188 |
// make sure that the object goes away |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
189 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
190 |
System.err.println("deactivating object."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
191 |
UnicastRemoteObject.unexportObject(r, true); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
192 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
193 |
e.getMessage(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
194 |
e.printStackTrace(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
195 |
} |
2 | 196 |
} |
197 |
} |