code
stringlengths 11
173k
| docstring
stringlengths 2
593k
| func_name
stringlengths 2
189
| language
stringclasses 1
value | repo
stringclasses 833
values | path
stringlengths 11
294
| url
stringlengths 60
339
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public void testSchedule5() throws InterruptedException {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
final long startTime = System.nanoTime();
final CountDownLatch done = new CountDownLatch(1);
Runnable task = new CheckedRunnable() {
public void realRun() {
done.countDown();
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
}};
ScheduledFuture f =
p.scheduleWithFixedDelay(task, timeoutMillis(),
LONG_DELAY_MS, MILLISECONDS);
await(done);
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
f.cancel(true);
}
} |
scheduleWithFixedDelay executes runnable after given initial delay
| CustomExecutor::testSchedule5 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testFixedRateSequence() throws InterruptedException {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
final long startTime = System.nanoTime();
final int cycles = 8;
final CountDownLatch done = new CountDownLatch(cycles);
final Runnable task = new CheckedRunnable() {
public void realRun() { done.countDown(); }};
final ScheduledFuture periodicTask =
p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
final int totalDelayMillis = (cycles - 1) * delay;
await(done, totalDelayMillis + LONG_DELAY_MS);
periodicTask.cancel(true);
final long elapsedMillis = millisElapsedSince(startTime);
assertTrue(elapsedMillis >= totalDelayMillis);
if (elapsedMillis <= cycles * delay)
return;
// else retry with longer delay
}
fail("unexpected execution rate");
}
} |
scheduleAtFixedRate executes series of tasks at given rate.
Eventually, it must hold that:
cycles - 1 <= elapsedMillis/delay < cycles
| RunnableCounter::testFixedRateSequence | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testFixedDelaySequence() throws InterruptedException {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
final long startTime = System.nanoTime();
final AtomicLong previous = new AtomicLong(startTime);
final AtomicBoolean tryLongerDelay = new AtomicBoolean(false);
final int cycles = 8;
final CountDownLatch done = new CountDownLatch(cycles);
final int d = delay;
final Runnable task = new CheckedRunnable() {
public void realRun() {
long now = System.nanoTime();
long elapsedMillis
= NANOSECONDS.toMillis(now - previous.get());
if (done.getCount() == cycles) { // first execution
if (elapsedMillis >= d)
tryLongerDelay.set(true);
} else {
assertTrue(elapsedMillis >= d);
if (elapsedMillis >= 2 * d)
tryLongerDelay.set(true);
}
previous.set(now);
done.countDown();
}};
final ScheduledFuture periodicTask =
p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS);
final int totalDelayMillis = (cycles - 1) * delay;
await(done, totalDelayMillis + cycles * LONG_DELAY_MS);
periodicTask.cancel(true);
final long elapsedMillis = millisElapsedSince(startTime);
assertTrue(elapsedMillis >= totalDelayMillis);
if (!tryLongerDelay.get())
return;
// else retry with longer delay
}
fail("unexpected execution rate");
}
} |
scheduleWithFixedDelay executes series of tasks with given period.
Eventually, it must hold that each task starts at least delay and at
most 2 * delay after the termination of the previous task.
| RunnableCounter::testFixedDelaySequence | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testScheduleNull() throws InterruptedException {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
try {
TrackedCallable callable = null;
Future f = p.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (NullPointerException success) {}
}
} |
schedule(null) throws NPE
| RunnableCounter::testScheduleNull | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testSchedule2_RejectedExecutionException() {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.shutdown();
p.schedule(new NoOpCallable(),
MEDIUM_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (RejectedExecutionException success) {
} catch (SecurityException ok) {}
}
} |
schedule throws RejectedExecutionException if shutdown
| RunnableCounter::testSchedule2_RejectedExecutionException | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testSchedule3_RejectedExecutionException() {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.shutdown();
p.schedule(new NoOpCallable(),
MEDIUM_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (RejectedExecutionException success) {
} catch (SecurityException ok) {}
}
} |
schedule callable throws RejectedExecutionException if shutdown
| RunnableCounter::testSchedule3_RejectedExecutionException | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testScheduleAtFixedRate1_RejectedExecutionException() {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.shutdown();
p.scheduleAtFixedRate(new NoOpRunnable(),
MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (RejectedExecutionException success) {
} catch (SecurityException ok) {}
}
} |
scheduleAtFixedRate throws RejectedExecutionException if shutdown
| RunnableCounter::testScheduleAtFixedRate1_RejectedExecutionException | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testScheduleWithFixedDelay1_RejectedExecutionException() {
final CustomExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p)) {
try {
p.shutdown();
p.scheduleWithFixedDelay(new NoOpRunnable(),
MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (RejectedExecutionException success) {
} catch (SecurityException ok) {}
}
} |
scheduleWithFixedDelay throws RejectedExecutionException if shutdown
| RunnableCounter::testScheduleWithFixedDelay1_RejectedExecutionException | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testGetTaskCount() throws InterruptedException {
final int TASKS = 3;
final CountDownLatch done = new CountDownLatch(1);
final ThreadPoolExecutor p = new CustomExecutor(1);
try (PoolCleaner cleaner = cleaner(p, done)) {
final CountDownLatch threadStarted = new CountDownLatch(1);
assertEquals(0, p.getTaskCount());
assertEquals(0, p.getCompletedTaskCount());
p.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
threadStarted.countDown();
await(done);
}});
await(threadStarted);
assertEquals(1, p.getTaskCount());
assertEquals(0, p.getCompletedTaskCount());
for (int i = 0; i < TASKS; i++) {
assertEquals(1 + i, p.getTaskCount());
p.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
threadStarted.countDown();
assertEquals(1 + TASKS, p.getTaskCount());
await(done);
}});
}
assertEquals(1 + TASKS, p.getTaskCount());
assertEquals(0, p.getCompletedTaskCount());
}
assertEquals(1 + TASKS, p.getTaskCount());
assertEquals(1 + TASKS, p.getCompletedTaskCount());
} |
getTaskCount increases, but doesn't overestimate, when tasks
submitted
| RunnableCounter::testGetTaskCount | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testShutdown_cancellation() throws Exception {
Boolean[] allBooleans = { null, Boolean.FALSE, Boolean.TRUE };
for (Boolean policy : allBooleans)
{
final int poolSize = 2;
final CustomExecutor p = new CustomExecutor(poolSize);
final boolean effectiveDelayedPolicy = (policy != Boolean.FALSE);
final boolean effectivePeriodicPolicy = (policy == Boolean.TRUE);
final boolean effectiveRemovePolicy = (policy == Boolean.TRUE);
if (policy != null) {
p.setExecuteExistingDelayedTasksAfterShutdownPolicy(policy);
p.setContinueExistingPeriodicTasksAfterShutdownPolicy(policy);
p.setRemoveOnCancelPolicy(policy);
}
assertEquals(effectiveDelayedPolicy,
p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
assertEquals(effectivePeriodicPolicy,
p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
assertEquals(effectiveRemovePolicy,
p.getRemoveOnCancelPolicy());
// Strategy: Wedge the pool with poolSize "blocker" threads
final AtomicInteger ran = new AtomicInteger(0);
final CountDownLatch poolBlocked = new CountDownLatch(poolSize);
final CountDownLatch unblock = new CountDownLatch(1);
final CountDownLatch periodicLatch1 = new CountDownLatch(2);
final CountDownLatch periodicLatch2 = new CountDownLatch(2);
Runnable task = new CheckedRunnable() { public void realRun()
throws InterruptedException {
poolBlocked.countDown();
assertTrue(unblock.await(LONG_DELAY_MS, MILLISECONDS));
ran.getAndIncrement();
}};
List<Future<?>> blockers = new ArrayList<>();
List<Future<?>> periodics = new ArrayList<>();
List<Future<?>> delayeds = new ArrayList<>();
for (int i = 0; i < poolSize; i++)
blockers.add(p.submit(task));
assertTrue(poolBlocked.await(LONG_DELAY_MS, MILLISECONDS));
periodics.add(p.scheduleAtFixedRate(countDowner(periodicLatch1),
1, 1, MILLISECONDS));
periodics.add(p.scheduleWithFixedDelay(countDowner(periodicLatch2),
1, 1, MILLISECONDS));
delayeds.add(p.schedule(task, 1, MILLISECONDS));
assertTrue(p.getQueue().containsAll(periodics));
assertTrue(p.getQueue().containsAll(delayeds));
try { p.shutdown(); } catch (SecurityException ok) { return; }
assertTrue(p.isShutdown());
assertFalse(p.isTerminated());
for (Future<?> periodic : periodics) {
assertTrue(effectivePeriodicPolicy ^ periodic.isCancelled());
assertTrue(effectivePeriodicPolicy ^ periodic.isDone());
}
for (Future<?> delayed : delayeds) {
assertTrue(effectiveDelayedPolicy ^ delayed.isCancelled());
assertTrue(effectiveDelayedPolicy ^ delayed.isDone());
}
if (testImplementationDetails) {
assertEquals(effectivePeriodicPolicy,
p.getQueue().containsAll(periodics));
assertEquals(effectiveDelayedPolicy,
p.getQueue().containsAll(delayeds));
}
// Release all pool threads
unblock.countDown();
for (Future<?> delayed : delayeds) {
if (effectiveDelayedPolicy) {
assertNull(delayed.get());
}
}
if (effectivePeriodicPolicy) {
assertTrue(periodicLatch1.await(LONG_DELAY_MS, MILLISECONDS));
assertTrue(periodicLatch2.await(LONG_DELAY_MS, MILLISECONDS));
for (Future<?> periodic : periodics) {
assertTrue(periodic.cancel(false));
assertTrue(periodic.isCancelled());
assertTrue(periodic.isDone());
}
}
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
assertTrue(p.isTerminated());
assertEquals(2 + (effectiveDelayedPolicy ? 1 : 0), ran.get());
}} |
By default, periodic tasks are cancelled at shutdown.
By default, delayed tasks keep running after shutdown.
Check that changing the default values work:
- setExecuteExistingDelayedTasksAfterShutdownPolicy
- setContinueExistingPeriodicTasksAfterShutdownPolicy
| RunnableCounter::testShutdown_cancellation | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
public void testInvokeAll4() throws Exception {
final ExecutorService e = new CustomExecutor(2);
try (PoolCleaner cleaner = cleaner(e)) {
List<Callable<String>> l = new ArrayList<Callable<String>>();
l.add(new NPETask());
List<Future<String>> futures = e.invokeAll(l);
assertEquals(1, futures.size());
try {
futures.get(0).get();
shouldThrow();
} catch (ExecutionException success) {
assertTrue(success.getCause() instanceof NullPointerException);
}
}
} |
get of invokeAll(c) throws exception on failed task
| RunnableCounter::testInvokeAll4 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorSubclassTest.java | Apache-2.0 |
void releaseLock(PublicReentrantLock lock) {
assertLockedByMoi(lock);
lock.unlock();
assertFalse(lock.isHeldByCurrentThread());
assertNotLocked(lock);
} |
Releases write lock, checking that it had a hold count of 1.
| PublicReentrantLock::releaseLock | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
void waitForQueuedThread(PublicReentrantLock lock, Thread t) {
long startTime = System.nanoTime();
while (!lock.hasQueuedThread(t)) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
throw new AssertionFailedError("timed out");
Thread.yield();
}
assertTrue(t.isAlive());
assertNotSame(t, lock.getOwner());
} |
Spin-waits until lock.hasQueuedThread(t) becomes true.
| PublicReentrantLock::waitForQueuedThread | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
void assertNotLocked(PublicReentrantLock lock) {
assertFalse(lock.isLocked());
assertFalse(lock.isHeldByCurrentThread());
assertNull(lock.getOwner());
assertEquals(0, lock.getHoldCount());
} |
Checks that lock is not locked.
| PublicReentrantLock::assertNotLocked | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
void assertLockedBy(PublicReentrantLock lock, Thread t) {
assertTrue(lock.isLocked());
assertSame(t, lock.getOwner());
assertEquals(t == Thread.currentThread(),
lock.isHeldByCurrentThread());
assertEquals(t == Thread.currentThread(),
lock.getHoldCount() > 0);
} |
Checks that lock is locked by the given thread.
| PublicReentrantLock::assertLockedBy | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
void assertLockedByMoi(PublicReentrantLock lock) {
assertLockedBy(lock, Thread.currentThread());
} |
Checks that lock is locked by the current thread.
| PublicReentrantLock::assertLockedByMoi | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
void assertHasNoWaiters(PublicReentrantLock lock, Condition c) {
assertHasWaiters(lock, c, new Thread[] {});
} |
Checks that condition c has no waiters.
| PublicReentrantLock::assertHasNoWaiters | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
void await(Condition c, AwaitMethod awaitMethod)
throws InterruptedException {
long timeoutMillis = 2 * LONG_DELAY_MS;
switch (awaitMethod) {
case await:
c.await();
break;
case awaitTimed:
assertTrue(c.await(timeoutMillis, MILLISECONDS));
break;
case awaitNanos:
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
long nanosRemaining = c.awaitNanos(timeoutNanos);
assertTrue(nanosRemaining > timeoutNanos / 2);
assertTrue(nanosRemaining <= timeoutNanos);
break;
case awaitUntil:
assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
break;
default:
throw new AssertionError();
}
} |
Awaits condition "indefinitely" using the specified AwaitMethod.
| AwaitMethod::await | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testConstructor() {
PublicReentrantLock lock;
lock = new PublicReentrantLock();
assertFalse(lock.isFair());
assertNotLocked(lock);
lock = new PublicReentrantLock(true);
assertTrue(lock.isFair());
assertNotLocked(lock);
lock = new PublicReentrantLock(false);
assertFalse(lock.isFair());
assertNotLocked(lock);
} |
Constructor sets given fairness, and is in unlocked state
| AwaitMethod::testConstructor | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testLock() { testLock(false); } |
locking an unlocked lock succeeds
| AwaitMethod::testLock | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testUnlock_IMSE() { testUnlock_IMSE(false); } |
Unlocking an unlocked lock throws IllegalMonitorStateException
| AwaitMethod::testUnlock_IMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testTryLock() { testTryLock(false); } |
tryLock on an unlocked lock succeeds
| AwaitMethod::testTryLock | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testGetQueueLength() { testGetQueueLength(false); } |
getQueueLength reports number of waiting threads
| AwaitMethod::testGetQueueLength | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testHasQueuedThreadNPE() { testHasQueuedThreadNPE(false); } |
hasQueuedThread(null) throws NPE
| AwaitMethod::testHasQueuedThreadNPE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testHasQueuedThread() { testHasQueuedThread(false); } |
hasQueuedThread reports whether a thread is queued
| AwaitMethod::testHasQueuedThread | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testGetQueuedThreads() { testGetQueuedThreads(false); } |
getQueuedThreads includes waiting threads
| AwaitMethod::testGetQueuedThreads | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testTryLock_Interruptible() { testTryLock_Interruptible(false); } |
timed tryLock is interruptible
| AwaitMethod::testTryLock_Interruptible | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testTryLockWhenLocked() { testTryLockWhenLocked(false); } |
tryLock on a locked lock fails
| AwaitMethod::testTryLockWhenLocked | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testTryLock_Timeout() { testTryLock_Timeout(false); } |
Timed tryLock on a locked lock times out
| AwaitMethod::testTryLock_Timeout | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testGetHoldCount() { testGetHoldCount(false); } |
getHoldCount returns number of recursive holds
| AwaitMethod::testGetHoldCount | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testIsLocked() { testIsLocked(false); } |
isLocked is true when locked and false when not
| AwaitMethod::testIsLocked | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testLockInterruptibly() { testLockInterruptibly(false); } |
lockInterruptibly succeeds when unlocked, else is interruptible
| AwaitMethod::testLockInterruptibly | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testAwait_IMSE() { testAwait_IMSE(false); } |
Calling await without holding lock throws IllegalMonitorStateException
| AwaitMethod::testAwait_IMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testSignal_IMSE() { testSignal_IMSE(false); } |
Calling signal without holding lock throws IllegalMonitorStateException
| AwaitMethod::testSignal_IMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testAwaitNanos_Timeout() { testAwaitNanos_Timeout(false); } |
awaitNanos without a signal times out
| AwaitMethod::testAwaitNanos_Timeout | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testAwait_Timeout() { testAwait_Timeout(false); } |
timed await without a signal times out
| AwaitMethod::testAwait_Timeout | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testAwaitUntil_Timeout() { testAwaitUntil_Timeout(false); } |
awaitUntil without a signal times out
| AwaitMethod::testAwaitUntil_Timeout | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testAwait() { testAwait(false); } |
await returns when signalled
| AwaitMethod::testAwait | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testHasWaitersNPE() { testHasWaitersNPE(false); } |
hasWaiters throws NPE if null
| AwaitMethod::testHasWaitersNPE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testGetWaitQueueLengthNPE() { testGetWaitQueueLengthNPE(false); } |
getWaitQueueLength throws NPE if null
| AwaitMethod::testGetWaitQueueLengthNPE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testHasWaitersIMSE() { testHasWaitersIMSE(false); } |
hasWaiters throws IllegalMonitorStateException if not locked
| AwaitMethod::testHasWaitersIMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testGetWaitQueueLengthIMSE() { testGetWaitQueueLengthIMSE(false); } |
getWaitQueueLength throws IllegalMonitorStateException if not locked
| AwaitMethod::testGetWaitQueueLengthIMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testGetWaitingThreadsIMSE() { testGetWaitingThreadsIMSE(false); } |
getWaitingThreads throws IllegalMonitorStateException if not locked
| AwaitMethod::testGetWaitingThreadsIMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testSignalWakesFifo() { testSignalWakesFifo(false); } |
signal wakes up waiting threads in FIFO order
| AwaitMethod::testSignalWakesFifo | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testAwaitLockCount() { testAwaitLockCount(false); } |
await after multiple reentrant locking preserves lock count
| AwaitMethod::testAwaitLockCount | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testSerialization() { testSerialization(false); } |
A serialized lock deserializes as unlocked
| AwaitMethod::testSerialization | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
public void testToString() { testToString(false); } |
toString indicates current lock state
| AwaitMethod::testToString | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantLockTest.java | Apache-2.0 |
void awaitNumberWaiting(CyclicBarrier barrier, int numberOfWaiters) {
long startTime = System.nanoTime();
while (barrier.getNumberWaiting() != numberOfWaiters) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
fail("timed out");
Thread.yield();
}
} |
Spin-waits till the number of waiters == numberOfWaiters.
| MyAction::awaitNumberWaiting | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testConstructor1() {
try {
new CyclicBarrier(-1, (Runnable)null);
shouldThrow();
} catch (IllegalArgumentException success) {}
} |
Creating with negative parties throws IAE
| MyAction::testConstructor1 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testConstructor2() {
try {
new CyclicBarrier(-1);
shouldThrow();
} catch (IllegalArgumentException success) {}
} |
Creating with negative parties and no action throws IAE
| MyAction::testConstructor2 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testGetParties() {
CyclicBarrier b = new CyclicBarrier(2);
assertEquals(2, b.getParties());
assertEquals(0, b.getNumberWaiting());
} |
getParties returns the number of parties given in constructor
| MyAction::testGetParties | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testSingleParty() throws Exception {
CyclicBarrier b = new CyclicBarrier(1);
assertEquals(1, b.getParties());
assertEquals(0, b.getNumberWaiting());
b.await();
b.await();
assertEquals(0, b.getNumberWaiting());
} |
A 1-party barrier triggers after single await
| MyAction::testSingleParty | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testBarrierAction() throws Exception {
countAction = 0;
CyclicBarrier b = new CyclicBarrier(1, new MyAction());
assertEquals(1, b.getParties());
assertEquals(0, b.getNumberWaiting());
b.await();
b.await();
assertEquals(0, b.getNumberWaiting());
assertEquals(2, countAction);
} |
The supplied barrier action is run at barrier
| MyAction::testBarrierAction | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testTwoParties() throws Exception {
final CyclicBarrier b = new CyclicBarrier(2);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws Exception {
b.await();
b.await();
b.await();
b.await();
}});
b.await();
b.await();
b.await();
b.await();
awaitTermination(t);
} |
A 2-party/thread barrier triggers after both threads invoke await
| MyAction::testTwoParties | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testAwait1_Interrupted_BrokenBarrier() {
final CyclicBarrier c = new CyclicBarrier(3);
final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
Thread t1 = new ThreadShouldThrow(InterruptedException.class) {
public void realRun() throws Exception {
pleaseInterrupt.countDown();
c.await();
}};
Thread t2 = new ThreadShouldThrow(BrokenBarrierException.class) {
public void realRun() throws Exception {
pleaseInterrupt.countDown();
c.await();
}};
t1.start();
t2.start();
await(pleaseInterrupt);
t1.interrupt();
awaitTermination(t1);
awaitTermination(t2);
} |
An interruption in one party causes others waiting in await to
throw BrokenBarrierException
| MyAction::testAwait1_Interrupted_BrokenBarrier | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CyclicBarrierTest.java | Apache-2.0 |
public void testPush() {
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
for (int i = 0; i < SIZE; ++i) {
Integer x = new Integer(i);
q.push(x);
assertEquals(x, q.peek());
}
assertEquals(0, q.remainingCapacity());
try {
q.push(new Integer(SIZE));
shouldThrow();
} catch (IllegalStateException success) {}
} |
push succeeds if not full; throws ISE if full
| Bounded::testPush | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedBlockingDequeTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedBlockingDequeTest.java | Apache-2.0 |
public void testAdd() {
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
for (int i = 0; i < SIZE; ++i)
assertTrue(q.add(new Integer(i)));
assertEquals(0, q.remainingCapacity());
try {
q.add(new Integer(SIZE));
shouldThrow();
} catch (IllegalStateException success) {}
} |
add succeeds if not full; throws ISE if full
| Bounded::testAdd | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedBlockingDequeTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedBlockingDequeTest.java | Apache-2.0 |
public void testConstructor() {
AtomicReference ai = new AtomicReference(one);
assertSame(one, ai.get());
} |
constructor initializes to given value
| AtomicReferenceTest::testConstructor | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | Apache-2.0 |
public void testConstructor2() {
AtomicReference ai = new AtomicReference();
assertNull(ai.get());
} |
default constructed initializes to null
| AtomicReferenceTest::testConstructor2 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | Apache-2.0 |
public void testGetSet() {
AtomicReference ai = new AtomicReference(one);
assertSame(one, ai.get());
ai.set(two);
assertSame(two, ai.get());
ai.set(m3);
assertSame(m3, ai.get());
} |
get returns the last value set
| AtomicReferenceTest::testGetSet | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | Apache-2.0 |
public void testGetLazySet() {
AtomicReference ai = new AtomicReference(one);
assertSame(one, ai.get());
ai.lazySet(two);
assertSame(two, ai.get());
ai.lazySet(m3);
assertSame(m3, ai.get());
} |
get returns the last value lazySet in same thread
| AtomicReferenceTest::testGetLazySet | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | Apache-2.0 |
public void testGetAndSet() {
AtomicReference ai = new AtomicReference(one);
assertSame(one, ai.getAndSet(zero));
assertSame(zero, ai.getAndSet(m10));
assertSame(m10, ai.getAndSet(one));
} |
getAndSet returns previous value and sets to given value
| AtomicReferenceTest::testGetAndSet | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | Apache-2.0 |
public void testSerialization() throws Exception {
AtomicReference x = new AtomicReference();
AtomicReference y = serialClone(x);
assertNotSame(x, y);
x.set(one);
AtomicReference z = serialClone(x);
assertNotSame(y, z);
assertEquals(one, x.get());
assertEquals(null, y.get());
assertEquals(one, z.get());
} |
a deserialized serialized atomic holds same value
| AtomicReferenceTest::testSerialization | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceTest.java | Apache-2.0 |
public void testConstructor1() {
assertEquals(SIZE, new ArrayBlockingQueue(SIZE).remainingCapacity());
} |
A new queue has the indicated capacity
| ArrayBlockingQueueTest::testConstructor1 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ArrayBlockingQueueTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ArrayBlockingQueueTest.java | Apache-2.0 |
public void testConstructor6() {
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE; ++i)
ints[i] = i;
Collection<Integer> elements = Arrays.asList(ints);
try {
new ArrayBlockingQueue(SIZE - 1, false, elements);
shouldThrow();
} catch (IllegalArgumentException success) {}
} |
Initializing from too large collection throws IAE
| ArrayBlockingQueueTest::testConstructor6 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ArrayBlockingQueueTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ArrayBlockingQueueTest.java | Apache-2.0 |
public void testAddAll4() {
ArrayBlockingQueue q = new ArrayBlockingQueue(1);
Integer[] ints = new Integer[SIZE];
for (int i = 0; i < SIZE; ++i)
ints[i] = new Integer(i);
try {
q.addAll(Arrays.asList(ints));
shouldThrow();
} catch (IllegalStateException success) {}
} |
addAll throws ISE if not enough room
| ArrayBlockingQueueTest::testAddAll4 | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ArrayBlockingQueueTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ArrayBlockingQueueTest.java | Apache-2.0 |
void waitForQueuedThread(PublicSemaphore s, Thread t) {
long startTime = System.nanoTime();
while (!s.hasQueuedThread(t)) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
throw new AssertionFailedError("timed out");
Thread.yield();
}
assertTrue(s.hasQueuedThreads());
assertTrue(t.isAlive());
} |
Spin-waits until s.hasQueuedThread(t) becomes true.
| InterruptedLockRunnable::waitForQueuedThread | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
void waitForQueuedThreads(Semaphore s) {
long startTime = System.nanoTime();
while (!s.hasQueuedThreads()) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
throw new AssertionFailedError("timed out");
Thread.yield();
}
} |
Spin-waits until s.hasQueuedThreads() becomes true.
| InterruptedLockRunnable::waitForQueuedThreads | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
void acquire(Semaphore s) throws InterruptedException {
acquire(s, 1);
} |
Spin-waits until s.hasQueuedThreads() becomes true.
void waitForQueuedThreads(Semaphore s) {
long startTime = System.nanoTime();
while (!s.hasQueuedThreads()) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
throw new AssertionFailedError("timed out");
Thread.yield();
}
}
enum AcquireMethod {
acquire() {
void acquire(Semaphore s) throws InterruptedException {
s.acquire();
}
},
acquireN() {
void acquire(Semaphore s, int permits) throws InterruptedException {
s.acquire(permits);
}
},
acquireUninterruptibly() {
void acquire(Semaphore s) {
s.acquireUninterruptibly();
}
},
acquireUninterruptiblyN() {
void acquire(Semaphore s, int permits) {
s.acquireUninterruptibly(permits);
}
},
tryAcquire() {
void acquire(Semaphore s) {
assertTrue(s.tryAcquire());
}
},
tryAcquireN() {
void acquire(Semaphore s, int permits) {
assertTrue(s.tryAcquire(permits));
}
},
tryAcquireTimed() {
void acquire(Semaphore s) throws InterruptedException {
assertTrue(s.tryAcquire(2 * LONG_DELAY_MS, MILLISECONDS));
}
},
tryAcquireTimedN {
void acquire(Semaphore s, int permits) throws InterruptedException {
assertTrue(s.tryAcquire(permits, 2 * LONG_DELAY_MS, MILLISECONDS));
}
};
// Intentionally meta-circular
/** Acquires 1 permit. | AcquireMethod::acquire | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
void acquire(Semaphore s, int permits) throws InterruptedException {
for (int i = 0; i < permits; i++)
acquire(s);
} |
Spin-waits until s.hasQueuedThreads() becomes true.
void waitForQueuedThreads(Semaphore s) {
long startTime = System.nanoTime();
while (!s.hasQueuedThreads()) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
throw new AssertionFailedError("timed out");
Thread.yield();
}
}
enum AcquireMethod {
acquire() {
void acquire(Semaphore s) throws InterruptedException {
s.acquire();
}
},
acquireN() {
void acquire(Semaphore s, int permits) throws InterruptedException {
s.acquire(permits);
}
},
acquireUninterruptibly() {
void acquire(Semaphore s) {
s.acquireUninterruptibly();
}
},
acquireUninterruptiblyN() {
void acquire(Semaphore s, int permits) {
s.acquireUninterruptibly(permits);
}
},
tryAcquire() {
void acquire(Semaphore s) {
assertTrue(s.tryAcquire());
}
},
tryAcquireN() {
void acquire(Semaphore s, int permits) {
assertTrue(s.tryAcquire(permits));
}
},
tryAcquireTimed() {
void acquire(Semaphore s) throws InterruptedException {
assertTrue(s.tryAcquire(2 * LONG_DELAY_MS, MILLISECONDS));
}
},
tryAcquireTimedN {
void acquire(Semaphore s, int permits) throws InterruptedException {
assertTrue(s.tryAcquire(permits, 2 * LONG_DELAY_MS, MILLISECONDS));
}
};
// Intentionally meta-circular
/** Acquires 1 permit.
void acquire(Semaphore s) throws InterruptedException {
acquire(s, 1);
}
/** Acquires the given number of permits. | AcquireMethod::acquire | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testConstructor() { testConstructor(false); } |
Zero, negative, and positive initial values are allowed in constructor
| SemaphoreTest::testConstructor | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testConstructorDefaultsToNonFair() {
for (int permits : new int[] { -42, -1, 0, 1, 42 }) {
Semaphore s = new Semaphore(permits);
assertEquals(permits, s.availablePermits());
assertFalse(s.isFair());
}
} |
Constructor without fairness argument behaves as nonfair
| SemaphoreTest::testConstructorDefaultsToNonFair | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testTryAcquireInSameThread() { testTryAcquireInSameThread(false); } |
tryAcquire succeeds when sufficient permits, else fails
| SemaphoreTest::testTryAcquireInSameThread | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testTryAcquire_timeout() { testTryAcquire_timeout(false); } |
timed tryAcquire times out
| SemaphoreTest::testTryAcquire_timeout | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testTryAcquireN_timeout() { testTryAcquireN_timeout(false); } |
timed tryAcquire(N) times out
| SemaphoreTest::testTryAcquireN_timeout | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testInterruptible_acquire() { testInterruptible(false, AcquireMethod.acquire); } |
acquire(), acquire(N), timed tryAcquired, timed tryAcquire(N)
are interruptible
| SemaphoreTest::testInterruptible_acquire | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testUninterruptible_acquireUninterruptibly() { testUninterruptible(false, AcquireMethod.acquireUninterruptibly); } |
acquireUninterruptibly(), acquireUninterruptibly(N) are
uninterruptible
| SemaphoreTest::testUninterruptible_acquireUninterruptibly | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testDrainPermits() { testDrainPermits(false); } |
drainPermits reports and removes given number of permits
| SemaphoreTest::testDrainPermits | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testReleaseIAE() { testReleaseIAE(false); } |
release(-N) throws IllegalArgumentException
| SemaphoreTest::testReleaseIAE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testReducePermitsIAE() { testReducePermitsIAE(false); } |
reducePermits(-N) throws IllegalArgumentException
| SemaphoreTest::testReducePermitsIAE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testReducePermits() { testReducePermits(false); } |
reducePermits reduces number of permits
| SemaphoreTest::testReducePermits | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testTryAcquireNInSameThread() { testTryAcquireNInSameThread(false); } |
tryAcquire(n) succeeds when sufficient permits, else fails
| SemaphoreTest::testTryAcquireNInSameThread | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testReleaseAcquireSameThread_acquire() { testReleaseAcquireSameThread(false, AcquireMethod.acquire); } |
acquire succeeds if permits available
| SemaphoreTest::testReleaseAcquireSameThread_acquire | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testReleaseAcquireDifferentThreads_acquire() { testReleaseAcquireDifferentThreads(false, AcquireMethod.acquire); } |
release in one thread enables acquire in another thread
| SemaphoreTest::testReleaseAcquireDifferentThreads_acquire | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
public void testFairLocksFifo() {
final PublicSemaphore s = new PublicSemaphore(1, true);
final CountDownLatch pleaseRelease = new CountDownLatch(1);
Thread t1 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
// Will block; permits are available, but not three
s.acquire(3);
}});
waitForQueuedThread(s, t1);
Thread t2 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
// Will fail, even though 1 permit is available
assertFalse(s.tryAcquire(0L, MILLISECONDS));
assertFalse(s.tryAcquire(1, 0L, MILLISECONDS));
// untimed tryAcquire will barge and succeed
assertTrue(s.tryAcquire());
s.release(2);
assertTrue(s.tryAcquire(2));
s.release();
pleaseRelease.countDown();
// Will queue up behind t1, even though 1 permit is available
s.acquire();
}});
await(pleaseRelease);
waitForQueuedThread(s, t2);
s.release(2);
awaitTermination(t1);
assertTrue(t2.isAlive());
s.release();
awaitTermination(t2);
} |
fair locks are strictly FIFO
| SemaphoreTest::testFairLocksFifo | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SemaphoreTest.java | Apache-2.0 |
void assertNotWriteLocked(PublicReentrantReadWriteLock lock) {
assertFalse(lock.isWriteLocked());
assertFalse(lock.isWriteLockedByCurrentThread());
assertFalse(lock.writeLock().isHeldByCurrentThread());
assertEquals(0, lock.getWriteHoldCount());
assertEquals(0, lock.writeLock().getHoldCount());
assertNull(lock.getOwner());
} |
Checks that lock is not write-locked.
| PublicReentrantReadWriteLock::assertNotWriteLocked | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
void assertWriteLockedBy(PublicReentrantReadWriteLock lock, Thread t) {
assertTrue(lock.isWriteLocked());
assertSame(t, lock.getOwner());
assertEquals(t == Thread.currentThread(),
lock.isWriteLockedByCurrentThread());
assertEquals(t == Thread.currentThread(),
lock.writeLock().isHeldByCurrentThread());
assertEquals(t == Thread.currentThread(),
lock.getWriteHoldCount() > 0);
assertEquals(t == Thread.currentThread(),
lock.writeLock().getHoldCount() > 0);
assertEquals(0, lock.getReadLockCount());
} |
Checks that lock is write-locked by the given thread.
| PublicReentrantReadWriteLock::assertWriteLockedBy | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
void assertWriteLockedByMoi(PublicReentrantReadWriteLock lock) {
assertWriteLockedBy(lock, Thread.currentThread());
} |
Checks that lock is write-locked by the current thread.
| PublicReentrantReadWriteLock::assertWriteLockedByMoi | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testGetWriteHoldCount() { testGetWriteHoldCount(false); } |
getWriteHoldCount returns number of recursive holds
| AwaitMethod::testGetWriteHoldCount | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testGetReadHoldCount() { testGetReadHoldCount(false); } |
getReadHoldCount returns number of recursive holds
| AwaitMethod::testGetReadHoldCount | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testWriteUnlock_IMSE() { testWriteUnlock_IMSE(false); } |
write-unlocking an unlocked lock throws IllegalMonitorStateException
| AwaitMethod::testWriteUnlock_IMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testReadUnlock_IMSE() { testReadUnlock_IMSE(false); } |
read-unlocking an unlocked lock throws IllegalMonitorStateException
| AwaitMethod::testReadUnlock_IMSE | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testWriteLockInterruptibly_Interruptible() { testWriteLockInterruptibly_Interruptible(false); } |
write-lockInterruptibly is interruptible
| AwaitMethod::testWriteLockInterruptibly_Interruptible | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testWriteTryLock_Interruptible() { testWriteTryLock_Interruptible(false); } |
timed write-tryLock is interruptible
| AwaitMethod::testWriteTryLock_Interruptible | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testReadLockInterruptibly_Interruptible() { testReadLockInterruptibly_Interruptible(false); } |
read-lockInterruptibly is interruptible
| AwaitMethod::testReadLockInterruptibly_Interruptible | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testReadTryLock_Interruptible() { testReadTryLock_Interruptible(false); } |
timed read-tryLock is interruptible
| AwaitMethod::testReadTryLock_Interruptible | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testWriteTryLock() { testWriteTryLock(false); } |
write-tryLock on an unlocked lock succeeds
| AwaitMethod::testWriteTryLock | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testWriteTryLockWhenLocked() { testWriteTryLockWhenLocked(false); } |
write-tryLock fails if locked
| AwaitMethod::testWriteTryLockWhenLocked | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testReadTryLockWhenLocked() { testReadTryLockWhenLocked(false); } |
read-tryLock fails if locked
| AwaitMethod::testReadTryLockWhenLocked | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
public void testMultipleReadLocks() { testMultipleReadLocks(false); } |
Multiple threads can hold a read lock when not write-locked
| AwaitMethod::testMultipleReadLocks | java | google/j2objc | jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ReentrantReadWriteLockTest.java | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.