281 |
|
} |
282 |
|
for (int i = 0; i < SIZE; i += 2) { |
283 |
|
assertTrue(q.removeFirstOccurrence(new Integer(i))); |
284 |
< |
assertFalse(q.removeFirstOccurrence(new Integer(i+1))); |
284 |
> |
assertFalse(q.removeFirstOccurrence(new Integer(i + 1))); |
285 |
|
} |
286 |
|
assertTrue(q.isEmpty()); |
287 |
|
} |
296 |
|
} |
297 |
|
for (int i = 0; i < SIZE; i += 2) { |
298 |
|
assertTrue(q.removeLastOccurrence(new Integer(i))); |
299 |
< |
assertFalse(q.removeLastOccurrence(new Integer(i+1))); |
299 |
> |
assertFalse(q.removeLastOccurrence(new Integer(i + 1))); |
300 |
|
} |
301 |
|
assertTrue(q.isEmpty()); |
302 |
|
} |
1246 |
|
public void testTakeLast() throws InterruptedException { |
1247 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1248 |
|
for (int i = 0; i < SIZE; ++i) { |
1249 |
< |
assertEquals(SIZE - i-1, q.takeLast()); |
1249 |
> |
assertEquals(SIZE - i - 1, q.takeLast()); |
1250 |
|
} |
1251 |
|
} |
1252 |
|
|
1259 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1260 |
|
public void realRun() throws InterruptedException { |
1261 |
|
for (int i = 0; i < SIZE; ++i) { |
1262 |
< |
assertEquals(SIZE - i-1, q.takeLast()); |
1262 |
> |
assertEquals(SIZE - i - 1, q.takeLast()); |
1263 |
|
} |
1264 |
|
|
1265 |
|
Thread.currentThread().interrupt(); |
1289 |
|
public void testTimedPollLast0() throws InterruptedException { |
1290 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1291 |
|
for (int i = 0; i < SIZE; ++i) { |
1292 |
< |
assertEquals(SIZE - i-1, q.pollLast(0, MILLISECONDS)); |
1292 |
> |
assertEquals(SIZE - i - 1, q.pollLast(0, MILLISECONDS)); |
1293 |
|
} |
1294 |
|
assertNull(q.pollLast(0, MILLISECONDS)); |
1295 |
|
} |
1301 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1302 |
|
for (int i = 0; i < SIZE; ++i) { |
1303 |
|
long startTime = System.nanoTime(); |
1304 |
< |
assertEquals(SIZE - i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS)); |
1304 |
> |
assertEquals(SIZE - i - 1, q.pollLast(LONG_DELAY_MS, MILLISECONDS)); |
1305 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1306 |
|
} |
1307 |
|
long startTime = System.nanoTime(); |
1320 |
|
public void realRun() throws InterruptedException { |
1321 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1322 |
|
for (int i = 0; i < SIZE; ++i) { |
1323 |
< |
assertEquals(SIZE - i-1, q.pollLast(LONG_DELAY_MS, MILLISECONDS)); |
1323 |
> |
assertEquals(SIZE - i - 1, |
1324 |
> |
q.pollLast(LONG_DELAY_MS, MILLISECONDS)); |
1325 |
|
} |
1326 |
|
|
1327 |
|
Thread.currentThread().interrupt(); |
1671 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1672 |
|
q.add(one); |
1673 |
|
q.add(two); |
1673 |
– |
ExecutorService executor = Executors.newFixedThreadPool(2); |
1674 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
1675 |
< |
executor.execute(new CheckedRunnable() { |
1676 |
< |
public void realRun() throws InterruptedException { |
1677 |
< |
assertFalse(q.offer(three)); |
1678 |
< |
threadsStarted.await(); |
1679 |
< |
assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS)); |
1680 |
< |
assertEquals(0, q.remainingCapacity()); |
1681 |
< |
}}); |
1682 |
< |
|
1683 |
< |
executor.execute(new CheckedRunnable() { |
1684 |
< |
public void realRun() throws InterruptedException { |
1685 |
< |
threadsStarted.await(); |
1686 |
< |
assertSame(one, q.take()); |
1687 |
< |
}}); |
1688 |
< |
|
1689 |
< |
joinPool(executor); |
1675 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
1676 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
1677 |
> |
executor.execute(new CheckedRunnable() { |
1678 |
> |
public void realRun() throws InterruptedException { |
1679 |
> |
assertFalse(q.offer(three)); |
1680 |
> |
threadsStarted.await(); |
1681 |
> |
assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS)); |
1682 |
> |
assertEquals(0, q.remainingCapacity()); |
1683 |
> |
}}); |
1684 |
> |
|
1685 |
> |
executor.execute(new CheckedRunnable() { |
1686 |
> |
public void realRun() throws InterruptedException { |
1687 |
> |
threadsStarted.await(); |
1688 |
> |
assertSame(one, q.take()); |
1689 |
> |
}}); |
1690 |
> |
} |
1691 |
|
} |
1692 |
|
|
1693 |
|
/** |
1696 |
|
public void testPollInExecutor() { |
1697 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1698 |
|
final CheckedBarrier threadsStarted = new CheckedBarrier(2); |
1699 |
< |
ExecutorService executor = Executors.newFixedThreadPool(2); |
1700 |
< |
executor.execute(new CheckedRunnable() { |
1701 |
< |
public void realRun() throws InterruptedException { |
1702 |
< |
assertNull(q.poll()); |
1703 |
< |
threadsStarted.await(); |
1704 |
< |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
1705 |
< |
checkEmpty(q); |
1706 |
< |
}}); |
1707 |
< |
|
1708 |
< |
executor.execute(new CheckedRunnable() { |
1709 |
< |
public void realRun() throws InterruptedException { |
1710 |
< |
threadsStarted.await(); |
1711 |
< |
q.put(one); |
1712 |
< |
}}); |
1713 |
< |
|
1714 |
< |
joinPool(executor); |
1699 |
> |
final ExecutorService executor = Executors.newFixedThreadPool(2); |
1700 |
> |
try (PoolCleaner cleaner = cleaner(executor)) { |
1701 |
> |
executor.execute(new CheckedRunnable() { |
1702 |
> |
public void realRun() throws InterruptedException { |
1703 |
> |
assertNull(q.poll()); |
1704 |
> |
threadsStarted.await(); |
1705 |
> |
assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
1706 |
> |
checkEmpty(q); |
1707 |
> |
}}); |
1708 |
> |
|
1709 |
> |
executor.execute(new CheckedRunnable() { |
1710 |
> |
public void realRun() throws InterruptedException { |
1711 |
> |
threadsStarted.await(); |
1712 |
> |
q.put(one); |
1713 |
> |
}}); |
1714 |
> |
} |
1715 |
|
} |
1716 |
|
|
1717 |
|
/** |