1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Aleksander V. Budniy 21 */ 22 23 /** 24 * Created on 11.03.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.MultiSession; 27 28 import org.apache.harmony.jpda.tests.framework.TestOptions; 29 import org.apache.harmony.jpda.tests.framework.TestErrorException; 30 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants; 32 import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent; 33 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 34 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 35 36 37 /** 38 * JDWP Unit test for verifying canceling of THREAD_END event after re-connection. 39 */ 40 public class ThreadEndTest extends JDWPEventTestCase { 41 /** 42 * This testcase verifies canceling of THREAD_END event after re-connection. 43 * <BR>It runs EventDebuggee, sets request for THREAD_END event 44 * and re-connects. 45 * <BR>It is expected that no any events, including THREAD_END, occur after re-connection 46 * and before EventDebuggee finish. 47 */ 48 public void testThreadEnd001() { 49 logWriter.println("==> testThreadEnd001 - STARTED..."); 50 51 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 52 53 logWriter.println("=> set ThreadEndEvent..."); 54 ReplyPacket reply = 55 debuggeeWrapper.vmMirror.setThreadEnd(JDWPConstants.SuspendPolicy.NONE); 56 checkReplyPacket(reply, "Set THREAD_END event"); 57 58 logWriter.println("=> set ThreadEndEvent - DONE"); 59 60 logWriter.println(""); 61 logWriter.println("=> CLOSE CONNECTION"); 62 closeConnection(); 63 logWriter.println("=> CONNECTION CLOSED"); 64 65 logWriter.println(""); 66 logWriter.println("=> OPEN NEW CONNECTION"); 67 openConnection(); 68 logWriter.println("=> CONNECTION OPENED"); 69 70 logWriter.println("=> Resuming debuggee"); 71 72 // start the thread 73 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 74 // wait for thread start and finish 75 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 76 77 logWriter.println("=> vmMirror.receiveEvent()..."); 78 CommandPacket event = null; 79 try { 80 event = debuggeeWrapper.vmMirror.receiveEvent(); 81 } catch (TestErrorException thrown) { 82 logWriter.println("=> Exception while receiving event:" + thrown); 83 } 84 if (event == null) { 85 logWriter.println("=> It's expected result, nothing was caught"); 86 logWriter.println("=> Resuming debuggee"); 87 //resuming debuggee 88 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 89 logWriter.println("==> testThreadStart001 PASSED! "); 90 } else { 91 logWriter.println("##FAILURE: Event was received"); 92 try { 93 ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event); 94 logWriter.println("=> Number of events = " + parsedEvents.length); 95 for (int i = 0; i < parsedEvents.length; i++) { 96 logWriter.println("=> EventKind() = " 97 + parsedEvents[0].getEventKind() 98 + " (" 99 + JDWPConstants.EventKind.getName(parsedEvents[0] 100 .getEventKind()) + ")"); 101 logWriter.println("=> EventRequestID() = " 102 + parsedEvents[0].getRequestID()); 103 104 } 105 } catch (Throwable thrown) { 106 logWriter.println("##FAILURE: Exception while analyzing received event:" 107 + thrown); 108 fail("##FAILURE: Exception while analyzing received event:" + thrown); 109 } 110 111 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 112 logWriter.println("==> testThreadEnd001 PASSED"); 113 } 114 } 115 116 @Override 117 protected void beforeConnectionSetUp() { 118 settings.setAttachConnectorKind(); 119 if (settings.getTransportAddress() == null) { 120 settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS); 121 } 122 logWriter.println("ATTACH connector kind"); 123 super.beforeConnectionSetUp(); 124 } 125 } 126