diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-11 15:59:10 +0000 |
---|---|---|
committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-15 10:42:51 +0000 |
commit | b8b75116273ecfdb8ffdd1869b1c0dd04570a95e (patch) | |
tree | 1622f7420704b7ca6520ba3db150bbc6ab918503 /jsr166-tests/src/test/java/jsr166/LinkedBlockingQueueTest.java | |
parent | a8a9d448e97004dcd25c9ccb128e09bcb7690f6a (diff) |
JSR-166 update without java 1.9 method/classes
Second attempt, in frist one I've submitted some code from openJdk 1.9
that shouldn't be here, orignial change can be found at
5328e07d282bef36ac8b757bbee16a761415b2c4
Adapted from sources taken from CVS using:
cvs -d ':pserver:anonymous@gee.cs.oswego.edu/home/jsr166/jsr166' checkout -D "03/03/2016 10:00:00 GMT" jsr166
This time with hidden/removed "@since 9" methods and classes
Bug: 27426599
Change-Id: Ibd8d26e13cba091bfd983c73d005e4f8d8f5946d
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/LinkedBlockingQueueTest.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/LinkedBlockingQueueTest.java | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/LinkedBlockingQueueTest.java b/jsr166-tests/src/test/java/jsr166/LinkedBlockingQueueTest.java index bd37b2a4e5..faf3f18e90 100644 --- a/jsr166-tests/src/test/java/jsr166/LinkedBlockingQueueTest.java +++ b/jsr166-tests/src/test/java/jsr166/LinkedBlockingQueueTest.java @@ -26,25 +26,27 @@ import junit.framework.Test; public class LinkedBlockingQueueTest 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 Unbounded extends BlockingQueueTest { - // protected BlockingQueue emptyCollection() { - // return new LinkedBlockingQueue(); + // protected BlockingQueue emptyCollection() { + // return new LinkedBlockingQueue(); // } // } - // + // public static class Bounded extends BlockingQueueTest { - // protected BlockingQueue emptyCollection() { + // protected BlockingQueue emptyCollection() { // return new LinkedBlockingQueue(SIZE); // } // } + + // 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); + // main(suite(), args); // } - // // public static Test suite() { // return newTestSuite(LinkedBlockingQueueTest.class, // new Unbounded().testSuite(), @@ -113,7 +115,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { */ public void testConstructor5() { Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) + for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); Collection<Integer> elements = Arrays.asList(ints); try { @@ -160,7 +162,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { assertEquals(i, q.remove()); } for (int i = 0; i < SIZE; ++i) { - assertEquals(SIZE-i, q.remainingCapacity()); + assertEquals(SIZE - i, q.remainingCapacity()); assertEquals(SIZE, q.size() + q.remainingCapacity()); assertTrue(q.add(i)); } @@ -207,7 +209,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { public void testAddAll3() { LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); Integer[] ints = new Integer[SIZE]; - for (int i = 0; i < SIZE-1; ++i) + for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); Collection<Integer> elements = Arrays.asList(ints); try { @@ -445,25 +447,23 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { final CountDownLatch aboutToWait = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { + long startTime = System.nanoTime(); for (int i = 0; i < SIZE; ++i) { - long t0 = System.nanoTime(); assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); } - long t0 = System.nanoTime(); aboutToWait.countDown(); try { - q.poll(MEDIUM_DELAY_MS, MILLISECONDS); + q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) { - assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } }}); - aboutToWait.await(); - waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); + await(aboutToWait); + waitForThreadToEnterWaitState(t, LONG_DELAY_MS); t.interrupt(); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); checkEmpty(q); } @@ -579,7 +579,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { assertTrue(changed); assertTrue(q.containsAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); p.remove(); } } @@ -592,7 +592,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { LinkedBlockingQueue q = populatedQueue(SIZE); LinkedBlockingQueue p = populatedQueue(i); assertTrue(q.removeAll(p)); - assertEquals(SIZE-i, q.size()); + assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.remove()); assertFalse(q.contains(x)); @@ -727,23 +727,23 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { final LinkedBlockingQueue q = new LinkedBlockingQueue(2); q.add(one); q.add(two); - ExecutorService executor = Executors.newFixedThreadPool(2); final CheckedBarrier threadsStarted = new CheckedBarrier(2); - executor.execute(new CheckedRunnable() { - public void realRun() throws InterruptedException { - assertFalse(q.offer(three)); - threadsStarted.await(); - assertTrue(q.offer(three, 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); + final ExecutorService executor = Executors.newFixedThreadPool(2); + try (PoolCleaner cleaner = cleaner(executor)) { + executor.execute(new CheckedRunnable() { + public void realRun() throws InterruptedException { + assertFalse(q.offer(three)); + threadsStarted.await(); + assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS)); + assertEquals(0, q.remainingCapacity()); + }}); + + executor.execute(new CheckedRunnable() { + public void realRun() throws InterruptedException { + threadsStarted.await(); + assertSame(one, q.take()); + }}); + } } /** @@ -752,22 +752,22 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { public void testPollInExecutor() { final LinkedBlockingQueue q = new LinkedBlockingQueue(2); final CheckedBarrier threadsStarted = new CheckedBarrier(2); - 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)); - checkEmpty(q); - }}); - - executor.execute(new CheckedRunnable() { - public void realRun() throws InterruptedException { - threadsStarted.await(); - q.put(one); - }}); - - joinPool(executor); + 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)); + checkEmpty(q); + }}); + + executor.execute(new CheckedRunnable() { + public void realRun() throws InterruptedException { + threadsStarted.await(); + q.put(one); + }}); + } } /** @@ -819,7 +819,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { final LinkedBlockingQueue q = populatedQueue(SIZE); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - q.put(new Integer(SIZE+1)); + q.put(new Integer(SIZE + 1)); }}); t.start(); @@ -844,7 +844,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase { q.drainTo(l, i); int k = (i < SIZE) ? i : SIZE; assertEquals(k, l.size()); - assertEquals(SIZE-k, q.size()); + assertEquals(SIZE - k, q.size()); for (int j = 0; j < k; ++j) assertEquals(l.get(j), new Integer(j)); do {} while (q.poll() != null); |