< prev index next >

test/jdk/java/util/concurrent/BlockingQueue/Interrupt.java

Print this page
rev 51731 : imported patch 8210732


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6384064
  27  * @summary Check proper handling of interrupts
  28  * @author Martin Buchholz
  29  * @library /lib/testlibrary/
  30  */
  31 
  32 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  33 
  34 import java.util.ArrayList;
  35 import java.util.List;
  36 import java.util.concurrent.ArrayBlockingQueue;
  37 import java.util.concurrent.BlockingDeque;
  38 import java.util.concurrent.BlockingQueue;
  39 import java.util.concurrent.LinkedBlockingDeque;
  40 import java.util.concurrent.LinkedBlockingQueue;
  41 import java.util.concurrent.SynchronousQueue;
  42 import java.util.concurrent.Executor;
  43 import java.util.concurrent.ScheduledThreadPoolExecutor;
  44 import jdk.testlibrary.Utils;
  45 
  46 public class Interrupt {
  47     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  48 
  49     static void checkInterrupted0(Iterable<Fun> fs, Executor ex) {
  50         for (Fun f : fs) {
  51             try {
  52                 ex.execute(new Runnable() {
  53                         final Thread thisThread = Thread.currentThread();
  54                         public void run() { thisThread.interrupt(); }});
  55                 f.f();
  56                 fail("Expected InterruptedException not thrown");
  57             } catch (InterruptedException e) {
  58                 check(! Thread.interrupted());
  59             } catch (Throwable t) { unexpected(t); }
  60         }
  61     }
  62 
  63     static void checkInterrupted(Iterable<Fun> fs)
  64             throws InterruptedException {




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6384064
  27  * @summary Check proper handling of interrupts
  28  * @author Martin Buchholz
  29  * @library /test/lib
  30  */
  31 
  32 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  33 
  34 import java.util.ArrayList;
  35 import java.util.List;
  36 import java.util.concurrent.ArrayBlockingQueue;
  37 import java.util.concurrent.BlockingDeque;
  38 import java.util.concurrent.BlockingQueue;
  39 import java.util.concurrent.LinkedBlockingDeque;
  40 import java.util.concurrent.LinkedBlockingQueue;
  41 import java.util.concurrent.SynchronousQueue;
  42 import java.util.concurrent.Executor;
  43 import java.util.concurrent.ScheduledThreadPoolExecutor;
  44 import jdk.test.lib.Utils;
  45 
  46 public class Interrupt {
  47     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  48 
  49     static void checkInterrupted0(Iterable<Fun> fs, Executor ex) {
  50         for (Fun f : fs) {
  51             try {
  52                 ex.execute(new Runnable() {
  53                         final Thread thisThread = Thread.currentThread();
  54                         public void run() { thisThread.interrupt(); }});
  55                 f.f();
  56                 fail("Expected InterruptedException not thrown");
  57             } catch (InterruptedException e) {
  58                 check(! Thread.interrupted());
  59             } catch (Throwable t) { unexpected(t); }
  60         }
  61     }
  62 
  63     static void checkInterrupted(Iterable<Fun> fs)
  64             throws InterruptedException {


< prev index next >