0N/A/*
2362N/A * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4419314
0N/A * @author Robert Field
0N/A *
0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter
0N/A * @run compile -g HelloWorld.java
0N/A * @run build VMDeathRequestTest
0N/A * @run main VMDeathRequestTest
0N/A *
0N/A * @summary VMDeathRequestTest checks to see that
0N/A * VMDisconnectedException is never thrown before VMDisconnectEvent.
0N/A *
0N/A * Failure mode for this test is throwing VMDisconnectedException
0N/A * on vm.eventQueue().remove();
0N/A * Does not use a scaffold since we don't want that hiding the exception.
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport com.sun.jdi.request.*;
0N/A
0N/Aimport java.util.*;
0N/A
0N/A
0N/A /********** test program **********/
0N/A
0N/Apublic class VMDeathRequestTest extends TestScaffold {
0N/A boolean requestedVMDeathOccurred = false;
0N/A boolean defaultVMDeathOccurred = false;
0N/A Object syncer = new Object();
0N/A boolean disconnected = false;
0N/A VMDeathRequest deathRequest;
0N/A EventSet currentEventSet;
0N/A
0N/A VMDeathRequestTest (String args[]) {
0N/A super(args);
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new VMDeathRequestTest(args).startTests();
0N/A }
0N/A
0N/A /********** event handlers **********/
0N/A
0N/A public void eventSetReceived(EventSet set) {
0N/A currentEventSet = set;
0N/A }
0N/A
0N/A public void vmDied(VMDeathEvent event) {
0N/A if (event.request() == deathRequest) {
0N/A requestedVMDeathOccurred = true;
0N/A println("Got requested VMDeathEvent");
0N/A if (currentEventSet.suspendPolicy() !=
0N/A EventRequest.SUSPEND_ALL) {
0N/A failure("failure: wrong suspend policy");
0N/A }
0N/A } else if (event.request() == null) {
0N/A defaultVMDeathOccurred = true;
0N/A println("Got default VMDeathEvent");
0N/A } else {
0N/A failure("failure: Unexpected type of VMDeathEvent occurred");
0N/A }
0N/A }
0N/A
0N/A public void vmDisconnected(VMDisconnectEvent event) {
0N/A println("Got VMDisconnectEvent");
0N/A disconnected = true;
0N/A synchronized (syncer) {
0N/A syncer.notifyAll();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Turn off default VMDeath handling
0N/A */
0N/A protected void createDefaultVMDeathRequest() {
0N/A }
0N/A
0N/A /********** test core **********/
0N/A
0N/A protected void runTests() throws Exception {
0N/A
0N/A startToMain("HelloWorld");
0N/A
0N/A deathRequest = eventRequestManager().createVMDeathRequest();
0N/A deathRequest.enable();
0N/A
0N/A /*
0N/A * Static tests
0N/A */
0N/A List reqs = eventRequestManager().vmDeathRequests();
0N/A if (reqs.size() != 1 || reqs.get(0) != deathRequest) {
0N/A failure("failure: vmDeathRequests()");
0N/A }
0N/A if (!vm().canRequestVMDeathEvent()) {
0N/A failure("failure: canRequestVMDeathEvent() returned false");
0N/A }
0N/A
0N/A /*
0N/A * Event tests
0N/A */
0N/A addListener(this);
0N/A synchronized (syncer) {
0N/A vm().resume();
0N/A while (!disconnected) {
0N/A try {
0N/A syncer.wait();
0N/A } catch (InterruptedException e) {
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Failure analysis
0N/A */
0N/A if (!requestedVMDeathOccurred) {
0N/A failure("failure: didn't get requested VMDeathEvent");
0N/A }
0N/A if (!defaultVMDeathOccurred) {
0N/A failure("failure: didn't get default VMDeathEvent");
0N/A }
0N/A
0N/A if (!testFailed) {
0N/A println("VMDeathRequestTest: passed");
0N/A } else {
0N/A throw new Exception("VMDeathRequestTest: failed");
0N/A }
0N/A }
0N/A}