448 |
|
*/ |
449 |
|
public void testRemoveElement() throws InterruptedException { |
450 |
|
LinkedTransferQueue q = populatedQueue(SIZE); |
451 |
< |
for (int i = 1; i < SIZE; i += 2) { |
451 |
> |
for (int i = 1; i < SIZE; i+=2) { |
452 |
> |
assertTrue(q.contains(i)); |
453 |
|
assertTrue(q.remove(i)); |
454 |
+ |
assertFalse(q.contains(i)); |
455 |
+ |
assertTrue(q.contains(i-1)); |
456 |
|
} |
457 |
< |
for (int i = 0; i < SIZE; i += 2) { |
457 |
> |
for (int i = 0; i < SIZE; i+=2) { |
458 |
> |
assertTrue(q.contains(i)); |
459 |
|
assertTrue(q.remove(i)); |
460 |
< |
assertFalse(q.remove(i + 1)); |
460 |
> |
assertFalse(q.contains(i)); |
461 |
> |
assertFalse(q.remove(i+1)); |
462 |
> |
assertFalse(q.contains(i+1)); |
463 |
|
} |
464 |
|
checkEmpty(q); |
465 |
|
} |
1078 |
|
} |
1079 |
|
|
1080 |
|
/** |
1081 |
< |
* tryTransfer waits the amount given if interrupted, and |
1082 |
< |
* throws interrupted exception |
1081 |
> |
* tryTransfer waits the amount given, and throws |
1082 |
> |
* InterruptedException when interrupted. |
1083 |
|
*/ |
1084 |
|
public void testTryTransfer5() throws InterruptedException { |
1085 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |
1086 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
1087 |
+ |
assertTrue(q.isEmpty()); |
1088 |
|
|
1089 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1090 |
|
public void realRun() throws InterruptedException { |
1095 |
|
shouldThrow(); |
1096 |
|
} catch (InterruptedException success) {} |
1097 |
|
assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS); |
1098 |
+ |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
1099 |
|
}}); |
1100 |
|
|
1101 |
|
threadStarted.await(); |
1102 |
+ |
while (q.isEmpty()) |
1103 |
+ |
Thread.yield(); |
1104 |
|
Thread.sleep(SHORT_DELAY_MS); |
1105 |
|
t.interrupt(); |
1106 |
|
awaitTermination(t, MEDIUM_DELAY_MS); |
1150 |
|
} |
1151 |
|
|
1152 |
|
/** |
1153 |
< |
* tryTransfer attempts to enqueue into the q and fails returning |
1154 |
< |
* false not enqueueing and the successive poll is null |
1153 |
> |
* tryTransfer attempts to enqueue into the queue and fails |
1154 |
> |
* returning false not enqueueing and the successive poll is null |
1155 |
|
*/ |
1156 |
|
public void testTryTransfer8() throws InterruptedException { |
1157 |
|
final LinkedTransferQueue q = new LinkedTransferQueue(); |