ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/LinkedTransferQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/LinkedTransferQueueTest.java (file contents):
Revision 1.60 by jsr166, Fri May 15 18:21:19 2015 UTC vs.
Revision 1.63 by jsr166, Sun Oct 4 18:49:02 2015 UTC

# Line 24 | Line 24 | import junit.framework.Test;
24  
25   @SuppressWarnings({"unchecked", "rawtypes"})
26   public class LinkedTransferQueueTest extends JSR166TestCase {
27 +    static class Implementation implements CollectionImplementation {
28 +        public Class<?> klazz() { return LinkedTransferQueue.class; }
29 +        public Collection emptyCollection() { return new LinkedTransferQueue(); }
30 +        public Object makeElement(int i) { return i; }
31 +        public boolean isConcurrent() { return true; }
32 +        public boolean permitsNulls() { return false; }
33 +    }
34  
35      public static class Generic extends BlockingQueueTest {
36          protected BlockingQueue emptyCollection() {
# Line 37 | Line 44 | public class LinkedTransferQueueTest ext
44  
45      public static Test suite() {
46          return newTestSuite(LinkedTransferQueueTest.class,
47 <                            new Generic().testSuite());
47 >                            new Generic().testSuite(),
48 >                            CollectionTest.testSuite(new Implementation()));
49      }
50  
51      /**
# Line 78 | Line 86 | public class LinkedTransferQueueTest ext
86       */
87      public void testConstructor4() {
88          Integer[] ints = new Integer[SIZE];
89 <        for (int i = 0; i < SIZE-1; ++i)
89 >        for (int i = 0; i < SIZE - 1; ++i)
90              ints[i] = i;
91          Collection<Integer> elements = Arrays.asList(ints);
92          try {
# Line 588 | Line 596 | public class LinkedTransferQueueTest ext
596      public void testOfferInExecutor() {
597          final LinkedTransferQueue q = new LinkedTransferQueue();
598          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
599 <        ExecutorService executor = Executors.newFixedThreadPool(2);
600 <
593 <        executor.execute(new CheckedRunnable() {
594 <            public void realRun() throws InterruptedException {
595 <                threadsStarted.await();
596 <                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
597 <            }});
598 <
599 <        executor.execute(new CheckedRunnable() {
600 <            public void realRun() throws InterruptedException {
601 <                threadsStarted.await();
602 <                assertSame(one, q.take());
603 <                checkEmpty(q);
604 <            }});
599 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
600 >        try (PoolCleaner cleaner = cleaner(executor)) {
601  
602 <        joinPool(executor);
602 >            executor.execute(new CheckedRunnable() {
603 >                public void realRun() throws InterruptedException {
604 >                    threadsStarted.await();
605 >                    assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
606 >                }});
607 >
608 >            executor.execute(new CheckedRunnable() {
609 >                public void realRun() throws InterruptedException {
610 >                    threadsStarted.await();
611 >                    assertSame(one, q.take());
612 >                    checkEmpty(q);
613 >                }});
614 >        }
615      }
616  
617      /**
# Line 612 | Line 620 | public class LinkedTransferQueueTest ext
620      public void testPollInExecutor() {
621          final LinkedTransferQueue q = new LinkedTransferQueue();
622          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
623 <        ExecutorService executor = Executors.newFixedThreadPool(2);
624 <
617 <        executor.execute(new CheckedRunnable() {
618 <            public void realRun() throws InterruptedException {
619 <                assertNull(q.poll());
620 <                threadsStarted.await();
621 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
622 <                checkEmpty(q);
623 <            }});
623 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
624 >        try (PoolCleaner cleaner = cleaner(executor)) {
625  
626 <        executor.execute(new CheckedRunnable() {
627 <            public void realRun() throws InterruptedException {
628 <                threadsStarted.await();
629 <                q.put(one);
630 <            }});
631 <
632 <        joinPool(executor);
626 >            executor.execute(new CheckedRunnable() {
627 >                public void realRun() throws InterruptedException {
628 >                    assertNull(q.poll());
629 >                    threadsStarted.await();
630 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
631 >                    checkEmpty(q);
632 >                }});
633 >
634 >            executor.execute(new CheckedRunnable() {
635 >                public void realRun() throws InterruptedException {
636 >                    threadsStarted.await();
637 >                    q.put(one);
638 >                }});
639 >        }
640      }
641  
642      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines