--- jsr166/src/test/tck/ArrayBlockingQueueTest.java 2009/11/22 00:17:37 1.25 +++ jsr166/src/test/tck/ArrayBlockingQueueTest.java 2009/12/01 06:03:49 1.27 @@ -319,30 +319,26 @@ public class ArrayBlockingQueueTest exte * put blocks waiting for take when full */ public void testPutWithTake() throws InterruptedException { - final ArrayBlockingQueue q = new ArrayBlockingQueue(2); + final int capacity = 2; + final ArrayBlockingQueue q = new ArrayBlockingQueue(capacity); Thread t = new Thread(new CheckedRunnable() { - public void realRun() { - int added = 0; + public void realRun() throws InterruptedException { + for (int i = 0; i < capacity + 1; i++) + q.put(i); try { - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - threadShouldThrow(); - } catch (InterruptedException success) { - threadAssertTrue(added >= 2); - } + q.put(99); + shouldThrow(); + } catch (InterruptedException success) {} }}); t.start(); Thread.sleep(SHORT_DELAY_MS); - q.take(); + assertEquals(q.remainingCapacity(), 0); + assertEquals(0, q.take()); + Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); + assertEquals(q.remainingCapacity(), 0); } /** @@ -502,10 +498,10 @@ public class ArrayBlockingQueueTest exte public void testPeek() { ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.peek()).intValue()); - q.poll(); + assertEquals(i, q.peek()); + assertEquals(i, q.poll()); assertTrue(q.peek() == null || - i != ((Integer)q.peek()).intValue()); + !q.peek().equals(i)); } assertNull(q.peek()); } @@ -516,8 +512,8 @@ public class ArrayBlockingQueueTest exte public void testElement() { ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.element()).intValue()); - q.poll(); + assertEquals(i, q.element()); + assertEquals(i, q.poll()); } try { q.element(); @@ -531,7 +527,7 @@ public class ArrayBlockingQueueTest exte public void testRemove() { ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, ((Integer)q.remove()).intValue()); + assertEquals(i, q.remove()); } try { q.remove(); @@ -561,7 +557,7 @@ public class ArrayBlockingQueueTest exte ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertTrue(q.contains(new Integer(i))); - q.poll(); + assertEquals(i, q.poll()); assertFalse(q.contains(new Integer(i))); } } @@ -656,8 +652,8 @@ public class ArrayBlockingQueueTest exte * toArray(null) throws NPE */ public void testToArray_BadArg() { + ArrayBlockingQueue q = populatedQueue(SIZE); try { - ArrayBlockingQueue q = populatedQueue(SIZE); Object o[] = q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} @@ -667,9 +663,9 @@ public class ArrayBlockingQueueTest exte * toArray with incompatible array type throws CCE */ public void testToArray1_BadArg() { + ArrayBlockingQueue q = populatedQueue(SIZE); try { - ArrayBlockingQueue q = populatedQueue(SIZE); - Object o[] = q.toArray(new String[10] ); + Object o[] = q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} } @@ -718,8 +714,7 @@ public class ArrayBlockingQueueTest exte int k = 0; for (Iterator it = q.iterator(); it.hasNext();) { - int i = ((Integer)(it.next())).intValue(); - assertEquals(++k, i); + assertEquals(++k, it.next()); } assertEquals(3, k); } @@ -762,15 +757,15 @@ public class ArrayBlockingQueueTest exte ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(q.offer(three)); - threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); - threadAssertEquals(0, q.remainingCapacity()); + assertFalse(q.offer(three)); + assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); + assertEquals(0, q.remainingCapacity()); }}); executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); - threadAssertEquals(one, q.take()); + assertSame(one, q.take()); }}); joinPool(executor); @@ -785,9 +780,9 @@ public class ArrayBlockingQueueTest exte ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertNull(q.poll()); - threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); - threadAssertTrue(q.isEmpty()); + assertNull(q.poll()); + assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(q.isEmpty()); }}); executor.execute(new CheckedRunnable() {