--- jsr166/src/test/tck/LinkedTransferQueueTest.java 2015/10/06 00:36:55 1.65 +++ jsr166/src/test/tck/LinkedTransferQueueTest.java 2016/10/16 20:16:36 1.67 @@ -24,14 +24,6 @@ import junit.framework.Test; @SuppressWarnings({"unchecked", "rawtypes"}) public class LinkedTransferQueueTest extends JSR166TestCase { - static class Implementation implements CollectionImplementation { - public Class klazz() { return LinkedTransferQueue.class; } - public Collection emptyCollection() { return new LinkedTransferQueue(); } - public Object makeElement(int i) { return i; } - public boolean isConcurrent() { return true; } - public boolean permitsNulls() { return false; } - } - public static class Generic extends BlockingQueueTest { protected BlockingQueue emptyCollection() { return new LinkedTransferQueue(); @@ -43,6 +35,13 @@ public class LinkedTransferQueueTest ext } public static Test suite() { + class Implementation implements CollectionImplementation { + public Class klazz() { return LinkedTransferQueue.class; } + public Collection emptyCollection() { return new LinkedTransferQueue(); } + public Object makeElement(int i) { return i; } + public boolean isConcurrent() { return true; } + public boolean permitsNulls() { return false; } + } return newTestSuite(LinkedTransferQueueTest.class, new Generic().testSuite(), CollectionTest.testSuite(new Implementation())); @@ -263,12 +262,12 @@ public class LinkedTransferQueueTest ext */ public void testTimedPoll() throws InterruptedException { LinkedTransferQueue q = populatedQueue(SIZE); - for (int i = 0; i < SIZE; ++i) { - long startTime = System.nanoTime(); - assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); - } long startTime = System.nanoTime(); + for (int i = 0; i < SIZE; ++i) + assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); + + startTime = System.nanoTime(); assertNull(q.poll(timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); checkEmpty(q); @@ -284,20 +283,18 @@ public class LinkedTransferQueueTest ext Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { long startTime = System.nanoTime(); - for (int i = 0; i < SIZE; ++i) { + for (int i = 0; i < SIZE; ++i) assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - } aboutToWait.countDown(); try { q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); - } catch (InterruptedException success) { - assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); - } + } catch (InterruptedException success) {} + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); aboutToWait.await(); - waitForThreadToEnterWaitState(t, LONG_DELAY_MS); + waitForThreadToEnterWaitState(t); t.interrupt(); awaitTermination(t); checkEmpty(q); @@ -311,19 +308,18 @@ public class LinkedTransferQueueTest ext final BlockingQueue q = populatedQueue(SIZE); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { + long startTime = System.nanoTime(); Thread.currentThread().interrupt(); - for (int i = 0; i < SIZE; ++i) { - long startTime = System.nanoTime(); + for (int i = 0; i < SIZE; ++i) assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); - } try { - q.poll(MEDIUM_DELAY_MS, MILLISECONDS); + q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); checkEmpty(q); } @@ -600,7 +596,9 @@ public class LinkedTransferQueueTest ext executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadsStarted.await(); + long startTime = System.nanoTime(); assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); executor.execute(new CheckedRunnable() { @@ -625,7 +623,9 @@ public class LinkedTransferQueueTest ext public void realRun() throws InterruptedException { assertNull(q.poll()); threadsStarted.await(); + long startTime = System.nanoTime(); assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); checkEmpty(q); }}); @@ -695,7 +695,7 @@ public class LinkedTransferQueueTest ext assertTrue(l.size() >= SIZE); for (int i = 0; i < SIZE; ++i) assertEquals(i, l.get(i)); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); assertTrue(q.size() + l.size() >= SIZE); } @@ -732,13 +732,15 @@ public class LinkedTransferQueueTest ext Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); + long startTime = System.nanoTime(); assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); assertEquals(0, q.getWaitingConsumerCount()); assertFalse(q.hasWaitingConsumer()); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); threadStarted.await(); - waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); + waitForThreadToEnterWaitState(t); assertEquals(1, q.getWaitingConsumerCount()); assertTrue(q.hasWaitingConsumer()); @@ -746,7 +748,7 @@ public class LinkedTransferQueueTest ext assertEquals(0, q.getWaitingConsumerCount()); assertFalse(q.hasWaitingConsumer()); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /** @@ -777,11 +779,11 @@ public class LinkedTransferQueueTest ext }}); threadStarted.await(); - waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); + waitForThreadToEnterWaitState(t); assertEquals(1, q.size()); assertSame(five, q.poll()); checkEmpty(q); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /** @@ -837,7 +839,7 @@ public class LinkedTransferQueueTest ext assertEquals(1, q.size()); assertTrue(q.offer(three)); assertSame(four, q.poll()); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /** @@ -860,7 +862,7 @@ public class LinkedTransferQueueTest ext assertEquals(1, q.size()); assertSame(four, q.take()); checkEmpty(q); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /** @@ -902,9 +904,11 @@ public class LinkedTransferQueueTest ext assertTrue(q.tryTransfer(hotPotato)); }}); - assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); + long startTime = System.nanoTime(); + assertSame(hotPotato, q.poll(LONG_DELAY_MS, MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); checkEmpty(q); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /** @@ -926,7 +930,7 @@ public class LinkedTransferQueueTest ext assertSame(q.take(), hotPotato); checkEmpty(q); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /** @@ -939,6 +943,7 @@ public class LinkedTransferQueueTest ext Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { + long startTime = System.nanoTime(); Thread.currentThread().interrupt(); try { q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); @@ -952,6 +957,7 @@ public class LinkedTransferQueueTest ext shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); }}); await(pleaseInterrupt); @@ -990,7 +996,9 @@ public class LinkedTransferQueueTest ext Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - assertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS)); + long startTime = System.nanoTime(); + assertTrue(q.tryTransfer(five, LONG_DELAY_MS, MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); checkEmpty(q); }}); @@ -1000,7 +1008,7 @@ public class LinkedTransferQueueTest ext assertSame(four, q.poll()); assertSame(five, q.poll()); checkEmpty(q); - awaitTermination(t, MEDIUM_DELAY_MS); + awaitTermination(t); } /**