diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-15 09:42:33 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-03-15 09:42:33 +0000 |
commit | a8a9d448e97004dcd25c9ccb128e09bcb7690f6a (patch) | |
tree | 214d4e0cdccf19471194d03dd3172933336910f1 /jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java | |
parent | 37f9fec54f50b2e0898ee2b61d058c4de879e38b (diff) | |
parent | ed4f365789d43b1961657195df223a19bf4ef20f (diff) |
Merge "Revert "JSR-166 update""
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java | 87 |
1 files changed, 41 insertions, 46 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java b/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java index 9d3f212588..605a95595b 100644 --- a/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java +++ b/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java @@ -25,7 +25,7 @@ import junit.framework.Test; public class SynchronousQueueTest extends JSR166TestCase { - // android-note: These tests have been moved into their own separate + // android-note: These tests have been moved into their own separate // classes to work around CTS issues. // // public static class Fair extends BlockingQueueTest { @@ -33,19 +33,17 @@ public class SynchronousQueueTest extends JSR166TestCase { // return new SynchronousQueue(true); // } // } - + // // public static class NonFair extends BlockingQueueTest { // protected BlockingQueue emptyCollection() { // return new SynchronousQueue(false); // } // } - - // android-note: Removed because the CTS runner does a bad job of - // retrying tests that have suite() declarations. // // public static void main(String[] args) { // main(suite(), args); // } + // // public static Test suite() { // return newTestSuite(SynchronousQueueTest.class, // new Fair().testSuite(), @@ -264,6 +262,7 @@ public class SynchronousQueueTest extends JSR166TestCase { pleaseOffer.countDown(); startTime = System.nanoTime(); assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS); Thread.currentThread().interrupt(); try { @@ -278,15 +277,13 @@ public class SynchronousQueueTest extends JSR166TestCase { shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); - - assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); await(pleaseOffer); long startTime = System.nanoTime(); try { assertTrue(q.offer(zero, LONG_DELAY_MS, MILLISECONDS)); } catch (InterruptedException e) { threadUnexpectedException(e); } - assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS); await(pleaseInterrupt); assertThreadStaysAlive(t); @@ -477,24 +474,24 @@ public class SynchronousQueueTest extends JSR166TestCase { public void testOfferInExecutor_fair() { testOfferInExecutor(true); } public void testOfferInExecutor(boolean fair) { final SynchronousQueue q = new SynchronousQueue(fair); + ExecutorService executor = Executors.newFixedThreadPool(2); final CheckedBarrier threadsStarted = new CheckedBarrier(2); - final ExecutorService executor = Executors.newFixedThreadPool(2); - try (PoolCleaner cleaner = cleaner(executor)) { - - executor.execute(new CheckedRunnable() { - public void realRun() throws InterruptedException { - assertFalse(q.offer(one)); - threadsStarted.await(); - assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS)); - assertEquals(0, q.remainingCapacity()); - }}); - - executor.execute(new CheckedRunnable() { - public void realRun() throws InterruptedException { - threadsStarted.await(); - assertSame(one, q.take()); - }}); - } + + executor.execute(new CheckedRunnable() { + public void realRun() throws InterruptedException { + assertFalse(q.offer(one)); + threadsStarted.await(); + assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS)); + assertEquals(0, q.remainingCapacity()); + }}); + + executor.execute(new CheckedRunnable() { + public void realRun() throws InterruptedException { + threadsStarted.await(); + assertSame(one, q.take()); + }}); + + joinPool(executor); } /** @@ -505,22 +502,22 @@ public class SynchronousQueueTest extends JSR166TestCase { public void testPollInExecutor(boolean fair) { final SynchronousQueue q = new SynchronousQueue(fair); final CheckedBarrier threadsStarted = new CheckedBarrier(2); - final ExecutorService executor = Executors.newFixedThreadPool(2); - try (PoolCleaner cleaner = cleaner(executor)) { - executor.execute(new CheckedRunnable() { - public void realRun() throws InterruptedException { - assertNull(q.poll()); - threadsStarted.await(); - assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); - assertTrue(q.isEmpty()); - }}); - - executor.execute(new CheckedRunnable() { - public void realRun() throws InterruptedException { - threadsStarted.await(); - q.put(one); - }}); - } + ExecutorService executor = Executors.newFixedThreadPool(2); + executor.execute(new CheckedRunnable() { + public void realRun() throws InterruptedException { + assertNull(q.poll()); + threadsStarted.await(); + assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(q.isEmpty()); + }}); + + executor.execute(new CheckedRunnable() { + public void realRun() throws InterruptedException { + threadsStarted.await(); + q.put(one); + }}); + + joinPool(executor); } /** @@ -598,12 +595,10 @@ public class SynchronousQueueTest extends JSR166TestCase { }}); ArrayList l = new ArrayList(); - int drained; - while ((drained = q.drainTo(l, 1)) == 0) Thread.yield(); - assertEquals(1, drained); + delay(SHORT_DELAY_MS); + q.drainTo(l, 1); assertEquals(1, l.size()); - while ((drained = q.drainTo(l, 1)) == 0) Thread.yield(); - assertEquals(1, drained); + q.drainTo(l, 1); assertEquals(2, l.size()); assertTrue(l.contains(one)); assertTrue(l.contains(two)); |