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_START event after re-connection. 39 */ 40 public class ThreadStartTest extends JDWPEventTestCase { 41 /** 42 * This testcase verifies canceling of THREAD_START event after re-connection. 43 * <BR>It runs EventDebuggee, sets request for THREAD_START event 44 * and re-connects. 45 * <BR>It is expected that no any events, including THREAD_START, occur after re-connection 46 * and before EventDebuggee finish. 47 */ 48 public void testThreadStart001() { 49 logWriter.println("==> testThreadStart001 - STARTED..."); 50 51 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 52 53 logWriter.println("=> set ThreadStartEvent..."); 54 ReplyPacket reply = 55 debuggeeWrapper.vmMirror.setThreadStart(JDWPConstants.SuspendPolicy.NONE); 56 checkReplyPacket(reply, "Set THREAD_START event"); 57 58 logWriter.println("=> set ThreadStartEvent - 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 } 85 if (event == null) { 86 logWriter.println("=> It's expected result, nothing was caught"); 87 logWriter.println("=> Resuming debuggee"); 88 //resuming debuggee 89 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 90 logWriter.println("==> testThreadStart001 PASSED! "); 91 } else { 92 93 logWriter.println("##FAILURE: Event was received"); 94 95 try { 96 ParsedEvent[] parsedEvents = ParsedEvent.parseEventPacket(event); 97 logWriter.println("=> Number of events = " + parsedEvents.length); 98 for (int i = 0; i < parsedEvents.length; i++) { 99 logWriter.println("=> EventKind() = " 100 + parsedEvents[0].getEventKind() 101 + " (" 102 + JDWPConstants.EventKind.getName(parsedEvents[0] 103 .getEventKind()) + ")"); 104 logWriter.println("=> EventRequestID() = " 105 + parsedEvents[0].getRequestID()); 106 107 } 108 } catch (Throwable thrown) { 109 logWriter.println("##FAILURE: Exception while analyzing received event:" 110 + thrown); 111 fail("##FAILURE: Exception while analyzing received event:" + thrown); 112 } 113 114 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 115 logWriter.println("==> testThreadStart001 PASSED"); 116 } 117 } 118 119 @Override 120 protected void beforeConnectionSetUp() { 121 settings.setAttachConnectorKind(); 122 if (settings.getTransportAddress() == null) { 123 settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS); 124 } 125 logWriter.println("ATTACH connector kind"); 126 super.beforeConnectionSetUp(); 127 } 128 } 129