Thread_isInterrupted05.java revision 13083:b9a173f12fe6
1219820Sjeff/*
2219820Sjeff * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3219820Sjeff * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4219820Sjeff *
5219820Sjeff * This code is free software; you can redistribute it and/or modify it
6219820Sjeff * under the terms of the GNU General Public License version 2 only, as
7219820Sjeff * published by the Free Software Foundation.
8219820Sjeff *
9219820Sjeff * This code is distributed in the hope that it will be useful, but WITHOUT
10219820Sjeff * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11219820Sjeff * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12219820Sjeff * version 2 for more details (a copy is included in the LICENSE file that
13219820Sjeff * accompanied this code).
14219820Sjeff *
15219820Sjeff * You should have received a copy of the GNU General Public License version
16219820Sjeff * 2 along with this work; if not, write to the Free Software Foundation,
17219820Sjeff * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18219820Sjeff *
19219820Sjeff * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20219820Sjeff * or visit www.oracle.com if you need additional information or have any
21219820Sjeff * questions.
22219820Sjeff */
23219820Sjeffpackage org.graalvm.compiler.jtt.threads;
24219820Sjeff
25219820Sjeffimport org.graalvm.compiler.jtt.JTTTest;
26219820Sjeffimport org.junit.Rule;
27219820Sjeffimport org.junit.Test;
28219820Sjeffimport org.junit.rules.DisableOnDebug;
29219820Sjeffimport org.junit.rules.TestRule;
30219820Sjeffimport org.junit.rules.Timeout;
31219820Sjeff
32219820Sjeff/*
33219820Sjeff */
34219820Sjeff
35219820Sjeff// Interrupted during wait, with interrupter joining
36219820Sjeffpublic class Thread_isInterrupted05 extends JTTTest {
37219820Sjeff
38219820Sjeff    @Rule public TestRule timeout = new DisableOnDebug(Timeout.seconds(20));
39219820Sjeff
40219820Sjeff    public static boolean test() throws InterruptedException {
41219820Sjeff        final WaitInterruptee waitInterruptee = new WaitInterruptee();
42219820Sjeff        waitInterruptee.start();
43219820Sjeff        waitInterruptee.interrupt();
44219820Sjeff        waitInterruptee.join();
45219820Sjeff
46219820Sjeff        if (waitInterruptee.throwable != null) {
47219820Sjeff            throw new RuntimeException(waitInterruptee.throwable);
48219820Sjeff        }
49219820Sjeff        return true;
50219820Sjeff    }
51219820Sjeff
52219820Sjeff    static class WaitInterruptee extends Thread {
53219820Sjeff
54219820Sjeff        Throwable throwable;
55219820Sjeff
56219820Sjeff        WaitInterruptee() {
57219820Sjeff            super("WaitInterruptee");
58219820Sjeff        }
59219820Sjeff
60219820Sjeff        @Override
61219820Sjeff        public void run() {
62219820Sjeff            try {
63219820Sjeff                synchronized (this) {
64219820Sjeff                    try {
65219820Sjeff                        wait();
66219820Sjeff                    } catch (InterruptedException ex) {
67219820Sjeff                    }
68219820Sjeff                }
69219820Sjeff            } catch (Throwable t) {
70219820Sjeff                throwable = t;
71219820Sjeff            }
72219820Sjeff        }
73219820Sjeff    }
74219820Sjeff
75219820Sjeff    @Test
76219820Sjeff    public void run0() throws Throwable {
77219820Sjeff        initializeForTimeout();
78219820Sjeff        runTest("test");
79219820Sjeff    }
80219820Sjeff
81219820Sjeff}
82219820Sjeff