--- jsr166/src/test/tck/LinkedTransferQueueTest.java 2009/11/21 19:45:16 1.17 +++ jsr166/src/test/tck/LinkedTransferQueueTest.java 2009/11/26 15:42:15 1.21 @@ -271,7 +271,7 @@ public class LinkedTransferQueueTest ext public void testTakeFromEmpty() throws InterruptedException { final LinkedTransferQueue q = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedInterruptedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { q.take(); }}); Thread.sleep(SHORT_DELAY_MS); @@ -284,14 +284,19 @@ public class LinkedTransferQueueTest ext */ public void testBlockingTake() throws InterruptedException { final LinkedTransferQueue q = populatedQueue(SIZE); - Thread t = newStartedThread(new CheckedInterruptedRunnable() { - void realRun() throws InterruptedException { + Thread t = new Thread(new CheckedRunnable() { + public void realRun() throws InterruptedException { for (int i = 0; i < SIZE; ++i) { - threadAssertEquals(i, (int) q.take()); + assertEquals(i, (int) q.take()); } - q.take(); + try { + q.take(); + shouldThrow(); + } catch (InterruptedException success) {} }}); - Thread.sleep(SMALL_DELAY_MS); + + t.start(); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); checkEmpty(q); @@ -343,7 +348,7 @@ public class LinkedTransferQueueTest ext public void testInterruptedTimedPoll() throws InterruptedException { final LinkedTransferQueue q = populatedQueue(SIZE); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { for (int i = 0; i < SIZE; ++i) { long t0 = System.nanoTime(); threadAssertEquals(i, (int) q.poll(LONG_DELAY_MS, @@ -369,12 +374,17 @@ public class LinkedTransferQueueTest ext */ public void testTimedPollWithOffer() throws InterruptedException { final LinkedTransferQueue q = new LinkedTransferQueue(); - Thread t = newStartedThread(new CheckedInterruptedRunnable() { - void realRun() throws InterruptedException { - threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - q.poll(LONG_DELAY_MS, MILLISECONDS); - q.poll(LONG_DELAY_MS, MILLISECONDS); + Thread t = new Thread(new CheckedRunnable() { + public void realRun() throws InterruptedException { + assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); + try { + q.poll(LONG_DELAY_MS, MILLISECONDS); + shouldThrow(); + } catch (InterruptedException success) {} }}); + + t.start(); Thread.sleep(SMALL_DELAY_MS); assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); t.interrupt(); @@ -560,8 +570,8 @@ public class LinkedTransferQueueTest ext * toArray(null) throws NullPointerException */ public void testToArray_BadArg() { + LinkedTransferQueue q = populatedQueue(SIZE); try { - LinkedTransferQueue q = populatedQueue(SIZE); Object o[] = q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} @@ -571,8 +581,8 @@ public class LinkedTransferQueueTest ext * toArray(incompatible array type) throws CCE */ public void testToArray1_BadArg() { + LinkedTransferQueue q = populatedQueue(SIZE); try { - LinkedTransferQueue q = populatedQueue(SIZE); Object o[] = q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} @@ -664,13 +674,13 @@ public class LinkedTransferQueueTest ext ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(new CheckedRunnable() { - void realRun() { + public void realRun() { threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); }}); executor.execute(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); threadAssertEquals(one, q.take()); }}); @@ -686,7 +696,7 @@ public class LinkedTransferQueueTest ext ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { threadAssertNull(q.poll()); threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); @@ -694,7 +704,7 @@ public class LinkedTransferQueueTest ext }}); executor.execute(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); q.put(one); }}); @@ -780,7 +790,7 @@ public class LinkedTransferQueueTest ext public void testDrainToWithActivePut() throws InterruptedException { final LinkedTransferQueue q = populatedQueue(SIZE); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() { + public void realRun() { q.put(SIZE + 1); }}); ArrayList l = new ArrayList(); @@ -847,7 +857,7 @@ public class LinkedTransferQueueTest ext assertFalse(q.hasWaitingConsumer()); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); threadAssertTrue(q.hasWaitingConsumer()); threadAssertEquals(q.getWaitingConsumerCount(), 1); @@ -882,7 +892,7 @@ public class LinkedTransferQueueTest ext = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { q.transfer(SIZE); threadAssertTrue(q.isEmpty()); }}); @@ -902,7 +912,7 @@ public class LinkedTransferQueueTest ext = new LinkedTransferQueue(); Thread first = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { Integer i = SIZE + 1; q.transfer(i); threadAssertTrue(!q.contains(i)); @@ -911,7 +921,7 @@ public class LinkedTransferQueueTest ext Thread interruptedThread = newStartedThread( new CheckedInterruptedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { while (q.size() == 0) Thread.yield(); q.transfer(SIZE); @@ -937,7 +947,7 @@ public class LinkedTransferQueueTest ext final LinkedTransferQueue q = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { q.transfer(four); threadAssertFalse(q.contains(four)); threadAssertEquals(three, q.poll()); @@ -958,7 +968,7 @@ public class LinkedTransferQueueTest ext = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { q.transfer(SIZE); checkEmpty(q); }}); @@ -1000,7 +1010,7 @@ public class LinkedTransferQueueTest ext final LinkedTransferQueue q = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() { + public void realRun() { while (! q.hasWaitingConsumer()) Thread.yield(); threadAssertTrue(q.hasWaitingConsumer()); @@ -1023,7 +1033,7 @@ public class LinkedTransferQueueTest ext final LinkedTransferQueue q = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() { + public void realRun() { while (! q.hasWaitingConsumer()) Thread.yield(); threadAssertTrue(q.hasWaitingConsumer()); @@ -1045,7 +1055,7 @@ public class LinkedTransferQueueTest ext final LinkedTransferQueue q = new LinkedTransferQueue(); Thread toInterrupt = newStartedThread(new CheckedInterruptedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { q.tryTransfer(new Object(), LONG_DELAY_MS, MILLISECONDS); }}); @@ -1061,7 +1071,7 @@ public class LinkedTransferQueueTest ext final LinkedTransferQueue q = new LinkedTransferQueue(); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { threadAssertFalse (q.tryTransfer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); @@ -1081,7 +1091,7 @@ public class LinkedTransferQueueTest ext assertTrue(q.offer(four)); Thread t = newStartedThread(new CheckedRunnable() { - void realRun() throws InterruptedException { + public void realRun() throws InterruptedException { threadAssertTrue(q.tryTransfer(five, MEDIUM_DELAY_MS, MILLISECONDS)); threadAssertTrue(q.isEmpty());