--- jsr166/src/test/tck/LinkedBlockingDequeTest.java 2017/05/14 01:30:34 1.78 +++ jsr166/src/test/tck/LinkedBlockingDequeTest.java 2018/05/28 21:19:50 1.83 @@ -442,7 +442,7 @@ public class LinkedBlockingDequeTest ext } /** - * push succeeds if not full; throws ISE if full + * push succeeds if not full; throws IllegalStateException if full */ public void testPush() { LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); @@ -492,7 +492,7 @@ public class LinkedBlockingDequeTest ext } /** - * add succeeds if not full; throws ISE if full + * add succeeds if not full; throws IllegalStateException if full */ public void testAdd() { LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); @@ -506,7 +506,7 @@ public class LinkedBlockingDequeTest ext } /** - * addAll(this) throws IAE + * addAll(this) throws IllegalArgumentException */ public void testAddAllSelf() { LinkedBlockingDeque q = populatedDeque(SIZE); @@ -626,6 +626,13 @@ public class LinkedBlockingDequeTest ext pleaseTake.countDown(); q.put(86); + Thread.currentThread().interrupt(); + try { + q.put(99); + shouldThrow(); + } catch (InterruptedException success) {} + assertFalse(Thread.interrupted()); + pleaseInterrupt.countDown(); try { q.put(99); @@ -648,7 +655,7 @@ public class LinkedBlockingDequeTest ext /** * timed offer times out if full and elements not taken */ - public void testTimedOffer() throws InterruptedException { + public void testTimedOffer() { final LinkedBlockingDeque q = new LinkedBlockingDeque(2); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { @@ -658,6 +665,14 @@ public class LinkedBlockingDequeTest ext long startTime = System.nanoTime(); assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); + + Thread.currentThread().interrupt(); + try { + q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); + shouldThrow(); + } catch (InterruptedException success) {} + assertFalse(Thread.interrupted()); + pleaseInterrupt.countDown(); try { q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); @@ -885,7 +900,7 @@ public class LinkedBlockingDequeTest ext /** * timed offerFirst times out if full and elements not taken */ - public void testTimedOfferFirst() throws InterruptedException { + public void testTimedOfferFirst() { final LinkedBlockingDeque q = new LinkedBlockingDeque(2); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { @@ -895,6 +910,14 @@ public class LinkedBlockingDequeTest ext long startTime = System.nanoTime(); assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); + + Thread.currentThread().interrupt(); + try { + q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); + shouldThrow(); + } catch (InterruptedException success) {} + assertFalse(Thread.interrupted()); + pleaseInterrupt.countDown(); try { q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); @@ -1212,6 +1235,13 @@ public class LinkedBlockingDequeTest ext pleaseTake.countDown(); q.putLast(86); + Thread.currentThread().interrupt(); + try { + q.putLast(99); + shouldThrow(); + } catch (InterruptedException success) {} + assertFalse(Thread.interrupted()); + pleaseInterrupt.countDown(); try { q.putLast(99); @@ -1234,7 +1264,7 @@ public class LinkedBlockingDequeTest ext /** * timed offerLast times out if full and elements not taken */ - public void testTimedOfferLast() throws InterruptedException { + public void testTimedOfferLast() { final LinkedBlockingDeque q = new LinkedBlockingDeque(2); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { @@ -1244,6 +1274,13 @@ public class LinkedBlockingDequeTest ext long startTime = System.nanoTime(); assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); + + Thread.currentThread().interrupt(); + try { + q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); + shouldThrow(); + } catch (InterruptedException success) {} + pleaseInterrupt.countDown(); try { q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); @@ -1506,9 +1543,11 @@ public class LinkedBlockingDequeTest ext */ public void testToArray() throws InterruptedException { LinkedBlockingDeque q = populatedDeque(SIZE); - Object[] o = q.toArray(); - for (int i = 0; i < o.length; i++) - assertSame(o[i], q.poll()); + Object[] a = q.toArray(); + assertSame(Object[].class, a.getClass()); + for (Object o : a) + assertSame(o, q.poll()); + assertTrue(q.isEmpty()); } /** @@ -1519,8 +1558,9 @@ public class LinkedBlockingDequeTest ext Integer[] ints = new Integer[SIZE]; Integer[] array = q.toArray(ints); assertSame(ints, array); - for (int i = 0; i < ints.length; i++) - assertSame(ints[i], q.remove()); + for (Integer o : ints) + assertSame(o, q.remove()); + assertTrue(q.isEmpty()); } /** @@ -1736,7 +1776,7 @@ public class LinkedBlockingDequeTest ext } /** - * A deserialized serialized deque has same elements in same order + * A deserialized/reserialized deque has same elements in same order */ public void testSerialization() throws Exception { Queue x = populatedDeque(SIZE);