Path: blob/master/test/jdk/com/sun/jdi/EventQueueDisconnectTest.java
41149 views
/*1* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 442585226* @author Robert Field27*28* @summary EventQueueDisconnectTest checks to see that29* VMDisconnectedException is never thrown before VMDisconnectEvent.30*31* Failure mode for this test is throwing VMDisconnectedException32* on vm.eventQueue().remove();33* Does not use a scaffold since we don't want that hiding the exception.34*35* @run build VMConnection36* @run compile -g EventQueueDisconnectTest.java37* @run driver EventQueueDisconnectTest38*/39import com.sun.jdi.*;40import com.sun.jdi.event.*;41import com.sun.jdi.request.*;424344/********** target program **********/4546class EventQueueDisconnectTarg {47public static void main(String args[]) {48for (int i=0; i < 10; ++i) {49Say(i);50}51}52static void Say(int what) {53System.out.println("Say " + what);54}55}5657/********** test program **********/5859public class EventQueueDisconnectTest {6061public static void main(String args[]) throws Exception {62VMConnection connection = new VMConnection(63"com.sun.jdi.CommandLineLaunch:",64VirtualMachine.TRACE_NONE);65connection.setConnectorArg("main", "EventQueueDisconnectTarg");66String debuggeeVMOptions = VMConnection.getDebuggeeVMOptions();67if (!debuggeeVMOptions.equals("")) {68if (connection.connectorArg("options").length() > 0) {69throw new IllegalArgumentException("VM options in two places");70}71connection.setConnectorArg("options", debuggeeVMOptions);72}73VirtualMachine vm = connection.open();74EventRequestManager requestManager = vm.eventRequestManager();75MethodEntryRequest req = requestManager.createMethodEntryRequest();76req.addClassFilter("EventQueueDisconnectTarg");77req.setSuspendPolicy(EventRequest.SUSPEND_NONE);78req.enable();7980// We need to have the BE stop when VMDeath comes81VMDeathRequest ourVMDeathRequest = requestManager.createVMDeathRequest();82ourVMDeathRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);83ourVMDeathRequest.enable();8485vm.resume();86while (true) {87EventSet set = vm.eventQueue().remove();88Event event = set.eventIterator().nextEvent();8990System.err.println("EventSet with: " + event.getClass());9192if (event instanceof VMDisconnectEvent) {93System.err.println("Disconnecting successfully");94break;95}9697if (event instanceof VMDeathEvent) {98System.err.println("Pausing after VM death");99100// sleep a few seconds101try {102Thread.sleep(40 * 1000);103} catch (InterruptedException exc) {104// ignore105}106}107108set.resume();109}110111System.err.println("EventQueueDisconnectTest passed");112}113}114115116