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 4109103
26 * @summary rmid should annotate child process output
27 *
28 * @author Laird Dornin; code borrowed from Ann Wollrath
29 *
30 * @library ../../../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 TestLibrary RMID MyRMI CheckAnnotations_Stub
36 * @run main/othervm/policy=security.policy/timeout=480 CheckAnnotations
37 */
38
39 import java.io.*;
40 import java.rmi.*;
41 import java.rmi.server.*;
42 import java.rmi.activation.*;
43 import java.security.CodeSource;
44 import java.util.Properties;
45 import java.util.StringTokenizer;
46
47
48 public class CheckAnnotations
49 extends Activatable implements MyRMI, Runnable
50 {
51
52 private static Object dummy = new Object();
53 private static MyRMI myRMI = null;
54
60 /*
61 * The following line is required with the JDK 1.2 VM so that the
62 * VM can exit gracefully when this test completes. Otherwise, the
63 * conservative garbage collector will find a handle to the server
64 * object on the native stack and not clear the weak reference to
65 * it in the RMI runtime's object table.
66 */
67 Object dummy1 = new Object();
68 RMID rmid = null;
69
70 System.err.println("\nRegression test for bug/rfe 4109103\n");
71
72 try {
73
74 // Set security manager according to the
75 // testlibrary.
76 TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);
77
78 // start an rmid.
79 RMID.removeLog();
80 rmid = RMID.createRMID(rmidOut, rmidErr, false);
81 rmid.start();
82
83 /* Cause activation groups to have a security policy that will
84 * allow security managers to be downloaded and installed
85 */
86 Properties p = new Properties();
87 // this test must always set policies/managers in its
88 // activation groups
89 p.put("java.security.policy",
90 TestParams.defaultGroupPolicy);
91 p.put("java.security.manager",
92 TestParams.defaultSecurityManager);
93
94 /* new desc - we will reuse in order to get multiple vms.*/
95 System.err.println("Create activation group in this VM");
96 ActivationGroupDesc groupDesc =
97 new ActivationGroupDesc(p, null);
98 ActivationSystem system = ActivationGroup.getSystem();
99 ActivationGroupID groupID = system.registerGroup(groupDesc);
100 ActivationGroup.createGroup(groupID, groupDesc, 0);
163
164 /* we have to wait for output to filter down
165 * from children so we can read it before we
166 * kill rmid.
167 */
168
169 String outString = null;
170 String errString = null;
171
172 for (int i = 0 ; i < 5 ; i ++ ) {
173 // have to give output from rmid time to trickle down to
174 // this process
175 try {
176 Thread.sleep(4000);
177 } catch(InterruptedException e) {
178 }
179
180 outString = rmidOut.toString();
181 errString = rmidErr.toString();
182
183 if ((!outString.equals("")) &&
184 (!errString.equals("")))
185 {
186 System.err.println("obtained annotations");
187 break;
188 }
189 System.err.println("rmid output not yet received, retrying...");
190 }
191
192 rmidOut.reset();
193 rmidErr.reset();
194
195 // only test when we are annotating..., first run does not annotate
196 if (iteration >= 0) {
197 System.err.println("Checking annotations...");
198 System.err.println(outString);
199 System.err.println(errString);
200
201 StringTokenizer stOut = new StringTokenizer(outString, ":");
202 StringTokenizer stErr = new StringTokenizer(errString, ":");
203
204 String execErr = null;
205 String execOut = null;
206 String destOut = null;
207 String destErr = null;
208 String outTmp = null;
209 String errTmp = null;
210
211 while (stOut.hasMoreTokens()) {
212 execOut = outTmp;
213 outTmp = destOut;
214 destOut = stOut.nextToken();
215 }
216 while (stErr.hasMoreTokens()) {
217 execErr = errTmp;
218 errTmp = destErr;
219 destErr = stErr.nextToken();
220 }
221
222 if ((execErr == null)||(errTmp == null)||
223 (destErr == null)) {
224 return false;
225 }
226 if ((execOut == null)||(outTmp == null)||
227 (destOut == null)) {
228 return false;
229 }
230
231 // just make sure that last two strings are what we expect.
232 if (execOut.equals("ExecGroup-" + iteration)
233 && (new String(destOut.substring(0,4)).equals("out" +
234 iteration))
235 && (execErr.equals("ExecGroup-"+iteration))
236 && (new String(destErr.substring(0,4)).equals("err" +
237 iteration)) ) {
238 return true;
239 } else {
240 return false;
241 }
242 }
243 return true;
244 }
245
246 // implementation of MyRMI, make this object activatable.
247 public CheckAnnotations
248 (ActivationID id, MarshalledObject mo)
249 throws RemoteException {
|
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 4109103
26 * @summary rmid should annotate child process output
27 *
28 * @author Laird Dornin; code borrowed from Ann Wollrath
29 *
30 * @library ../../../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 * java.base/sun.nio.ch
36 * @build TestLibrary RMID MyRMI CheckAnnotations_Stub
37 * @run main/othervm/policy=security.policy/timeout=480 CheckAnnotations
38 */
39
40 import java.io.*;
41 import java.rmi.*;
42 import java.rmi.server.*;
43 import java.rmi.activation.*;
44 import java.security.CodeSource;
45 import java.util.Properties;
46 import java.util.StringTokenizer;
47
48
49 public class CheckAnnotations
50 extends Activatable implements MyRMI, Runnable
51 {
52
53 private static Object dummy = new Object();
54 private static MyRMI myRMI = null;
55
61 /*
62 * The following line is required with the JDK 1.2 VM so that the
63 * VM can exit gracefully when this test completes. Otherwise, the
64 * conservative garbage collector will find a handle to the server
65 * object on the native stack and not clear the weak reference to
66 * it in the RMI runtime's object table.
67 */
68 Object dummy1 = new Object();
69 RMID rmid = null;
70
71 System.err.println("\nRegression test for bug/rfe 4109103\n");
72
73 try {
74
75 // Set security manager according to the
76 // testlibrary.
77 TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);
78
79 // start an rmid.
80 RMID.removeLog();
81 rmid = RMID.createRMIDOnEphemeralPort(rmidOut, rmidErr, false);
82 rmid.start();
83
84 /* Cause activation groups to have a security policy that will
85 * allow security managers to be downloaded and installed
86 */
87 Properties p = new Properties();
88 // this test must always set policies/managers in its
89 // activation groups
90 p.put("java.security.policy",
91 TestParams.defaultGroupPolicy);
92 p.put("java.security.manager",
93 TestParams.defaultSecurityManager);
94
95 /* new desc - we will reuse in order to get multiple vms.*/
96 System.err.println("Create activation group in this VM");
97 ActivationGroupDesc groupDesc =
98 new ActivationGroupDesc(p, null);
99 ActivationSystem system = ActivationGroup.getSystem();
100 ActivationGroupID groupID = system.registerGroup(groupDesc);
101 ActivationGroup.createGroup(groupID, groupDesc, 0);
164
165 /* we have to wait for output to filter down
166 * from children so we can read it before we
167 * kill rmid.
168 */
169
170 String outString = null;
171 String errString = null;
172
173 for (int i = 0 ; i < 5 ; i ++ ) {
174 // have to give output from rmid time to trickle down to
175 // this process
176 try {
177 Thread.sleep(4000);
178 } catch(InterruptedException e) {
179 }
180
181 outString = rmidOut.toString();
182 errString = rmidErr.toString();
183
184 System.err.println("outString: " + outString);
185 System.err.println("errString: " + errString);
186
187 if ((!outString.equals("")) &&
188 (!errString.equals("")))
189 {
190 System.err.println("obtained annotations");
191 break;
192 }
193 System.err.println("rmid output not yet received, retrying...");
194 }
195
196 rmidOut.reset();
197 rmidErr.reset();
198
199 // only test when we are annotating..., first run does not annotate
200 if (iteration >= 0) {
201 System.err.println("Checking annotations...");
202 System.err.println(outString);
203 System.err.println(errString);
204
205 StringTokenizer stOut = new StringTokenizer(outString, ":");
206 StringTokenizer stErr = new StringTokenizer(errString, ":");
207
208 String execErr = null;
209 String execOut = null;
210 String destOut = null;
211 String destErr = null;
212 String outTmp = null;
213 String errTmp = null;
214
215 while (stOut.hasMoreTokens()) {
216 execOut = outTmp;
217 outTmp = destOut;
218 destOut = stOut.nextToken();
219 }
220 while (stErr.hasMoreTokens()) {
221 execErr = errTmp;
222 errTmp = destErr;
223 destErr = stErr.nextToken();
224 }
225
226 System.err.printf("execOut:%s, outTmp:%s, destOut:%s %n", execOut, outTmp, destOut);
227 System.err.printf("execErr:%s, errTmp:%s, destErr:%s %n", execErr, errTmp, destErr);
228
229 if ((execErr == null)||(errTmp == null)||
230 (destErr == null)) {
231 return false;
232 }
233 if ((execOut == null)||(outTmp == null)||
234 (destOut == null)) {
235 return false;
236 }
237
238
239 // just make sure that last two strings are what we expect.
240 if (execOut.equals("ExecGroup-" + iteration)
241 && (new String(destOut.substring(0,4)).equals("out" +
242 iteration))
243 && (execErr.equals("ExecGroup-"+iteration))
244 && (new String(destErr.substring(0,4)).equals("err" +
245 iteration)) ) {
246 return true;
247 } else {
248 return false;
249 }
250 }
251 return true;
252 }
253
254 // implementation of MyRMI, make this object activatable.
255 public CheckAnnotations
256 (ActivationID id, MarshalledObject mo)
257 throws RemoteException {
|