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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -67,46 +67,34 @@
             final BlockingDeque<Object> deq =
                 (q instanceof BlockingDeque<?>) ?
                 (BlockingDeque<Object>) q : null;
             q.clear();
             List<Fun> fs = new ArrayList<Fun>();
-            fs.add(new Fun() { void f() throws Throwable
-                    { q.take(); }});
-            fs.add(new Fun() { void f() throws Throwable
-                    { q.poll(60, SECONDS); }});
+            fs.add(() -> q.take());
+            fs.add(() -> q.poll(60, SECONDS));
             if (deq != null) {
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.takeFirst(); }});
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.takeLast(); }});
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.pollFirst(7, SECONDS); }});
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.pollLast(7, SECONDS); }});
+                fs.add(() -> deq.takeFirst());
+                fs.add(() -> deq.takeLast());
+                fs.add(() -> deq.pollFirst(7, SECONDS));
+                fs.add(() -> deq.pollLast(7, SECONDS));
             }
 
             checkInterrupted(fs);
 
             // fill q to capacity, to ensure insertions will block
             while (q.remainingCapacity() > 0)
                 try { q.put(1); }
                 catch (Throwable t) { unexpected(t); }
 
             fs.clear();
-            fs.add(new Fun() { void f() throws Throwable
-                    { q.put(1); }});
-            fs.add(new Fun() { void f() throws Throwable
-                    { q.offer(1, 7, SECONDS); }});
+            fs.add(() -> q.put(1));
+            fs.add(() -> q.offer(1, 7, SECONDS));
             if (deq != null) {
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.putFirst(1); }});
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.putLast(1); }});
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.offerFirst(1, 7, SECONDS); }});
-                fs.add(new Fun() { void f() throws Throwable
-                        { deq.offerLast(1, 7, SECONDS); }});
+                fs.add(() -> deq.putFirst(1));
+                fs.add(() -> deq.putLast(1));
+                fs.add(() -> deq.offerFirst(1, 7, SECONDS));
+                fs.add(() -> deq.offerLast(1, 7, SECONDS));
             }
             checkInterrupted(fs);
         } catch (Throwable t) {
           System.out.printf("Failed: %s%n", q.getClass().getSimpleName());
           unexpected(t);

@@ -133,7 +121,7 @@
         else fail(x + " not equal to " + y);}
     public static void main(String[] args) throws Throwable {
         try {realMain(args);} catch (Throwable t) {unexpected(t);}
         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
         if (failed > 0) throw new AssertionError("Some tests failed");}
-    private abstract static class Fun {abstract void f() throws Throwable;}
+    @FunctionalInterface interface Fun {void f() throws Throwable;}
 }