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: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Elena Semukhina
020: * @version $Revision$
021: */package java.lang;
022:
023: import junit.framework.TestCase;
024:
025: public class ThreadRTest extends TestCase {
026:
027: private class ThreadRunning extends Thread {
028: volatile boolean stopWork = false;
029: int i = 0;
030:
031: ThreadRunning() {
032: super ();
033: }
034:
035: ThreadRunning(ThreadGroup g, String name) {
036: super (g, name);
037: }
038:
039: public void run() {
040: while (!stopWork) {
041: i++;
042: }
043: }
044: }
045:
046: public void testGetThreadGroupDeadThread() {
047: ThreadRunning t = new ThreadRunning();
048: t.start();
049: t.stopWork = true;
050: try {
051: t.join();
052: } catch (InterruptedException e) {
053: e.printStackTrace();
054: }
055: try {
056: t.getThreadGroup();
057: t.getThreadGroup();
058: } catch (NullPointerException e) {
059: fail("NullPointerException has been thrown");
060: }
061: }
062:
063: /*
064: * Regression test for Harmony-917
065: */
066: public void testJoinJI() throws Exception {
067: Thread th = new Thread();
068:
069: long mls = 688204075024689866L;
070: int nn = -10000;
071: try {
072: th.join(mls, nn);
073: fail("1: test failed");
074: } catch (IllegalArgumentException e) {
075: //expected
076: }
077:
078: mls = -1000000000000L;
079: nn = 90000;
080: try {
081: th.join(mls, nn);
082: fail("2: test failed");
083: } catch (IllegalArgumentException e) {
084: //expected
085: }
086:
087: mls = 10000000000000L;
088: nn = 1000001;
089: try {
090: th.join(mls, nn);
091: fail("3: Test failed");
092: } catch (IllegalArgumentException e) {
093: //expected
094: }
095: }
096:
097: static class TT implements Runnable {
098: public volatile boolean started = false;
099: public volatile boolean finished = false;
100:
101: public void run() {
102: started = true;
103: try {
104: synchronized (this ) {
105: while (true) {
106: }
107: }
108: } finally {
109: finished = true;
110: }
111: }
112: }
113:
114: /*
115: * Regression test for Harmony-3116
116: */
117: public void testStopFinally() throws Exception {
118: TT tt = new TT();
119: Thread t = new Thread(tt);
120: t.start();
121: while (!tt.started) {
122: }
123: t.stop();
124:
125: int count = 300;
126: while (!tt.finished && count-- > 0) {
127: Thread.sleep(100);
128: }
129: assertTrue(tt.finished);
130: }
131:
132: }
|