Path: blob/master/test/jdk/com/sun/jdi/ExpiredRequestDeletionTest.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 445331026* @summary Test the deletion of event requests that are expired27* by virtue of addCountFilter.28*29* @author Robert Field30*31* @run build TestScaffold VMConnection TargetListener TargetAdapter32* @run compile -g ExpiredRequestDeletionTest.java33* @run driver ExpiredRequestDeletionTest34*/35import com.sun.jdi.*;36import com.sun.jdi.event.*;37import com.sun.jdi.request.*;3839import java.util.*;4041/********** target program **********/4243class ExpiredRequestDeletionTarg {44int foo = 9;4546public static void main(String[] args){47System.out.println("Why, hello there...");48(new ExpiredRequestDeletionTarg()).bar();49}5051void bar() {52++foo;53}54}5556/********** test program **********/5758public class ExpiredRequestDeletionTest extends TestScaffold {59EventRequestManager erm;60ReferenceType targetClass;61ThreadReference mainThread;62Throwable throwable = null;6364ExpiredRequestDeletionTest (String args[]) {65super(args);66}6768public static void main(String[] args) throws Exception {69new ExpiredRequestDeletionTest(args).startTests();70}7172/********** event handlers **********/7374public void breakpointReached(BreakpointEvent event) {75try {76EventRequest req = event.request();77if (req != null) {78println("Deleting BreakpointRequest");79erm.deleteEventRequest(req);80} else {81println("Got BreakpointEvent with null request");82}83} catch (Throwable exc) {84throwable = exc;85failure("Deleting BreakpointRequest threw - " + exc);86}87}8889public void stepCompleted(StepEvent event) {90try {91EventRequest req = event.request();92if (req != null) {93println("Deleting StepRequest");94erm.deleteEventRequest(req);95} else {96println("Got StepEvent with null request");97}98} catch (Throwable exc) {99throwable = exc;100failure("Deleting StepRequest threw - " + exc);101}102}103104/********** test core **********/105106protected void runTests() throws Exception {107/*108* Get to the top of main()109* to determine targetClass and mainThread110*/111BreakpointEvent bpe = startToMain("ExpiredRequestDeletionTarg");112targetClass = bpe.location().declaringType();113mainThread = bpe.thread();114erm = vm().eventRequestManager();115116List meths = targetClass.methodsByName("bar");117if (meths.size() != 1) {118throw new Exception("test error: should be one bar()");119}120Method barMethod = (Method)meths.get(0);121122/*123* Set event requests124*/125StepRequest sr = erm.createStepRequest(mainThread,126StepRequest.STEP_LINE,127StepRequest.STEP_OVER);128sr.addCountFilter(1);129sr.enable();130131BreakpointRequest bpr =132erm.createBreakpointRequest(barMethod.location());133bpr.addCountFilter(1);134bpr.enable();135136/*137* resume the target listening for events138*/139listenUntilVMDisconnect();140141/*142* deal with results of test143* if anything has called failure("foo") testFailed will be true144*/145if (!testFailed) {146println("ExpiredRequestDeletionTest: passed");147} else {148throw new Exception("ExpiredRequestDeletionTest: failed", throwable);149}150}151}152153154