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.2 $
022: */
023:
024: /**
025: * Created on 22.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
027:
028: import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
029: import org.apache.harmony.jpda.tests.framework.LogWriter;
030: import org.apache.harmony.jpda.tests.framework.TestOptions;
031: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
032: import org.apache.harmony.jpda.tests.share.SyncDebuggee;
033:
034: /**
035: * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.StopTest</code>.
036: * This debuggee starts the tested thread <code>TESTED_THREAD</code> which waits for
037: * 'Stop' command with NullPointerException exception.
038: */
039: public class StopDebuggee extends SyncDebuggee {
040:
041: static Object waitTimeObject = new Object();
042:
043: static void waitMlsecsTime(long mlsecsTime) {
044: synchronized (waitTimeObject) {
045: try {
046: waitTimeObject.wait(mlsecsTime);
047: } catch (Throwable throwable) {
048: // ignore
049: }
050: }
051: }
052:
053: static Object waitTimeObjectWithException = new Object();
054:
055: static void waitMlsecsTimeWithException(long mlsecsTime)
056: throws Throwable {
057: synchronized (waitTimeObject) {
058: try {
059: waitTimeObject.wait(mlsecsTime);
060: } catch (Throwable throwable) {
061: throw throwable;
062: }
063: }
064: }
065:
066: public static String testStatus = "PASSED";
067: public static final String TESTED_THREAD = "TestedThread";
068: public static final String FIELD_NAME = "exception";
069: // public static final String EXCEPTION_SIGNATURE = "Ljava/lang/NullPointerException;";
070: public static NullPointerException exception = new NullPointerException();
071:
072: static Object waitForStart = new Object();
073:
074: public void run() {
075: logWriter.println("StopDebuggee: started");
076: DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
077: logWriter, synchronizer);
078:
079: synchronized (waitForStart) {
080: thrd.start();
081: try {
082: waitForStart.wait();
083: } catch (InterruptedException e) {
084: logWriter.println("StopDebuggee:" + e
085: + " is cought while waitForStart.wait()");
086: }
087: }
088:
089: logWriter
090: .println("StopDebuggee: Wait for TestedThread to finish...");
091: while (thrd.isAlive()) {
092: waitMlsecsTime(1000);
093: }
094: logWriter.println("StopDebuggee: TestedThread finished");
095:
096: synchronizer.sendMessage(testStatus);
097: logWriter.println("StopDebuggee: finishing...");
098: }
099:
100: class DebuggeeThread extends Thread {
101:
102: LogWriter logWriter;
103: DebuggeeSynchronizer synchronizer;
104:
105: public DebuggeeThread(String name, LogWriter logWriter,
106: DebuggeeSynchronizer synchronizer) {
107: super (name);
108: this .logWriter = logWriter;
109: this .synchronizer = synchronizer;
110: }
111:
112: public void run() {
113: logWriter.println(getName() + ": started");
114: synchronized (waitForStart) {
115: waitForStart.notifyAll();
116: }
117:
118: logWriter
119: .println(getName()
120: + ": Wait for 'Stop' command with NullPointerException...");
121: try {
122: synchronizer
123: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
124: waitMlsecsTimeWithException(TestOptions.DEFAULT_TIMEOUT);
125: logWriter
126: .println(getName()
127: + ": FAILED: TIMEOUT is run out - No any exception is caught");
128: testStatus = "FAILED";
129: } catch (Throwable thrown) {
130: logWriter.println(getName() + ": Exception is caught: "
131: + thrown);
132: if (thrown.equals(exception)) {
133: logWriter.println(getName()
134: + ": PASSED: It is expected Exception");
135: } else {
136: logWriter.println(getName()
137: + ": FAILED: It is unexpected Exception");
138: testStatus = "FAILED";
139: }
140: }
141: }
142: }
143:
144: public static void main(String[] args) {
145: runDebuggee(StopDebuggee.class);
146: }
147: }
|