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.59 by jsr166, Sat Apr 25 04:55:31 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 132 | Line 140 | public class LinkedTransferQueueTest ext
140       * addAll(this) throws IllegalArgumentException
141       */
142      public void testAddAllSelf() {
143 +        LinkedTransferQueue q = populatedQueue(SIZE);
144          try {
136            LinkedTransferQueue q = populatedQueue(SIZE);
145              q.addAll(q);
146              shouldThrow();
147          } catch (IllegalArgumentException success) {}
# Line 144 | Line 152 | public class LinkedTransferQueueTest ext
152       * NullPointerException after possibly adding some elements
153       */
154      public void testAddAll3() {
155 +        LinkedTransferQueue q = new LinkedTransferQueue();
156 +        Integer[] ints = new Integer[SIZE];
157 +        for (int i = 0; i < SIZE - 1; ++i)
158 +            ints[i] = i;
159          try {
148            LinkedTransferQueue q = new LinkedTransferQueue();
149            Integer[] ints = new Integer[SIZE];
150            for (int i = 0; i < SIZE - 1; ++i) {
151                ints[i] = i;
152            }
160              q.addAll(Arrays.asList(ints));
161              shouldThrow();
162          } catch (NullPointerException success) {}
# Line 589 | 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);
599 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
600 >        try (PoolCleaner cleaner = cleaner(executor)) {
601  
602 <        executor.execute(new CheckedRunnable() {
603 <            public void realRun() throws InterruptedException {
604 <                threadsStarted.await();
605 <                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
606 <            }});
599 <
600 <        executor.execute(new CheckedRunnable() {
601 <            public void realRun() throws InterruptedException {
602 <                threadsStarted.await();
603 <                assertSame(one, q.take());
604 <                checkEmpty(q);
605 <            }});
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 <        joinPool(executor);
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 613 | 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 <
618 <        executor.execute(new CheckedRunnable() {
619 <            public void realRun() throws InterruptedException {
620 <                assertNull(q.poll());
621 <                threadsStarted.await();
622 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
623 <                checkEmpty(q);
624 <            }});
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 <            }});
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 <        joinPool(executor);
634 >            executor.execute(new CheckedRunnable() {
635 >                public void realRun() throws InterruptedException {
636 >                    threadsStarted.await();
637 >                    q.put(one);
638 >                }});
639 >        }
640      }
641  
642      /**
# Line 862 | Line 869 | public class LinkedTransferQueueTest ext
869       * tryTransfer(null) throws NullPointerException
870       */
871      public void testTryTransfer1() {
872 +        final LinkedTransferQueue q = new LinkedTransferQueue();
873          try {
866            final LinkedTransferQueue q = new LinkedTransferQueue();
874              q.tryTransfer(null);
875              shouldThrow();
876          } catch (NullPointerException success) {}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines