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

Comparing jsr166/src/test/tck/SynchronousQueueTest.java (file contents):
Revision 1.47 by jsr166, Sat Apr 25 04:55:31 2015 UTC vs.
Revision 1.50 by jsr166, Thu Oct 8 00:26:16 2015 UTC

# Line 257 | Line 257 | public class SynchronousQueueTest extend
257                  pleaseOffer.countDown();
258                  startTime = System.nanoTime();
259                  assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
260                assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
260  
261                  Thread.currentThread().interrupt();
262                  try {
# Line 272 | Line 271 | public class SynchronousQueueTest extend
271                      shouldThrow();
272                  } catch (InterruptedException success) {}
273                  assertFalse(Thread.interrupted());
274 +
275 +                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
276              }});
277  
278          await(pleaseOffer);
279          long startTime = System.nanoTime();
280          try { assertTrue(q.offer(zero, LONG_DELAY_MS, MILLISECONDS)); }
281          catch (InterruptedException e) { threadUnexpectedException(e); }
282 <        assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
282 >        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
283  
284          await(pleaseInterrupt);
285          assertThreadStaysAlive(t);
# Line 469 | Line 470 | public class SynchronousQueueTest extend
470      public void testOfferInExecutor_fair() { testOfferInExecutor(true); }
471      public void testOfferInExecutor(boolean fair) {
472          final SynchronousQueue q = new SynchronousQueue(fair);
472        ExecutorService executor = Executors.newFixedThreadPool(2);
473          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
474 +        final ExecutorService executor = Executors.newFixedThreadPool(2);
475 +        try (PoolCleaner cleaner = cleaner(executor)) {
476  
477 <        executor.execute(new CheckedRunnable() {
478 <            public void realRun() throws InterruptedException {
479 <                assertFalse(q.offer(one));
480 <                threadsStarted.await();
481 <                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
482 <                assertEquals(0, q.remainingCapacity());
483 <            }});
484 <
485 <        executor.execute(new CheckedRunnable() {
486 <            public void realRun() throws InterruptedException {
487 <                threadsStarted.await();
488 <                assertSame(one, q.take());
489 <            }});
490 <
489 <        joinPool(executor);
477 >            executor.execute(new CheckedRunnable() {
478 >                public void realRun() throws InterruptedException {
479 >                    assertFalse(q.offer(one));
480 >                    threadsStarted.await();
481 >                    assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
482 >                    assertEquals(0, q.remainingCapacity());
483 >                }});
484 >
485 >            executor.execute(new CheckedRunnable() {
486 >                public void realRun() throws InterruptedException {
487 >                    threadsStarted.await();
488 >                    assertSame(one, q.take());
489 >                }});
490 >        }
491      }
492  
493      /**
# Line 497 | Line 498 | public class SynchronousQueueTest extend
498      public void testPollInExecutor(boolean fair) {
499          final SynchronousQueue q = new SynchronousQueue(fair);
500          final CheckedBarrier threadsStarted = new CheckedBarrier(2);
501 <        ExecutorService executor = Executors.newFixedThreadPool(2);
502 <        executor.execute(new CheckedRunnable() {
503 <            public void realRun() throws InterruptedException {
504 <                assertNull(q.poll());
505 <                threadsStarted.await();
506 <                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
507 <                assertTrue(q.isEmpty());
508 <            }});
509 <
510 <        executor.execute(new CheckedRunnable() {
511 <            public void realRun() throws InterruptedException {
512 <                threadsStarted.await();
513 <                q.put(one);
514 <            }});
515 <
516 <        joinPool(executor);
501 >        final ExecutorService executor = Executors.newFixedThreadPool(2);
502 >        try (PoolCleaner cleaner = cleaner(executor)) {
503 >            executor.execute(new CheckedRunnable() {
504 >                public void realRun() throws InterruptedException {
505 >                    assertNull(q.poll());
506 >                    threadsStarted.await();
507 >                    assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
508 >                    assertTrue(q.isEmpty());
509 >                }});
510 >
511 >            executor.execute(new CheckedRunnable() {
512 >                public void realRun() throws InterruptedException {
513 >                    threadsStarted.await();
514 >                    q.put(one);
515 >                }});
516 >        }
517      }
518  
519      /**
# Line 590 | Line 591 | public class SynchronousQueueTest extend
591              }});
592  
593          ArrayList l = new ArrayList();
594 <        delay(SHORT_DELAY_MS);
595 <        q.drainTo(l, 1);
594 >        int drained;
595 >        while ((drained = q.drainTo(l, 1)) == 0) Thread.yield();
596 >        assertEquals(1, drained);
597          assertEquals(1, l.size());
598 <        q.drainTo(l, 1);
598 >        while ((drained = q.drainTo(l, 1)) == 0) Thread.yield();
599 >        assertEquals(1, drained);
600          assertEquals(2, l.size());
601          assertTrue(l.contains(one));
602          assertTrue(l.contains(two));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines