7 |
|
import junit.framework.*; |
8 |
|
import java.util.*; |
9 |
|
import java.util.concurrent.*; |
10 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
11 |
|
import java.io.*; |
12 |
|
|
13 |
|
public class LinkedBlockingDequeTest extends JSR166TestCase { |
668 |
|
try { |
669 |
|
q.put(new Object()); |
670 |
|
q.put(new Object()); |
671 |
< |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
672 |
< |
q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
671 |
> |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
672 |
> |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
673 |
|
threadShouldThrow(); |
674 |
|
} catch (InterruptedException success) {} |
675 |
|
} |
768 |
|
try { |
769 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
770 |
|
for (int i = 0; i < SIZE; ++i) { |
771 |
< |
assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue()); |
771 |
> |
assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); |
772 |
|
} |
773 |
< |
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
773 |
> |
assertNull(q.poll(0, MILLISECONDS)); |
774 |
|
} catch (InterruptedException e) { |
775 |
|
unexpectedException(); |
776 |
|
} |
783 |
|
try { |
784 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
785 |
|
for (int i = 0; i < SIZE; ++i) { |
786 |
< |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
786 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
787 |
|
} |
788 |
< |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
788 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
789 |
|
} catch (InterruptedException e) { |
790 |
|
unexpectedException(); |
791 |
|
} |
801 |
|
try { |
802 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
803 |
|
for (int i = 0; i < SIZE; ++i) { |
804 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
804 |
> |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
805 |
|
} |
806 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
806 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
807 |
|
} catch (InterruptedException success) { |
808 |
|
} |
809 |
|
}}); |
827 |
|
Thread t = new Thread(new Runnable() { |
828 |
|
public void run() { |
829 |
|
try { |
830 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
831 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
832 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
830 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
831 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
832 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
833 |
|
threadShouldThrow(); |
834 |
|
} catch (InterruptedException success) { } |
835 |
|
} |
837 |
|
try { |
838 |
|
t.start(); |
839 |
|
Thread.sleep(SMALL_DELAY_MS); |
840 |
< |
assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
840 |
> |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
841 |
|
t.interrupt(); |
842 |
|
t.join(); |
843 |
|
} catch (Exception e) { |
954 |
|
try { |
955 |
|
q.putFirst(new Object()); |
956 |
|
q.putFirst(new Object()); |
957 |
< |
threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
958 |
< |
q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
957 |
> |
threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
958 |
> |
q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS); |
959 |
|
threadShouldThrow(); |
960 |
|
} catch (InterruptedException success) {} |
961 |
|
} |
1043 |
|
try { |
1044 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1045 |
|
for (int i = 0; i < SIZE; ++i) { |
1046 |
< |
assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue()); |
1046 |
> |
assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue()); |
1047 |
|
} |
1048 |
< |
assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS)); |
1048 |
> |
assertNull(q.pollFirst(0, MILLISECONDS)); |
1049 |
|
} catch (InterruptedException e) { |
1050 |
|
unexpectedException(); |
1051 |
|
} |
1058 |
|
try { |
1059 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1060 |
|
for (int i = 0; i < SIZE; ++i) { |
1061 |
< |
assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
1061 |
> |
assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1062 |
|
} |
1063 |
< |
assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1063 |
> |
assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); |
1064 |
|
} catch (InterruptedException e) { |
1065 |
|
unexpectedException(); |
1066 |
|
} |
1076 |
|
try { |
1077 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1078 |
|
for (int i = 0; i < SIZE; ++i) { |
1079 |
< |
threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
1079 |
> |
threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1080 |
|
} |
1081 |
< |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1081 |
> |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); |
1082 |
|
} catch (InterruptedException success) { |
1083 |
|
} |
1084 |
|
}}); |
1102 |
|
Thread t = new Thread(new Runnable() { |
1103 |
|
public void run() { |
1104 |
|
try { |
1105 |
< |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1106 |
< |
q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1107 |
< |
q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1105 |
> |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); |
1106 |
> |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
1107 |
> |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
1108 |
|
threadShouldThrow(); |
1109 |
|
} catch (InterruptedException success) { } |
1110 |
|
} |
1112 |
|
try { |
1113 |
|
t.start(); |
1114 |
|
Thread.sleep(SMALL_DELAY_MS); |
1115 |
< |
assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1115 |
> |
assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS)); |
1116 |
|
t.interrupt(); |
1117 |
|
t.join(); |
1118 |
|
} catch (Exception e) { |
1228 |
|
try { |
1229 |
|
q.putLast(new Object()); |
1230 |
|
q.putLast(new Object()); |
1231 |
< |
threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1232 |
< |
q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1231 |
> |
threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
1232 |
> |
q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1233 |
|
threadShouldThrow(); |
1234 |
|
} catch (InterruptedException success) {} |
1235 |
|
} |
1317 |
|
try { |
1318 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1319 |
|
for (int i = 0; i < SIZE; ++i) { |
1320 |
< |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue()); |
1320 |
> |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue()); |
1321 |
|
} |
1322 |
< |
assertNull(q.pollLast(0, TimeUnit.MILLISECONDS)); |
1322 |
> |
assertNull(q.pollLast(0, MILLISECONDS)); |
1323 |
|
} catch (InterruptedException e) { |
1324 |
|
unexpectedException(); |
1325 |
|
} |
1332 |
|
try { |
1333 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1334 |
|
for (int i = 0; i < SIZE; ++i) { |
1335 |
< |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
1335 |
> |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1336 |
|
} |
1337 |
< |
assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1337 |
> |
assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS)); |
1338 |
|
} catch (InterruptedException e) { |
1339 |
|
unexpectedException(); |
1340 |
|
} |
1350 |
|
try { |
1351 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1352 |
|
for (int i = 0; i < SIZE; ++i) { |
1353 |
< |
threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
1353 |
> |
threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1354 |
|
} |
1355 |
< |
threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1355 |
> |
threadAssertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS)); |
1356 |
|
} catch (InterruptedException success) { |
1357 |
|
} |
1358 |
|
}}); |
1376 |
|
Thread t = new Thread(new Runnable() { |
1377 |
|
public void run() { |
1378 |
|
try { |
1379 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1380 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1381 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
1379 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
1380 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
1381 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
1382 |
|
threadShouldThrow(); |
1383 |
|
} catch (InterruptedException success) { } |
1384 |
|
} |
1386 |
|
try { |
1387 |
|
t.start(); |
1388 |
|
Thread.sleep(SMALL_DELAY_MS); |
1389 |
< |
assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
1389 |
> |
assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS)); |
1390 |
|
t.interrupt(); |
1391 |
|
t.join(); |
1392 |
|
} catch (Exception e) { |
1716 |
|
public void run() { |
1717 |
|
threadAssertFalse(q.offer(three)); |
1718 |
|
try { |
1719 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
1719 |
> |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
1720 |
|
threadAssertEquals(0, q.remainingCapacity()); |
1721 |
|
} |
1722 |
|
catch (InterruptedException e) { |
1750 |
|
public void run() { |
1751 |
|
threadAssertNull(q.poll()); |
1752 |
|
try { |
1753 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
1753 |
> |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
1754 |
|
threadAssertTrue(q.isEmpty()); |
1755 |
|
} |
1756 |
|
catch (InterruptedException e) { |