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

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

# Line 82 | Line 82 | public class LinkedBlockingDequeTest ext
82      public void testSize() {
83          LinkedBlockingDeque q = populatedDeque(SIZE);
84          for (int i = 0; i < SIZE; ++i) {
85 <            assertEquals(SIZE-i, q.size());
85 >            assertEquals(SIZE - i, q.size());
86              q.removeFirst();
87          }
88          for (int i = 0; i < SIZE; ++i) {
# Line 147 | Line 147 | public class LinkedBlockingDequeTest ext
147       */
148      public void testPollLast() {
149          LinkedBlockingDeque q = populatedDeque(SIZE);
150 <        for (int i = SIZE-1; i >= 0; --i) {
150 >        for (int i = SIZE - 1; i >= 0; --i) {
151              assertEquals(i, q.pollLast());
152          }
153          assertNull(q.pollLast());
# Line 186 | Line 186 | public class LinkedBlockingDequeTest ext
186       */
187      public void testPeekLast() {
188          LinkedBlockingDeque q = populatedDeque(SIZE);
189 <        for (int i = SIZE-1; i >= 0; --i) {
189 >        for (int i = SIZE - 1; i >= 0; --i) {
190              assertEquals(i, q.peekLast());
191              assertEquals(i, q.pollLast());
192              assertTrue(q.peekLast() == null ||
# Line 216 | Line 216 | public class LinkedBlockingDequeTest ext
216       */
217      public void testLastElement() {
218          LinkedBlockingDeque q = populatedDeque(SIZE);
219 <        for (int i = SIZE-1; i >= 0; --i) {
219 >        for (int i = SIZE - 1; i >= 0; --i) {
220              assertEquals(i, q.getLast());
221              assertEquals(i, q.pollLast());
222          }
# Line 281 | Line 281 | public class LinkedBlockingDequeTest ext
281          }
282          for (int i = 0; i < SIZE; i += 2) {
283              assertTrue(q.removeFirstOccurrence(new Integer(i)));
284 <            assertFalse(q.removeFirstOccurrence(new Integer(i+1)));
284 >            assertFalse(q.removeFirstOccurrence(new Integer(i + 1)));
285          }
286          assertTrue(q.isEmpty());
287      }
# Line 296 | Line 296 | public class LinkedBlockingDequeTest ext
296          }
297          for (int i = 0; i < SIZE; i += 2) {
298              assertTrue(q.removeLastOccurrence(new Integer(i)));
299 <            assertFalse(q.removeLastOccurrence(new Integer(i+1)));
299 >            assertFalse(q.removeLastOccurrence(new Integer(i + 1)));
300          }
301          assertTrue(q.isEmpty());
302      }
# Line 367 | Line 367 | public class LinkedBlockingDequeTest ext
367       */
368      public void testConstructor5() {
369          Integer[] ints = new Integer[SIZE];
370 <        for (int i = 0; i < SIZE-1; ++i)
370 >        for (int i = 0; i < SIZE - 1; ++i)
371              ints[i] = i;
372          Collection<Integer> elements = Arrays.asList(ints);
373          try {
# Line 414 | Line 414 | public class LinkedBlockingDequeTest ext
414              assertEquals(i, q.remove());
415          }
416          for (int i = 0; i < SIZE; ++i) {
417 <            assertEquals(SIZE-i, q.remainingCapacity());
417 >            assertEquals(SIZE - i, q.remainingCapacity());
418              assertEquals(SIZE, q.size() + q.remainingCapacity());
419              assertTrue(q.add(i));
420          }
# Line 513 | Line 513 | public class LinkedBlockingDequeTest ext
513      public void testAddAll3() {
514          LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
515          Integer[] ints = new Integer[SIZE];
516 <        for (int i = 0; i < SIZE-1; ++i)
516 >        for (int i = 0; i < SIZE - 1; ++i)
517              ints[i] = new Integer(i);
518          Collection<Integer> elements = Arrays.asList(ints);
519          try {
# Line 1246 | Line 1246 | public class LinkedBlockingDequeTest ext
1246      public void testTakeLast() throws InterruptedException {
1247          LinkedBlockingDeque q = populatedDeque(SIZE);
1248          for (int i = 0; i < SIZE; ++i) {
1249 <            assertEquals(SIZE-i-1, q.takeLast());
1249 >            assertEquals(SIZE - i - 1, q.takeLast());
1250          }
1251      }
1252  
# Line 1259 | Line 1259 | public class LinkedBlockingDequeTest ext
1259          Thread t = newStartedThread(new CheckedRunnable() {
1260              public void realRun() throws InterruptedException {
1261                  for (int i = 0; i < SIZE; ++i) {
1262 <                    assertEquals(SIZE-i-1, q.takeLast());
1262 >                    assertEquals(SIZE - i - 1, q.takeLast());
1263                  }
1264  
1265                  Thread.currentThread().interrupt();
# Line 1289 | Line 1289 | public class LinkedBlockingDequeTest ext
1289      public void testTimedPollLast0() throws InterruptedException {
1290          LinkedBlockingDeque q = populatedDeque(SIZE);
1291          for (int i = 0; i < SIZE; ++i) {
1292 <            assertEquals(SIZE-i-1, q.pollLast(0, MILLISECONDS));
1292 >            assertEquals(SIZE - i - 1, q.pollLast(0, MILLISECONDS));
1293          }
1294          assertNull(q.pollLast(0, MILLISECONDS));
1295      }
# Line 1301 | Line 1301 | public class LinkedBlockingDequeTest ext
1301          LinkedBlockingDeque q = populatedDeque(SIZE);
1302          for (int i = 0; i < SIZE; ++i) {
1303              long startTime = System.nanoTime();
1304 <            assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1304 >            assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1305              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1306          }
1307          long startTime = System.nanoTime();
# Line 1320 | Line 1320 | public class LinkedBlockingDequeTest ext
1320              public void realRun() throws InterruptedException {
1321                  LinkedBlockingDeque q = populatedDeque(SIZE);
1322                  for (int i = 0; i < SIZE; ++i) {
1323 <                    assertEquals(SIZE-i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1323 >                    assertEquals(SIZE - i - 1,
1324 >                                 q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1325                  }
1326  
1327                  Thread.currentThread().interrupt();
# Line 1458 | Line 1459 | public class LinkedBlockingDequeTest ext
1459                  assertTrue(changed);
1460  
1461              assertTrue(q.containsAll(p));
1462 <            assertEquals(SIZE-i, q.size());
1462 >            assertEquals(SIZE - i, q.size());
1463              p.remove();
1464          }
1465      }
# Line 1471 | Line 1472 | public class LinkedBlockingDequeTest ext
1472              LinkedBlockingDeque q = populatedDeque(SIZE);
1473              LinkedBlockingDeque p = populatedDeque(i);
1474              assertTrue(q.removeAll(p));
1475 <            assertEquals(SIZE-i, q.size());
1475 >            assertEquals(SIZE - i, q.size());
1476              for (int j = 0; j < i; ++j) {
1477                  Integer x = (Integer)(p.remove());
1478                  assertFalse(q.contains(x));
# Line 1670 | Line 1671 | public class LinkedBlockingDequeTest ext
1671          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1672          q.add(one);
1673          q.add(two);
1673        ExecutorService executor = Executors.newFixedThreadPool(2);
1674          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1675 <        executor.execute(new CheckedRunnable() {
1676 <            public void realRun() throws InterruptedException {
1677 <                assertFalse(q.offer(three));
1678 <                threadsStarted.await();
1679 <                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1680 <                assertEquals(0, q.remainingCapacity());
1681 <            }});
1682 <
1683 <        executor.execute(new CheckedRunnable() {
1684 <            public void realRun() throws InterruptedException {
1685 <                threadsStarted.await();
1686 <                assertSame(one, q.take());
1687 <            }});
1688 <
1689 <        joinPool(executor);
1675 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1676 >        try (PoolCleaner cleaner = cleaner(executor)) {
1677 >            executor.execute(new CheckedRunnable() {
1678 >                public void realRun() throws InterruptedException {
1679 >                    assertFalse(q.offer(three));
1680 >                    threadsStarted.await();
1681 >                    assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
1682 >                    assertEquals(0, q.remainingCapacity());
1683 >                }});
1684 >
1685 >            executor.execute(new CheckedRunnable() {
1686 >                public void realRun() throws InterruptedException {
1687 >                    threadsStarted.await();
1688 >                    assertSame(one, q.take());
1689 >                }});
1690 >        }
1691      }
1692  
1693      /**
# Line 1695 | Line 1696 | public class LinkedBlockingDequeTest ext
1696      public void testPollInExecutor() {
1697          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1698          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
1699 <        ExecutorService executor = Executors.newFixedThreadPool(2);
1700 <        executor.execute(new CheckedRunnable() {
1701 <            public void realRun() throws InterruptedException {
1702 <                assertNull(q.poll());
1703 <                threadsStarted.await();
1704 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1705 <                checkEmpty(q);
1706 <            }});
1707 <
1708 <        executor.execute(new CheckedRunnable() {
1709 <            public void realRun() throws InterruptedException {
1710 <                threadsStarted.await();
1711 <                q.put(one);
1712 <            }});
1713 <
1714 <        joinPool(executor);
1699 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
1700 >        try (PoolCleaner cleaner = cleaner(executor)) {
1701 >            executor.execute(new CheckedRunnable() {
1702 >                public void realRun() throws InterruptedException {
1703 >                    assertNull(q.poll());
1704 >                    threadsStarted.await();
1705 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
1706 >                    checkEmpty(q);
1707 >                }});
1708 >
1709 >            executor.execute(new CheckedRunnable() {
1710 >                public void realRun() throws InterruptedException {
1711 >                    threadsStarted.await();
1712 >                    q.put(one);
1713 >                }});
1714 >        }
1715      }
1716  
1717      /**
# Line 1762 | Line 1763 | public class LinkedBlockingDequeTest ext
1763          final LinkedBlockingDeque q = populatedDeque(SIZE);
1764          Thread t = new Thread(new CheckedRunnable() {
1765              public void realRun() throws InterruptedException {
1766 <                q.put(new Integer(SIZE+1));
1766 >                q.put(new Integer(SIZE + 1));
1767              }});
1768  
1769          t.start();
# Line 1787 | Line 1788 | public class LinkedBlockingDequeTest ext
1788              q.drainTo(l, i);
1789              int k = (i < SIZE) ? i : SIZE;
1790              assertEquals(k, l.size());
1791 <            assertEquals(SIZE-k, q.size());
1791 >            assertEquals(SIZE - k, q.size());
1792              for (int j = 0; j < k; ++j)
1793                  assertEquals(l.get(j), new Integer(j));
1794              do {} while (q.poll() != null);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines