001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Aleksander V. Budniy
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 11.03.2005
026: */package org.apache.harmony.jpda.tests.jdwp.MultiSession;
027:
028: import org.apache.harmony.jpda.tests.framework.TestOptions;
029: import org.apache.harmony.jpda.tests.framework.TestErrorException;
030: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
031: import org.apache.harmony.jpda.tests.framework.jdwp.Event;
032: import org.apache.harmony.jpda.tests.framework.jdwp.EventMod;
033: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
034: import org.apache.harmony.jpda.tests.framework.jdwp.ParsedEvent;
035: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
036: import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
037: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
038:
039: /**
040: * JDWP Unit test for verifying canceling of THREAD_START event after re-connection.
041: */
042: public class ThreadStartTest extends JDWPEventTestCase {
043:
044: public static void main(String[] args) {
045: junit.textui.TestRunner.run(ThreadStartTest.class);
046: }
047:
048: /**
049: * This testcase verifies canceling of THREAD_START event after re-connection.
050: * <BR>It runs EventDebuggee, sets request for THREAD_START event
051: * and re-connects.
052: * <BR>It is expected that no any events, including THREAD_START, occur after re-connection
053: * and before EventDebuggee finish.
054: */
055: public void testThreadStart001() {
056: logWriter.println("==> testThreadStart001 - STARTED...");
057:
058: synchronizer
059: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
060:
061: logWriter.println("=> set ThreadStartEvent...");
062: ReplyPacket reply;
063: // reply = debuggeeWrapper.vmMirror.setThreadStart();
064: byte eventKind = JDWPConstants.EventKind.THREAD_START;
065: byte suspendPolicy = JDWPConstants.SuspendPolicy.NONE;
066: EventMod[] mods = new EventMod[0];
067: Event eventToSet = new Event(eventKind, suspendPolicy, mods);
068:
069: reply = debuggeeWrapper.vmMirror.setEvent(eventToSet);
070: checkReplyPacket(reply, "Set THREAD_START event");
071:
072: logWriter.println("=> set ThreadStartEvent - DONE");
073:
074: logWriter.println("");
075: logWriter.println("=> CLOSE CONNECTION");
076: closeConnection();
077: logWriter.println("=> CONNECTION CLOSED");
078:
079: logWriter.println("");
080: logWriter.println("=> OPEN NEW CONNECTION");
081: openConnection();
082: logWriter.println("=> CONNECTION OPENED");
083:
084: logWriter.println("=> Resuming debuggee");
085:
086: // start the thread
087: synchronizer
088: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
089: // wait for thread start and finish
090: synchronizer
091: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
092:
093: logWriter.println("=> vmMirror.receiveEvent()...");
094: CommandPacket event = null;
095: try {
096: event = debuggeeWrapper.vmMirror.receiveEvent();
097: } catch (TestErrorException thrown) {
098: logWriter.println("=> Exception while receiving event:"
099: + thrown);
100:
101: }
102: if (event == null) {
103: logWriter
104: .println("=> It's expected result, nothing was caught");
105: logWriter.println("=> Resuming debuggee");
106: //resuming debuggee
107: synchronizer
108: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
109: logWriter.println("==> testThreadStart001 PASSED! ");
110: } else {
111:
112: logWriter.println("##FAILURE: Event was received");
113:
114: try {
115: ParsedEvent[] parsedEvents = ParsedEvent
116: .parseEventPacket(event);
117: logWriter.println("=> Number of events = "
118: + parsedEvents.length);
119: for (int i = 0; i < parsedEvents.length; i++) {
120: logWriter.println("=> EventKind() = "
121: + parsedEvents[0].getEventKind()
122: + " ("
123: + JDWPConstants.EventKind
124: .getName(parsedEvents[0]
125: .getEventKind()) + ")");
126: logWriter.println("=> EventRequestID() = "
127: + parsedEvents[0].getRequestID());
128:
129: }
130: } catch (Throwable thrown) {
131: logWriter
132: .println("##FAILURE: Exception while analyzing received event:"
133: + thrown);
134: fail("##FAILURE: Exception while analyzing received event:"
135: + thrown);
136: }
137:
138: synchronizer
139: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
140: logWriter.println("==> testThreadStart001 PASSED");
141: }
142: }
143:
144: protected void beforeDebuggeeStart(
145: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
146: settings.setAttachConnectorKind();
147: if (settings.getTransportAddress() == null) {
148: settings
149: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
150: }
151: logWriter.println("ATTACH connector kind");
152: super.beforeDebuggeeStart(debuggeeWrapper);
153: }
154: }
|