blob: 39ef4906516ca63a199191bfe7beb2810da77392 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001-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/**
25 * @test
26 * @bug 4425852
27 * @author Robert Field
28 *
29 * @run build VMConnection
30 * @run compile -g EventQueueDisconnectTest.java
31 * @run main EventQueueDisconnectTest
32 *
33 * @summary EventQueueDisconnectTest checks to see that
34 * VMDisconnectedException is never thrown before VMDisconnectEvent.
35 *
36 * Failure mode for this test is throwing VMDisconnectedException
37 * on vm.eventQueue().remove();
38 * Does not use a scaffold since we don't want that hiding the exception.
39 */
40import com.sun.jdi.*;
41import com.sun.jdi.event.*;
42import com.sun.jdi.request.*;
43
44
45 /********** target program **********/
46
47class EventQueueDisconnectTarg {
48 public static void main(String args[]) {
49 for (int i=0; i < 10; ++i) {
50 Say(i);
51 }
52 }
53 static void Say(int what) {
54 System.out.println("Say " + what);
55 }
56}
57
58 /********** test program **********/
59
60public class EventQueueDisconnectTest {
61
62 public static void main(String args[]) throws Exception {
63 VMConnection connection = new VMConnection(
64 "com.sun.jdi.CommandLineLaunch:",
65 VirtualMachine.TRACE_NONE);
66 connection.setConnectorArg("main", "EventQueueDisconnectTarg");
67 String debuggeeVMOptions = connection.getDebuggeeVMOptions();
68 if (!debuggeeVMOptions.equals("")) {
69 if (connection.connectorArg("options").length() > 0) {
70 throw new IllegalArgumentException("VM options in two places");
71 }
72 connection.setConnectorArg("options", debuggeeVMOptions);
73 }
74 VirtualMachine vm = connection.open();
75 EventRequestManager requestManager = vm.eventRequestManager();
76 MethodEntryRequest req = requestManager.createMethodEntryRequest();
77 req.addClassFilter("EventQueueDisconnectTarg");
78 req.setSuspendPolicy(EventRequest.SUSPEND_NONE);
79 req.enable();
80
81 // We need to have the BE stop when VMDeath comes
82 VMDeathRequest ourVMDeathRequest = requestManager.createVMDeathRequest();
83 ourVMDeathRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
84 ourVMDeathRequest.enable();
85
86 vm.resume();
87 while (true) {
88 EventSet set = vm.eventQueue().remove();
89 Event event = set.eventIterator().nextEvent();
90
91 System.err.println("EventSet with: " + event.getClass());
92
93 if (event instanceof VMDisconnectEvent) {
94 System.err.println("Disconnecting successfully");
95 break;
96 }
97
98 if (event instanceof VMDeathEvent) {
99 System.err.println("Pausing after VM death");
100
101 // sleep a few seconds
102 try {
103 Thread.sleep(40 * 1000);
104 } catch (InterruptedException exc) {
105 // ignore
106 }
107 }
108
109 set.resume();
110 }
111
112 System.err.println("EventQueueDisconnectTest passed");
113 }
114}