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 Vitaly A. Provodin
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 18.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
031: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
033: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035: /**
036: * JDWP Unit test for ThreadReference.Interrupt command.
037: */
038: public class InterruptTest extends JDWPSyncTestCase {
039:
040: static String waitForString = "java.lang.InterruptedException";
041: boolean isReceived = false;
042:
043: protected String getDebuggeeClassName() {
044: return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.InterruptDebuggee";
045: }
046:
047: /**
048: * This testcase exercises ThreadReference.Interrupt command.
049: * <BR>At first the test starts InterruptDebuggee which runs
050: * the tested thread 'TESTED_THREAD' and blocks it in invocation of
051: * the 'wait()' method.
052: * <BR> Then the tests performs the ThreadReference.Interrupt command
053: * for tested thread.
054: * <BR>After sending Interrupt command, the test waits signals via synchronization
055: * channel that 'InterruptedException' was thrown.
056: */
057: public void testInterrupt001() {
058: synchronizer
059: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
060:
061: // getting ID of the tested thread
062: logWriter.println("get thread ID");
063: long threadID = debuggeeWrapper.vmMirror
064: .getThreadID(InterruptDebuggee.TESTED_THREAD);
065:
066: // getting the thread group ID
067: CommandPacket packet = new CommandPacket(
068: JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
069: JDWPCommands.ThreadReferenceCommandSet.InterruptCommand);
070: packet.setNextValueAsThreadID(threadID);
071: logWriter.println("send \"Interrupt\" command");
072:
073: ReplyPacket reply = debuggeeWrapper.vmMirror
074: .performCommand(packet);
075:
076: short err = reply.getErrorCode();
077: logWriter.println("error = " + err);
078:
079: if (err == JDWPConstants.Error.NONE) {
080: Thread thrd = new RecvThread();
081: thrd.start();
082: try {
083: thrd.join(settings.getTimeout());
084: } catch (InterruptedException e) {
085:
086: }
087: }
088:
089: if (!isReceived) {
090: printErrorAndFail(waitForString + " is not received");
091: } else {
092: logWriter.println(waitForString + " is received");
093: }
094: synchronizer
095: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
096: }
097:
098: class RecvThread extends Thread {
099:
100: public void run() {
101: logWriter.println("wait for " + waitForString);
102: isReceived = synchronizer.receiveMessage(waitForString);
103: }
104:
105: }
106:
107: public static void main(String[] args) {
108: junit.textui.TestRunner.run(InterruptTest.class);
109: }
110: }
|