--- jsr166/src/test/tck/LinkedBlockingQueueTest.java 2005/01/20 00:39:13 1.11 +++ jsr166/src/test/tck/LinkedBlockingQueueTest.java 2009/11/02 20:28:31 1.12 @@ -2,8 +2,8 @@ * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at * http://creativecommons.org/licenses/publicdomain - * Other contributors include Andrew Wright, Jeffrey Hayes, - * Pat Fisher, Mike Judd. + * Other contributors include Andrew Wright, Jeffrey Hayes, + * Pat Fisher, Mike Judd. */ import junit.framework.*; @@ -14,7 +14,7 @@ import java.io.*; public class LinkedBlockingQueueTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run (suite()); } public static Test suite() { @@ -36,7 +36,7 @@ public class LinkedBlockingQueueTest ext assertEquals(n, q.size()); return q; } - + /** * A new queue has the indicated capacity, or Integer.MAX_VALUE if * none given @@ -149,7 +149,7 @@ public class LinkedBlockingQueueTest ext LinkedBlockingQueue q = new LinkedBlockingQueue(1); q.offer(null); shouldThrow(); - } catch (NullPointerException success) { } + } catch (NullPointerException success) { } } /** @@ -160,7 +160,7 @@ public class LinkedBlockingQueueTest ext LinkedBlockingQueue q = new LinkedBlockingQueue(1); q.add(null); shouldThrow(); - } catch (NullPointerException success) { } + } catch (NullPointerException success) { } } /** @@ -184,7 +184,7 @@ public class LinkedBlockingQueueTest ext assertEquals(0, q.remainingCapacity()); q.add(new Integer(SIZE)); } catch (IllegalStateException success){ - } + } } /** @@ -278,9 +278,9 @@ public class LinkedBlockingQueueTest ext LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE); q.put(null); shouldThrow(); - } + } catch (NullPointerException success){ - } + } catch (InterruptedException ie) { unexpectedException(); } @@ -321,11 +321,11 @@ public class LinkedBlockingQueueTest ext threadShouldThrow(); } catch (InterruptedException ie){ threadAssertEquals(added, SIZE); - } + } }}); t.start(); - try { - Thread.sleep(SHORT_DELAY_MS); + try { + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -384,7 +384,7 @@ public class LinkedBlockingQueueTest ext } catch (InterruptedException success){} } }); - + try { t.start(); Thread.sleep(SMALL_DELAY_MS); @@ -406,7 +406,7 @@ public class LinkedBlockingQueueTest ext } } catch (InterruptedException e){ unexpectedException(); - } + } } /** @@ -419,7 +419,7 @@ public class LinkedBlockingQueueTest ext try { q.take(); threadShouldThrow(); - } catch (InterruptedException success){ } + } catch (InterruptedException success){ } } }); try { @@ -446,11 +446,11 @@ public class LinkedBlockingQueueTest ext q.take(); threadShouldThrow(); } catch (InterruptedException success){ - } + } }}); t.start(); - try { - Thread.sleep(SHORT_DELAY_MS); + try { + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -483,7 +483,7 @@ public class LinkedBlockingQueueTest ext assertNull(q.poll(0, TimeUnit.MILLISECONDS)); } catch (InterruptedException e){ unexpectedException(); - } + } } /** @@ -498,7 +498,7 @@ public class LinkedBlockingQueueTest ext assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException e){ unexpectedException(); - } + } } /** @@ -515,11 +515,11 @@ public class LinkedBlockingQueueTest ext } threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException success){ - } + } }}); t.start(); - try { - Thread.sleep(SHORT_DELAY_MS); + try { + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -541,7 +541,7 @@ public class LinkedBlockingQueueTest ext q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); threadShouldThrow(); - } catch (InterruptedException success) { } + } catch (InterruptedException success) { } } }); try { @@ -553,7 +553,7 @@ public class LinkedBlockingQueueTest ext } catch (Exception e){ unexpectedException(); } - } + } /** * peek returns next element, or null if empty @@ -597,7 +597,7 @@ public class LinkedBlockingQueueTest ext q.remove(); shouldThrow(); } catch (NoSuchElementException success){ - } + } } /** @@ -631,7 +631,7 @@ public class LinkedBlockingQueueTest ext unexpectedException(); } } - + /** * contains(x) reports true when elements added but not yet removed */ @@ -720,7 +720,7 @@ public class LinkedBlockingQueueTest ext assertEquals(o[i], q.take()); } catch (InterruptedException e){ unexpectedException(); - } + } } /** @@ -735,7 +735,7 @@ public class LinkedBlockingQueueTest ext assertEquals(ints[i], q.take()); } catch (InterruptedException e){ unexpectedException(); - } + } } /** @@ -760,7 +760,7 @@ public class LinkedBlockingQueueTest ext } catch(ArrayStoreException success){} } - + /** * iterator iterates through all elements */ @@ -773,7 +773,7 @@ public class LinkedBlockingQueueTest ext } } catch (InterruptedException e){ unexpectedException(); - } + } } /** @@ -788,7 +788,7 @@ public class LinkedBlockingQueueTest ext Iterator it = q.iterator(); it.next(); it.remove(); - + it = q.iterator(); assertEquals(it.next(), one); assertEquals(it.next(), three); @@ -843,7 +843,7 @@ public class LinkedBlockingQueueTest ext for (int i = 0; i < SIZE; ++i) { assertTrue(s.indexOf(String.valueOf(i)) >= 0); } - } + } /** @@ -878,7 +878,7 @@ public class LinkedBlockingQueueTest ext } } }); - + joinPool(executor); } @@ -912,7 +912,7 @@ public class LinkedBlockingQueueTest ext } } }); - + joinPool(executor); } @@ -932,7 +932,7 @@ public class LinkedBlockingQueueTest ext ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); LinkedBlockingQueue r = (LinkedBlockingQueue)in.readObject(); assertEquals(q.size(), r.size()); - while (!q.isEmpty()) + while (!q.isEmpty()) assertEquals(q.remove(), r.remove()); } catch(Exception e){ unexpectedException(); @@ -941,7 +941,7 @@ public class LinkedBlockingQueueTest ext /** * drainTo(null) throws NPE - */ + */ public void testDrainToNull() { LinkedBlockingQueue q = populatedQueue(SIZE); try { @@ -953,7 +953,7 @@ public class LinkedBlockingQueueTest ext /** * drainTo(this) throws IAE - */ + */ public void testDrainToSelf() { LinkedBlockingQueue q = populatedQueue(SIZE); try { @@ -965,14 +965,14 @@ public class LinkedBlockingQueueTest ext /** * drainTo(c) empties queue into another collection c - */ + */ public void testDrainTo() { LinkedBlockingQueue q = populatedQueue(SIZE); ArrayList l = new ArrayList(); q.drainTo(l); assertEquals(q.size(), 0); assertEquals(l.size(), SIZE); - for (int i = 0; i < SIZE; ++i) + for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i)); q.add(zero); q.add(one); @@ -983,20 +983,20 @@ public class LinkedBlockingQueueTest ext q.drainTo(l); assertEquals(q.size(), 0); assertEquals(l.size(), 2); - for (int i = 0; i < 2; ++i) + for (int i = 0; i < 2; ++i) assertEquals(l.get(i), new Integer(i)); } /** * drainTo empties full queue, unblocking a waiting put. - */ + */ public void testDrainToWithActivePut() { final LinkedBlockingQueue q = populatedQueue(SIZE); Thread t = new Thread(new Runnable() { public void run() { try { q.put(new Integer(SIZE+1)); - } catch (InterruptedException ie){ + } catch (InterruptedException ie){ threadUnexpectedException(); } } @@ -1006,7 +1006,7 @@ public class LinkedBlockingQueueTest ext ArrayList l = new ArrayList(); q.drainTo(l); assertTrue(l.size() >= SIZE); - for (int i = 0; i < SIZE; ++i) + for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i)); t.join(); assertTrue(q.size() + l.size() >= SIZE); @@ -1017,7 +1017,7 @@ public class LinkedBlockingQueueTest ext /** * drainTo(null, n) throws NPE - */ + */ public void testDrainToNullN() { LinkedBlockingQueue q = populatedQueue(SIZE); try { @@ -1029,7 +1029,7 @@ public class LinkedBlockingQueueTest ext /** * drainTo(this, n) throws IAE - */ + */ public void testDrainToSelfN() { LinkedBlockingQueue q = populatedQueue(SIZE); try { @@ -1041,7 +1041,7 @@ public class LinkedBlockingQueueTest ext /** * drainTo(c, n) empties first max {n, size} elements of queue into c - */ + */ public void testDrainToN() { LinkedBlockingQueue q = new LinkedBlockingQueue(); for (int i = 0; i < SIZE + 2; ++i) { @@ -1052,7 +1052,7 @@ public class LinkedBlockingQueueTest ext int k = (i < SIZE)? i : SIZE; assertEquals(l.size(), k); assertEquals(q.size(), SIZE-k); - for (int j = 0; j < k; ++j) + for (int j = 0; j < k; ++j) assertEquals(l.get(j), new Integer(j)); while (q.poll() != null) ; }