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 testWriteAfterReadLock() { testWriteAfterReadLock(false); }
A writelock succeeds only after a reading thread unlocks
AwaitMethod::testWriteAfterReadLock
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 testWriteAfterMultipleReadLocks() { testWriteAfterMultipleReadLocks(false); }
A writelock succeeds only after reading threads unlock
AwaitMethod::testWriteAfterMultipleReadLocks
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 testReaderWriterReaderFairFifo() { final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock(true); final AtomicBoolean t1GotLock = new AtomicBoolean(false); lock.readLock().lock(); Thread t1 = newStartedThread(new CheckedRunnable() { public void realRun() { assertEquals(1, lock.getReadLockCount()); lock.writeLock().lock(); assertEquals(0, lock.getReadLockCount()); t1GotLock.set(true); lock.writeLock().unlock(); }}); waitForQueuedThread(lock, t1); Thread t2 = newStartedThread(new CheckedRunnable() { public void realRun() { assertEquals(1, lock.getReadLockCount()); lock.readLock().lock(); assertEquals(1, lock.getReadLockCount()); assertTrue(t1GotLock.get()); lock.readLock().unlock(); }}); waitForQueuedThread(lock, t2); assertTrue(t1.isAlive()); assertNotWriteLocked(lock); assertEquals(1, lock.getReadLockCount()); lock.readLock().unlock(); awaitTermination(t1); awaitTermination(t2); assertNotWriteLocked(lock); }
A thread that tries to acquire a fair read lock (non-reentrantly) will block if there is a waiting writer thread
AwaitMethod::testReaderWriterReaderFairFifo
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 testReadAfterWriteLock() { testReadAfterWriteLock(false); }
Readlocks succeed only after a writing thread unlocks
AwaitMethod::testReadAfterWriteLock
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 testReadHoldingWriteLock() { testReadHoldingWriteLock(false); }
Read trylock succeeds if write locked by current thread
AwaitMethod::testReadHoldingWriteLock
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 testReadTryLockBarging() { testReadTryLockBarging(false); }
Read trylock succeeds (barging) even in the presence of waiting readers and/or writers
AwaitMethod::testReadTryLockBarging
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 testReadHoldingWriteLock2() { testReadHoldingWriteLock2(false); }
Read lock succeeds if write locked by current thread even if other threads are waiting for readlock
AwaitMethod::testReadHoldingWriteLock2
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 testReadHoldingWriteLock3() { testReadHoldingWriteLock3(false); }
Read lock succeeds if write locked by current thread even if other threads are waiting for writelock
AwaitMethod::testReadHoldingWriteLock3
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 testWriteHoldingWriteLock4() { testWriteHoldingWriteLock4(false); }
Write lock succeeds if write locked by current thread even if other threads are waiting for writelock
AwaitMethod::testWriteHoldingWriteLock4
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 testTryLockWhenReadLocked() { testTryLockWhenReadLocked(false); }
Read tryLock succeeds if readlocked but not writelocked
AwaitMethod::testTryLockWhenReadLocked
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 testWriteTryLockWhenReadLocked() { testWriteTryLockWhenReadLocked(false); }
write tryLock fails when readlocked
AwaitMethod::testWriteTryLockWhenReadLocked
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_Timeout() { testWriteTryLock_Timeout(false); }
write timed tryLock times out if locked
AwaitMethod::testWriteTryLock_Timeout
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_Timeout() { testReadTryLock_Timeout(false); }
read timed tryLock times out if write-locked
AwaitMethod::testReadTryLock_Timeout
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() { testWriteLockInterruptibly(false); }
write lockInterruptibly succeeds if unlocked, else is interruptible
AwaitMethod::testWriteLockInterruptibly
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() { testReadLockInterruptibly(false); }
read lockInterruptibly succeeds if lock free else is interruptible
AwaitMethod::testReadLockInterruptibly
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 testSignalAll_IMSE() { testSignalAll_IMSE(false); }
Calling signalAll without holding lock throws IllegalMonitorStateException
AwaitMethod::testSignalAll_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 testReadLockToString() { testReadLockToString(false); }
readLock.toString indicates current lock state
AwaitMethod::testReadLockToString
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 testWriteLockToString() { testWriteLockToString(false); }
writeLock.toString indicates current lock state
AwaitMethod::testWriteLockToString
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 testEmptyFull() { testEmptyFull(false); }
Any SynchronousQueue is both empty and full
SynchronousQueueTest::testEmptyFull
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testOffer() { testOffer(false); }
offer fails if no active taker
SynchronousQueueTest::testOffer
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testAdd() { testAdd(false); }
add throws IllegalStateException if no active taker
SynchronousQueueTest::testAdd
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testAddAll_ISE() { testAddAll_ISE(false); }
addAll throws ISE if no active taker
SynchronousQueueTest::testAddAll_ISE
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testBlockingPut() { testBlockingPut(false); }
put blocks interruptibly if no active taker
SynchronousQueueTest::testBlockingPut
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testPutWithTake() { testPutWithTake(false); }
put blocks interruptibly waiting for take
SynchronousQueueTest::testPutWithTake
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testTimedOffer() { testTimedOffer(false); }
timed offer times out if elements not taken
SynchronousQueueTest::testTimedOffer
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testPoll() { testPoll(false); }
poll return null if no active putter
SynchronousQueueTest::testPoll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testTimedPoll0() { testTimedPoll0(false); }
timed poll with zero timeout times out if no active putter
SynchronousQueueTest::testTimedPoll0
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testTimedPoll() { testTimedPoll(false); }
timed poll with nonzero timeout times out if no active putter
SynchronousQueueTest::testTimedPoll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testTimedPollWithOffer() { testTimedPollWithOffer(false); }
timed poll before a delayed offer times out, returning null; after offer succeeds; on interruption throws
SynchronousQueueTest::testTimedPollWithOffer
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testPeek() { testPeek(false); }
peek() returns null if no active putter
SynchronousQueueTest::testPeek
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testElement() { testElement(false); }
element() throws NoSuchElementException if no active putter
SynchronousQueueTest::testElement
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testRemove() { testRemove(false); }
remove() throws NoSuchElementException if no active putter
SynchronousQueueTest::testRemove
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testContains() { testContains(false); }
contains returns false
SynchronousQueueTest::testContains
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testClear() { testClear(false); }
clear ensures isEmpty
SynchronousQueueTest::testClear
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testContainsAll() { testContainsAll(false); }
containsAll returns false unless empty
SynchronousQueueTest::testContainsAll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testRetainAll() { testRetainAll(false); }
retainAll returns false
SynchronousQueueTest::testRetainAll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testRemoveAll() { testRemoveAll(false); }
removeAll returns false
SynchronousQueueTest::testRemoveAll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testToArray() { testToArray(false); }
toArray is empty
SynchronousQueueTest::testToArray
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testToArray2() { testToArray2(false); }
toArray(Integer array) returns its argument with the first element (if present) nulled out
SynchronousQueueTest::testToArray2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testToArray_null() { testToArray_null(false); }
toArray(null) throws NPE
SynchronousQueueTest::testToArray_null
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testIterator() { testIterator(false); }
iterator does not traverse any elements
SynchronousQueueTest::testIterator
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testIteratorRemove() { testIteratorRemove(false); }
iterator remove throws ISE
SynchronousQueueTest::testIteratorRemove
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testSerialization() { final SynchronousQueue x = new SynchronousQueue(); final SynchronousQueue y = new SynchronousQueue(false); final SynchronousQueue z = new SynchronousQueue(true); assertSerialEquals(x, y); assertNotSerialEquals(x, z); SynchronousQueue[] qs = { x, y, z }; for (SynchronousQueue q : qs) { SynchronousQueue clone = serialClone(q); assertNotSame(q, clone); assertSerialEquals(q, clone); assertTrue(clone.isEmpty()); assertEquals(0, clone.size()); assertEquals(0, clone.remainingCapacity()); assertFalse(clone.offer(zero)); } }
a deserialized serialized queue is usable
SynchronousQueueTest::testSerialization
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testDrainTo() { testDrainTo(false); }
drainTo(c) of empty queue doesn't transfer elements
SynchronousQueueTest::testDrainTo
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testDrainToWithActivePut() { testDrainToWithActivePut(false); }
drainTo empties queue, unblocking a waiting put.
SynchronousQueueTest::testDrainToWithActivePut
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testDrainToN() throws InterruptedException { final SynchronousQueue q = new SynchronousQueue(); Thread t1 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.put(one); }}); Thread t2 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.put(two); }}); ArrayList l = new ArrayList(); int drained; while ((drained = q.drainTo(l, 1)) == 0) Thread.yield(); assertEquals(1, drained); assertEquals(1, l.size()); while ((drained = q.drainTo(l, 1)) == 0) Thread.yield(); assertEquals(1, drained); assertEquals(2, l.size()); assertTrue(l.contains(one)); assertTrue(l.contains(two)); awaitTermination(t1); awaitTermination(t2); }
drainTo(c, n) empties up to n elements of queue into c
SynchronousQueueTest::testDrainToN
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SynchronousQueueTest.java
Apache-2.0
public void testComplete() { for (Object x : new Object[] { Boolean.TRUE, null }) { for (int pendingCount : new int[] { 0, 42 }) { testComplete(new NoopCC(), x, pendingCount); testComplete(new NoopCC(new NoopCC()), x, pendingCount); } } }
A newly constructed CountedCompleter is not completed; complete() causes completion. pendingCount is ignored.
NoopCC::testComplete
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CountedCompleterTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CountedCompleterTest.java
Apache-2.0
public void testCompleteExceptionally() { new NoopCC() .checkCompletesExceptionally(new FJException()); new NoopCC(new NoopCC()) .checkCompletesExceptionally(new FJException()); }
completeExceptionally completes exceptionally
NoopCC::testCompleteExceptionally
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CountedCompleterTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/CountedCompleterTest.java
Apache-2.0
private NavigableSet dset5() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); q.add(m1); q.add(m2); q.add(m3); q.add(m4); q.add(m5); NavigableSet s = q.descendingSet(); assertEquals(5, s.size()); return s; }
Returns a new set of first 5 negative ints.
MyReverseComparator::dset5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentSkipListSubSetTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentSkipListSubSetTest.java
Apache-2.0
static int compare(int x, int y) { return (x < y) ? -1 : (x > y) ? 1 : 0; }
Returns a new map from Integers 1-5 to Strings "A"-"E". private static ConcurrentHashMap<Integer, String> map5() { ConcurrentHashMap map = new ConcurrentHashMap<Integer, String>(5); assertTrue(map.isEmpty()); map.put(one, "A"); map.put(two, "B"); map.put(three, "C"); map.put(four, "D"); map.put(five, "E"); assertFalse(map.isEmpty()); assertEquals(5, map.size()); return map; } /** Re-implement Integer.compare for old java versions
ConcurrentHashMapTest::compare
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testComparableFamily() { int size = 500; // makes measured test run time -> 60ms ConcurrentHashMap<BI, Boolean> m = new ConcurrentHashMap<BI, Boolean>(); for (int i = 0; i < size; i++) { assertTrue(m.put(new CI(i), true) == null); } for (int i = 0; i < size; i++) { assertTrue(m.containsKey(new CI(i))); assertTrue(m.containsKey(new DI(i))); } }
Inserted elements that are subclasses of the same Comparable class are found.
ComparableCollidingObject::testComparableFamily
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testGenericComparable() { int size = 120; // makes measured test run time -> 60ms ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<Object, Boolean>(); for (int i = 0; i < size; i++) { BI bi = new BI(i); BS bs = new BS(String.valueOf(i)); LexicographicList<BI> bis = new LexicographicList<BI>(bi); LexicographicList<BS> bss = new LexicographicList<BS>(bs); assertTrue(m.putIfAbsent(bis, true) == null); assertTrue(m.containsKey(bis)); if (m.putIfAbsent(bss, true) == null) assertTrue(m.containsKey(bss)); assertTrue(m.containsKey(bis)); } for (int i = 0; i < size; i++) { assertTrue(m.containsKey(Collections.singletonList(new BI(i)))); } }
Elements of classes with erased generic type parameters based on Comparable can be inserted and found.
ComparableCollidingObject::testGenericComparable
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testGenericComparable2() { int size = 500; // makes measured test run time -> 60ms ConcurrentHashMap<Object, Boolean> m = new ConcurrentHashMap<Object, Boolean>(); for (int i = 0; i < size; i++) { m.put(Collections.singletonList(new BI(i)), true); } for (@AutoreleasePool int i = 0; i < size; i++) { LexicographicList<BI> bis = new LexicographicList<BI>(new BI(i)); assertTrue(m.containsKey(bis)); } }
Elements of non-comparable classes equal to those of classes with erased generic type parameters based on Comparable can be inserted and found.
ComparableCollidingObject::testGenericComparable2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testMixedComparable() { int size = 1200; // makes measured test run time -> 35ms ConcurrentHashMap<Object, Object> map = new ConcurrentHashMap<Object, Object>(); Random rng = new Random(); for (int i = 0; i < size; i++) { Object x; switch (rng.nextInt(4)) { case 0: x = new Object(); break; case 1: x = new CollidingObject(Integer.toString(i)); break; default: x = new ComparableCollidingObject(Integer.toString(i)); } assertNull(map.put(x, x)); } int count = 0; for (Object k : map.keySet()) { assertEquals(map.get(k), k); ++count; } assertEquals(count, size); assertEquals(map.size(), size); for (Object k : map.keySet()) { assertEquals(map.put(k, k), k); } }
Mixtures of instances of comparable and non-comparable classes can be inserted and found.
ComparableCollidingObject::testMixedComparable
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testHashCode() { ConcurrentHashMap<Integer,String> map = map5(); int sum = 0; for (Map.Entry<Integer,String> e : map.entrySet()) sum += e.getKey().hashCode() ^ e.getValue().hashCode(); assertEquals(sum, map.hashCode()); }
hashCode() equals sum of each key.hashCode ^ value.hashCode
ComparableCollidingObject::testHashCode
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testContains() { ConcurrentHashMap map = map5(); assertTrue(map.contains("A")); assertFalse(map.contains("Z")); }
contains returns true for contained value
ComparableCollidingObject::testContains
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testEnumeration() { ConcurrentHashMap map = map5(); Enumeration e = map.elements(); int count = 0; while (e.hasMoreElements()) { count++; e.nextElement(); } assertEquals(5, count); }
enumeration returns an enumeration containing the correct elements
ComparableCollidingObject::testEnumeration
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testKeys() { ConcurrentHashMap map = map5(); Enumeration e = map.keys(); int count = 0; while (e.hasMoreElements()) { count++; e.nextElement(); } assertEquals(5, count); }
keys returns an enumeration containing all the keys from the map
ComparableCollidingObject::testKeys
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testConstructor1() { try { new ConcurrentHashMap(-1); shouldThrow(); } catch (IllegalArgumentException success) {} }
Cannot create with only negative capacity
ComparableCollidingObject::testConstructor1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testConstructor2() { try { new ConcurrentHashMap(-1, .75f); shouldThrow(); } catch (IllegalArgumentException success) {} try { new ConcurrentHashMap(16, -1); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor (initialCapacity, loadFactor) throws IllegalArgumentException if either argument is negative
ComparableCollidingObject::testConstructor2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testConstructor3() { try { new ConcurrentHashMap(-1, .75f, 1); shouldThrow(); } catch (IllegalArgumentException success) {} try { new ConcurrentHashMap(16, -1, 1); shouldThrow(); } catch (IllegalArgumentException success) {} try { new ConcurrentHashMap(16, .75f, -1); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor (initialCapacity, loadFactor, concurrencyLevel) throws IllegalArgumentException if any argument is negative
ComparableCollidingObject::testConstructor3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testConstructor4() { try { new ConcurrentHashMap(null); shouldThrow(); } catch (NullPointerException success) {} }
ConcurrentHashMap(map) throws NullPointerException if the given map is null
ComparableCollidingObject::testConstructor4
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testConstructor5() { ConcurrentHashMap map1 = map5(); ConcurrentHashMap map2 = new ConcurrentHashMap(map5()); assertTrue(map2.equals(map1)); map2.put(one, "F"); assertFalse(map2.equals(map1)); }
ConcurrentHashMap(map) creates a new map with the same mappings as the given map
ComparableCollidingObject::testConstructor5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testGet_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.get(null); shouldThrow(); } catch (NullPointerException success) {} }
get(null) throws NPE
ComparableCollidingObject::testGet_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testContainsKey_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.containsKey(null); shouldThrow(); } catch (NullPointerException success) {} }
containsKey(null) throws NPE
ComparableCollidingObject::testContainsKey_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testContains_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.contains(null); shouldThrow(); } catch (NullPointerException success) {} }
contains(null) throws NPE
ComparableCollidingObject::testContains_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testPut2_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.put("whatever", null); shouldThrow(); } catch (NullPointerException success) {} }
put(x, null) throws NPE
ComparableCollidingObject::testPut2_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testPutIfAbsent2_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.putIfAbsent("whatever", null); shouldThrow(); } catch (NullPointerException success) {} }
putIfAbsent(x, null) throws NPE
ComparableCollidingObject::testPutIfAbsent2_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testReplace2_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.replace("whatever", null); shouldThrow(); } catch (NullPointerException success) {} }
replace(x, null) throws NPE
ComparableCollidingObject::testReplace2_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testReplaceValue2_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.replace("whatever", null, "A"); shouldThrow(); } catch (NullPointerException success) {} }
replace(x, null, y) throws NPE
ComparableCollidingObject::testReplaceValue2_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testReplaceValue3_NullPointerException() { ConcurrentHashMap c = new ConcurrentHashMap(5); try { c.replace("whatever", one, null); shouldThrow(); } catch (NullPointerException success) {} }
replace(x, y, null) throws NPE
ComparableCollidingObject::testReplaceValue3_NullPointerException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testRemove3() { ConcurrentHashMap c = new ConcurrentHashMap(5); c.put("sadsdf", "asdads"); assertFalse(c.remove("sadsdf", null)); }
remove(x, null) returns false
ComparableCollidingObject::testRemove3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testSetValueWriteThrough() { // Adapted from a bug report by Eric Zoerner ConcurrentHashMap map = new ConcurrentHashMap(2, 5.0f, 1); assertTrue(map.isEmpty()); for (int i = 0; i < 20; i++) map.put(new Integer(i), new Integer(i)); assertFalse(map.isEmpty()); Map.Entry entry1 = (Map.Entry)map.entrySet().iterator().next(); // Unless it happens to be first (in which case remainder of // test is skipped), remove a possibly-colliding key from map // which, under some implementations, may cause entry1 to be // cloned in map if (!entry1.getKey().equals(new Integer(16))) { map.remove(new Integer(16)); entry1.setValue("XYZ"); assertTrue(map.containsValue("XYZ")); // fails if write-through broken } }
SetValue of an EntrySet entry sets value in the map.
ComparableCollidingObject::testSetValueWriteThrough
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentHashMapTest.java
Apache-2.0
public void testConstructor() { AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(SIZE); for (int i = 0; i < SIZE; i++) { assertNull(aa.get(i)); } }
constructor creates array of given size with all elements null
AtomicReferenceArrayTest::testConstructor
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceArrayTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceArrayTest.java
Apache-2.0
public void testConstructorSubClassArray() { Integer[] a = { two, one, three, four, seven }; AtomicReferenceArray<Number> aa = new AtomicReferenceArray<Number>(a); assertEquals(a.length, aa.length()); for (int i = 0; i < a.length; i++) { assertSame(a[i], aa.get(i)); Long x = Long.valueOf(i); aa.set(i, x); assertSame(x, aa.get(i)); } }
Initialize AtomicReferenceArray<Class> with SubClass[]
AtomicReferenceArrayTest::testConstructorSubClassArray
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceArrayTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/AtomicReferenceArrayTest.java
Apache-2.0
public void testForkTimedGetNullTimeUnit() { testForkTimedGetNullTimeUnit(mainPool()); }
timed get with null time unit throws NullPointerException
FailingAsyncFib::testForkTimedGetNullTimeUnit
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinTask8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinTask8Test.java
Apache-2.0
public void testInvokeAllNullTask() { testInvokeAllNullTask(mainPool()); }
invokeAll(tasks) with any null task throws NullPointerException
FailingAsyncFib::testInvokeAllNullTask
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinTask8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinTask8Test.java
Apache-2.0
public void testExchange() { final Exchanger e = new Exchanger(); Thread t1 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertSame(one, e.exchange(two)); assertSame(two, e.exchange(one)); }}); Thread t2 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertSame(two, e.exchange(one)); assertSame(one, e.exchange(two)); }}); awaitTermination(t1); awaitTermination(t2); }
exchange exchanges objects across two threads
ExchangerTest::testExchange
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
Apache-2.0
public void testTimedExchange() { final Exchanger e = new Exchanger(); Thread t1 = newStartedThread(new CheckedRunnable() { public void realRun() throws Exception { assertSame(one, e.exchange(two, LONG_DELAY_MS, MILLISECONDS)); assertSame(two, e.exchange(one, LONG_DELAY_MS, MILLISECONDS)); }}); Thread t2 = newStartedThread(new CheckedRunnable() { public void realRun() throws Exception { assertSame(two, e.exchange(one, LONG_DELAY_MS, MILLISECONDS)); assertSame(one, e.exchange(two, LONG_DELAY_MS, MILLISECONDS)); }}); awaitTermination(t1); awaitTermination(t2); }
timed exchange exchanges objects across two threads
ExchangerTest::testTimedExchange
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
Apache-2.0
public void testExchange_InterruptedException() { final Exchanger e = new Exchanger(); final CountDownLatch threadStarted = new CountDownLatch(1); Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); e.exchange(one); }}); await(threadStarted); t.interrupt(); awaitTermination(t); }
interrupt during wait for exchange throws IE
ExchangerTest::testExchange_InterruptedException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
Apache-2.0
public void testTimedExchange_InterruptedException() { final Exchanger e = new Exchanger(); final CountDownLatch threadStarted = new CountDownLatch(1); Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws Exception { threadStarted.countDown(); e.exchange(null, LONG_DELAY_MS, MILLISECONDS); }}); await(threadStarted); t.interrupt(); awaitTermination(t); }
interrupt during wait for timed exchange throws IE
ExchangerTest::testTimedExchange_InterruptedException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
Apache-2.0
public void testExchange_TimeoutException() { final Exchanger e = new Exchanger(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws Exception { long startTime = System.nanoTime(); try { e.exchange(null, timeoutMillis(), MILLISECONDS); shouldThrow(); } catch (TimeoutException success) {} assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); }}); awaitTermination(t); }
timeout during wait for timed exchange throws TimeoutException
ExchangerTest::testExchange_TimeoutException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
Apache-2.0
public void testReplacementAfterExchange() { final Exchanger e = new Exchanger(); final CountDownLatch exchanged = new CountDownLatch(2); final CountDownLatch interrupted = new CountDownLatch(1); Thread t1 = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { assertSame(two, e.exchange(one)); exchanged.countDown(); e.exchange(two); }}); Thread t2 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertSame(one, e.exchange(two)); exchanged.countDown(); interrupted.await(); assertSame(three, e.exchange(one)); }}); Thread t3 = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { interrupted.await(); assertSame(one, e.exchange(three)); }}); await(exchanged); t1.interrupt(); awaitTermination(t1); interrupted.countDown(); awaitTermination(t2); awaitTermination(t3); }
If one exchanging thread is interrupted, another succeeds.
ExchangerTest::testReplacementAfterExchange
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ExchangerTest.java
Apache-2.0
public void testConstructor1() { Map.Entry e = new AbstractMap.SimpleEntry(k1, v1); assertEquals(k1, e.getKey()); assertEquals(v1, e.getValue()); }
A new SimpleEntry(k, v) holds k, v.
EntryTest::testConstructor1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testConstructor2() { Map.Entry s = new AbstractMap.SimpleImmutableEntry(k1, v1); assertEquals(k1, s.getKey()); assertEquals(v1, s.getValue()); }
A new SimpleImmutableEntry(k, v) holds k, v.
EntryTest::testConstructor2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testConstructor3() { Map.Entry e2 = new AbstractMap.SimpleEntry(k1, v1); Map.Entry e = new AbstractMap.SimpleEntry(e2); assertEquals(k1, e.getKey()); assertEquals(v1, e.getValue()); }
A new SimpleEntry(entry(k, v)) holds k, v.
EntryTest::testConstructor3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testConstructor4() { Map.Entry s2 = new AbstractMap.SimpleImmutableEntry(k1, v1); Map.Entry s = new AbstractMap.SimpleImmutableEntry(s2); assertEquals(k1, s.getKey()); assertEquals(v1, s.getValue()); }
A new SimpleImmutableEntry(entry(k, v)) holds k, v.
EntryTest::testConstructor4
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testEquals() { Map.Entry e2 = new AbstractMap.SimpleEntry(k1, v1); Map.Entry e = new AbstractMap.SimpleEntry(e2); Map.Entry s2 = new AbstractMap.SimpleImmutableEntry(k1, v1); Map.Entry s = new AbstractMap.SimpleImmutableEntry(s2); assertEquals(e2, e); assertEquals(e2.hashCode(), e.hashCode()); assertEquals(s2, s); assertEquals(s2.hashCode(), s.hashCode()); assertEquals(e2, s2); assertEquals(e2.hashCode(), s2.hashCode()); assertEquals(e, s); assertEquals(e.hashCode(), s.hashCode()); }
Entries with same key-value pairs are equal and have same hashcodes
EntryTest::testEquals
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testNotEquals() { Map.Entry e2 = new AbstractMap.SimpleEntry(k1, v1); Map.Entry e = new AbstractMap.SimpleEntry(k2, v1); assertFalse(e2.equals(e)); e = new AbstractMap.SimpleEntry(k1, v2); assertFalse(e2.equals(e)); e = new AbstractMap.SimpleEntry(k2, v2); assertFalse(e2.equals(e)); Map.Entry s2 = new AbstractMap.SimpleImmutableEntry(k1, v1); Map.Entry s = new AbstractMap.SimpleImmutableEntry(k2, v1); assertFalse(s2.equals(s)); s = new AbstractMap.SimpleImmutableEntry(k1, v2); assertFalse(s2.equals(s)); s = new AbstractMap.SimpleImmutableEntry(k2, v2); assertFalse(s2.equals(s)); }
Entries with different key-value pairs are not equal
EntryTest::testNotEquals
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testSetValue1() { Map.Entry e2 = new AbstractMap.SimpleEntry(k1, v1); Map.Entry e = new AbstractMap.SimpleEntry(e2); assertEquals(k1, e.getKey()); assertEquals(v1, e.getValue()); e.setValue(k2); assertEquals(k2, e.getValue()); assertFalse(e2.equals(e)); }
getValue returns last setValue for SimpleEntry
EntryTest::testSetValue1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testSetValue2() { Map.Entry s2 = new AbstractMap.SimpleImmutableEntry(k1, v1); Map.Entry s = new AbstractMap.SimpleImmutableEntry(s2); assertEquals(k1, s.getKey()); assertEquals(v1, s.getValue()); try { s.setValue(k2); shouldThrow(); } catch (UnsupportedOperationException success) {} }
setValue for SimpleImmutableEntry throws UnsupportedOperationException
EntryTest::testSetValue2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/EntryTest.java
Apache-2.0
public void testEntryImmutability() { ConcurrentSkipListMap map = map5(); Map.Entry e = map.lowerEntry(three); assertEquals(two, e.getKey()); try { e.setValue("X"); shouldThrow(); } catch (UnsupportedOperationException success) {} e = map.higherEntry(zero); assertEquals(one, e.getKey()); try { e.setValue("X"); shouldThrow(); } catch (UnsupportedOperationException success) {} e = map.floorEntry(one); assertEquals(one, e.getKey()); try { e.setValue("X"); shouldThrow(); } catch (UnsupportedOperationException success) {} e = map.ceilingEntry(five); assertEquals(five, e.getKey()); try { e.setValue("X"); shouldThrow(); } catch (UnsupportedOperationException success) {} }
lowerEntry, higherEntry, ceilingEntry, and floorEntry return immutable entries
ConcurrentSkipListMapTest::testEntryImmutability
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentSkipListMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentSkipListMapTest.java
Apache-2.0
public void testTailMapContents() { ConcurrentSkipListMap map = map5(); NavigableMap sm = map.tailMap(two, true); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); k = (Integer)(i.next()); assertEquals(four, k); k = (Integer)(i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator r = sm.descendingKeySet().iterator(); k = (Integer)(r.next()); assertEquals(five, k); k = (Integer)(r.next()); assertEquals(four, k); k = (Integer)(r.next()); assertEquals(three, k); k = (Integer)(r.next()); assertEquals(two, k); assertFalse(r.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); NavigableMap ssm = sm.tailMap(four, true); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
tailMap returns map with keys in requested range
ConcurrentSkipListMapTest::testTailMapContents
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentSkipListMapTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentSkipListMapTest.java
Apache-2.0
public void testCommonPoolParallelism() { assertEquals(ForkJoinPool.getCommonPoolParallelism(), ForkJoinPool.commonPool().getParallelism()); }
Common pool exists and has expected parallelism.
ForkJoinPool8Test::testCommonPoolParallelism
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
Apache-2.0
public void testCommonPoolShutDown() { assertFalse(ForkJoinPool.commonPool().isShutdown()); assertFalse(ForkJoinPool.commonPool().isTerminating()); assertFalse(ForkJoinPool.commonPool().isTerminated()); ForkJoinPool.commonPool().shutdown(); assertFalse(ForkJoinPool.commonPool().isShutdown()); assertFalse(ForkJoinPool.commonPool().isTerminating()); assertFalse(ForkJoinPool.commonPool().isTerminated()); ForkJoinPool.commonPool().shutdownNow(); assertFalse(ForkJoinPool.commonPool().isShutdown()); assertFalse(ForkJoinPool.commonPool().isTerminating()); assertFalse(ForkJoinPool.commonPool().isTerminated()); }
Common pool cannot be shut down
ForkJoinPool8Test::testCommonPoolShutDown
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
Apache-2.0
public void testInvoke() { RecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { FibAction f = new FibAction(8); assertNull(f.invoke()); assertEquals(21, f.result); checkCompletedNormally(f); }}; checkInvoke(a); }
invoke returns when task completes normally. isCompletedAbnormally and isCancelled return false for normally completed tasks. getRawResult of a RecursiveAction returns null;
FailingFibAction::testInvoke
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
Apache-2.0
public void testJoinIgnoresInterrupts() { RecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() { FibAction f = new FibAction(8); final Thread myself = Thread.currentThread(); // test join() assertSame(f, f.fork()); myself.interrupt(); assertTrue(myself.isInterrupted()); assertNull(f.join()); Thread.interrupted(); assertEquals(21, f.result); checkCompletedNormally(f); f = new FibAction(8); f.cancel(true); assertSame(f, f.fork()); myself.interrupt(); assertTrue(myself.isInterrupted()); try { f.join(); shouldThrow(); } catch (CancellationException success) { Thread.interrupted(); checkCancelled(f); } f = new FibAction(8); f.completeExceptionally(new FJException()); assertSame(f, f.fork()); myself.interrupt(); assertTrue(myself.isInterrupted()); try { f.join(); shouldThrow(); } catch (FJException success) { Thread.interrupted(); checkCompletedAbnormally(f, success); } // test quietlyJoin() f = new FibAction(8); assertSame(f, f.fork()); myself.interrupt(); assertTrue(myself.isInterrupted()); f.quietlyJoin(); Thread.interrupted(); assertEquals(21, f.result); checkCompletedNormally(f); f = new FibAction(8); f.cancel(true); assertSame(f, f.fork()); myself.interrupt(); assertTrue(myself.isInterrupted()); f.quietlyJoin(); Thread.interrupted(); checkCancelled(f); f = new FibAction(8); f.completeExceptionally(new FJException()); assertSame(f, f.fork()); myself.interrupt(); assertTrue(myself.isInterrupted()); f.quietlyJoin(); Thread.interrupted(); checkCompletedAbnormally(f, f.getException()); }}; checkInvoke(a); a.reinitialize(); checkInvoke(a); }
join/quietlyJoin of a forked task succeeds in the presence of interrupts
FailingFibAction::testJoinIgnoresInterrupts
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
Apache-2.0
public void testAwaitQuiescence1() throws Exception { final ForkJoinPool p = new ForkJoinPool(); try (PoolCleaner cleaner = cleaner(p)) { final long startTime = System.nanoTime(); assertTrue(p.isQuiescent()); ForkJoinTask a = new CheckedRecursiveAction() { protected void realCompute() { FibAction f = new FibAction(8); assertSame(f, f.fork()); assertSame(p, ForkJoinTask.getPool()); boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS); assertTrue(quiescent); assertFalse(p.isQuiescent()); while (!f.isDone()) { assertFalse(p.getAsyncMode()); assertFalse(p.isShutdown()); assertFalse(p.isTerminating()); assertFalse(p.isTerminated()); Thread.yield(); } assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); assertFalse(p.isQuiescent()); assertEquals(0, ForkJoinTask.getQueuedTaskCount()); assertEquals(21, f.result); }}; p.execute(a); while (!a.isDone() || !p.isQuiescent()) { assertFalse(p.getAsyncMode()); assertFalse(p.isShutdown()); assertFalse(p.isTerminating()); assertFalse(p.isTerminated()); Thread.yield(); } assertEquals(0, p.getQueuedTaskCount()); assertFalse(p.getAsyncMode()); assertEquals(0, p.getQueuedSubmissionCount()); assertFalse(p.hasQueuedSubmissions()); while (p.getActiveThreadCount() != 0 && millisElapsedSince(startTime) < LONG_DELAY_MS) Thread.yield(); assertFalse(p.isShutdown()); assertFalse(p.isTerminating()); assertFalse(p.isTerminated()); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } }
awaitQuiescence by a worker is equivalent in effect to ForkJoinTask.helpQuiesce()
RFCCF::testAwaitQuiescence1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
Apache-2.0
public void testAwaitQuiescence2() throws Exception { /** * """It is possible to disable or limit the use of threads in the * common pool by setting the parallelism property to zero. However * doing so may cause unjoined tasks to never be executed.""" */ if ("0".equals(System.getProperty( "java.util.concurrent.ForkJoinPool.common.parallelism"))) return; final ForkJoinPool p = new ForkJoinPool(); try (PoolCleaner cleaner = cleaner(p)) { assertTrue(p.isQuiescent()); final long startTime = System.nanoTime(); ForkJoinTask a = new CheckedRecursiveAction() { protected void realCompute() { FibAction f = new FibAction(8); assertSame(f, f.fork()); while (!f.isDone() && millisElapsedSince(startTime) < LONG_DELAY_MS) { assertFalse(p.getAsyncMode()); assertFalse(p.isShutdown()); assertFalse(p.isTerminating()); assertFalse(p.isTerminated()); Thread.yield(); } assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); assertEquals(0, ForkJoinTask.getQueuedTaskCount()); assertEquals(21, f.result); }}; p.execute(a); assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)); assertTrue(p.isQuiescent()); assertTrue(a.isDone()); assertEquals(0, p.getQueuedTaskCount()); assertFalse(p.getAsyncMode()); assertEquals(0, p.getQueuedSubmissionCount()); assertFalse(p.hasQueuedSubmissions()); while (p.getActiveThreadCount() != 0 && millisElapsedSince(startTime) < LONG_DELAY_MS) Thread.yield(); assertFalse(p.isShutdown()); assertFalse(p.isTerminating()); assertFalse(p.isTerminated()); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } }
awaitQuiescence returns when pool isQuiescent() or the indicated timeout elapsed
RFCCF::testAwaitQuiescence2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ForkJoinPool8Test.java
Apache-2.0
public void testInterruptedSubmit() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, 60, SECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p, done)) { final CountDownLatch threadStarted = new CountDownLatch(1); Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws Exception { Callable task = new CheckedCallable<Boolean>() { public Boolean realCall() throws InterruptedException { threadStarted.countDown(); await(done); return Boolean.TRUE; }}; p.submit(task).get(); }}); await(threadStarted); t.interrupt(); awaitTermination(t); } }
get of submitted callable throws InterruptedException if interrupted
FailingThreadFactory::testInterruptedSubmit
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ThreadPoolExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ThreadPoolExecutorTest.java
Apache-2.0