< prev index next >
test/jdk/java/util/concurrent/tck/ArrayBlockingQueueTest.java
Print this page
8225490: Miscellaneous changes imported from jsr166 CVS 2019-09
Reviewed-by: martin, alanb
*** 59,69 ****
public static Test suite() {
class Implementation implements CollectionImplementation {
public Class<?> klazz() { return ArrayBlockingQueue.class; }
public Collection emptyCollection() {
! boolean fair = ThreadLocalRandom.current().nextBoolean();
return populatedQueue(0, SIZE, 2 * SIZE, fair);
}
public Object makeElement(int i) { return i; }
public boolean isConcurrent() { return true; }
public boolean permitsNulls() { return false; }
--- 59,69 ----
public static Test suite() {
class Implementation implements CollectionImplementation {
public Class<?> klazz() { return ArrayBlockingQueue.class; }
public Collection emptyCollection() {
! boolean fair = randomBoolean();
return populatedQueue(0, SIZE, 2 * SIZE, fair);
}
public Object makeElement(int i) { return i; }
public boolean isConcurrent() { return true; }
public boolean permitsNulls() { return false; }
*** 365,375 ****
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
}});
await(pleaseInterrupt);
! assertThreadBlocks(t, Thread.State.WAITING);
t.interrupt();
awaitTermination(t);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
}
--- 365,375 ----
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
}});
await(pleaseInterrupt);
! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
t.interrupt();
awaitTermination(t);
assertEquals(SIZE, q.size());
assertEquals(0, q.remainingCapacity());
}
*** 407,417 ****
await(pleaseTake);
assertEquals(0, q.remainingCapacity());
assertEquals(0, q.take());
await(pleaseInterrupt);
! assertThreadBlocks(t, Thread.State.WAITING);
t.interrupt();
awaitTermination(t);
assertEquals(0, q.remainingCapacity());
}
--- 407,417 ----
await(pleaseTake);
assertEquals(0, q.remainingCapacity());
assertEquals(0, q.take());
await(pleaseInterrupt);
! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
t.interrupt();
awaitTermination(t);
assertEquals(0, q.remainingCapacity());
}
*** 429,453 ****
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);
shouldThrow();
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
}});
await(pleaseInterrupt);
! assertThreadBlocks(t, Thread.State.TIMED_WAITING);
t.interrupt();
awaitTermination(t);
}
/**
--- 429,453 ----
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
Thread.currentThread().interrupt();
try {
! q.offer(new Object(), randomTimeout(), randomTimeUnit());
shouldThrow();
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
! q.offer(new Object(), LONGER_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
}});
await(pleaseInterrupt);
! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
t.interrupt();
awaitTermination(t);
}
/**
*** 484,494 ****
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
}});
await(pleaseInterrupt);
! assertThreadBlocks(t, Thread.State.WAITING);
t.interrupt();
awaitTermination(t);
}
/**
--- 484,494 ----
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
}});
await(pleaseInterrupt);
! if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING);
t.interrupt();
awaitTermination(t);
}
/**
*** 537,569 ****
public void testInterruptedTimedPoll() throws InterruptedException {
final BlockingQueue<Integer> q = populatedQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
- long startTime = System.nanoTime();
for (int i = 0; i < SIZE; i++)
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
Thread.currentThread().interrupt();
try {
! q.poll(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
! q.poll(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
-
- assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}});
await(pleaseInterrupt);
! assertThreadBlocks(t, Thread.State.TIMED_WAITING);
t.interrupt();
awaitTermination(t);
checkEmpty(q);
}
--- 537,566 ----
public void testInterruptedTimedPoll() throws InterruptedException {
final BlockingQueue<Integer> q = populatedQueue(SIZE);
final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
for (int i = 0; i < SIZE; i++)
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
Thread.currentThread().interrupt();
try {
! q.poll(randomTimeout(), randomTimeUnit());
shouldThrow();
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
pleaseInterrupt.countDown();
try {
! q.poll(LONGER_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (InterruptedException success) {}
assertFalse(Thread.interrupted());
}});
await(pleaseInterrupt);
! if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING);
t.interrupt();
awaitTermination(t);
checkEmpty(q);
}
< prev index next >