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_END event after re-connection.
041: */
042: public class ThreadEndTest extends JDWPEventTestCase {
043:
044: public static void main(String[] args) {
045: junit.textui.TestRunner.run(ThreadEndTest.class);
046: }
047:
048: /**
049: * This testcase verifies canceling of THREAD_END event after re-connection.
050: * <BR>It runs EventDebuggee, sets request for THREAD_END event
051: * and re-connects.
052: * <BR>It is expected that no any events, including THREAD_END, occur after re-connection
053: * and before EventDebuggee finish.
054: */
055: public void testThreadEnd001() {
056: logWriter.println("==> testThreadEnd001 - STARTED...");
057:
058: synchronizer
059: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
060:
061: logWriter.println("=> set ThreadEndEvent...");
062: ReplyPacket reply;
063: byte eventKind = JDWPConstants.EventKind.THREAD_END;
064: byte suspendPolicy = JDWPConstants.SuspendPolicy.NONE;
065: EventMod[] mods = new EventMod[0];
066: Event eventToSet = new Event(eventKind, suspendPolicy, mods);
067:
068: reply = debuggeeWrapper.vmMirror.setEvent(eventToSet);
069: checkReplyPacket(reply, "Set THREAD_END event");
070:
071: logWriter.println("=> set ThreadEndEvent - DONE");
072:
073: logWriter.println("");
074: logWriter.println("=> CLOSE CONNECTION");
075: closeConnection();
076: logWriter.println("=> CONNECTION CLOSED");
077:
078: logWriter.println("");
079: logWriter.println("=> OPEN NEW CONNECTION");
080: openConnection();
081: logWriter.println("=> CONNECTION OPENED");
082:
083: logWriter.println("=> Resuming debuggee");
084:
085: // start the thread
086: synchronizer
087: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
088: // wait for thread start and finish
089: synchronizer
090: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
091:
092: logWriter.println("=> vmMirror.receiveEvent()...");
093: CommandPacket event = null;
094: try {
095: event = debuggeeWrapper.vmMirror.receiveEvent();
096: } catch (TestErrorException thrown) {
097: logWriter.println("=> Exception while receiving event:"
098: + thrown);
099: }
100: if (event == null) {
101: logWriter
102: .println("=> It's expected result, nothing was caught");
103: logWriter.println("=> Resuming debuggee");
104: //resuming debuggee
105: synchronizer
106: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
107: logWriter.println("==> testThreadStart001 PASSED! ");
108: } else {
109: logWriter.println("##FAILURE: Event was received");
110: try {
111: ParsedEvent[] parsedEvents = ParsedEvent
112: .parseEventPacket(event);
113: logWriter.println("=> Number of events = "
114: + parsedEvents.length);
115: for (int i = 0; i < parsedEvents.length; i++) {
116: logWriter.println("=> EventKind() = "
117: + parsedEvents[0].getEventKind()
118: + " ("
119: + JDWPConstants.EventKind
120: .getName(parsedEvents[0]
121: .getEventKind()) + ")");
122: logWriter.println("=> EventRequestID() = "
123: + parsedEvents[0].getRequestID());
124:
125: }
126: } catch (Throwable thrown) {
127: logWriter
128: .println("##FAILURE: Exception while analyzing received event:"
129: + thrown);
130: fail("##FAILURE: Exception while analyzing received event:"
131: + thrown);
132: }
133:
134: synchronizer
135: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
136: logWriter.println("==> testThreadEnd001 PASSED");
137: }
138: }
139:
140: protected void beforeDebuggeeStart(
141: JDWPUnitDebuggeeWrapper debuggeeWrapper) {
142: settings.setAttachConnectorKind();
143: if (settings.getTransportAddress() == null) {
144: settings
145: .setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
146: }
147: logWriter.println("ATTACH connector kind");
148: super.beforeDebuggeeStart(debuggeeWrapper);
149: }
150: }
|