code
stringlengths
11
173k
docstring
stringlengths
2
593k
func_name
stringlengths
2
189
language
stringclasses
1 value
repo
stringclasses
844 values
path
stringlengths
11
294
url
stringlengths
60
339
license
stringclasses
4 values
public void testRemoveFirstOccurrence() { LinkedList q = populatedQueue(SIZE); for (int i = 1; i < SIZE; i += 2) { assertTrue(q.removeFirstOccurrence(new Integer(i))); } for (int i = 0; i < SIZE; i += 2) { assertTrue(q.removeFirstOccurrence(new Integer(i))); assertFalse(q.removeFirstOccurrence(new Integer(i + 1))); } assertTrue(q.isEmpty()); }
removeFirstOccurrence(x) removes x and returns true if present
LinkedListTest::testRemoveFirstOccurrence
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedListTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedListTest.java
Apache-2.0
public void testRemoveLastOccurrence() { LinkedList q = populatedQueue(SIZE); for (int i = 1; i < SIZE; i += 2) { assertTrue(q.removeLastOccurrence(new Integer(i))); } for (int i = 0; i < SIZE; i += 2) { assertTrue(q.removeLastOccurrence(new Integer(i))); assertFalse(q.removeLastOccurrence(new Integer(i + 1))); } assertTrue(q.isEmpty()); }
removeLastOccurrence(x) removes x and returns true if present
LinkedListTest::testRemoveLastOccurrence
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedListTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/LinkedListTest.java
Apache-2.0
public void testExecute() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch done = new CountDownLatch(1); final Runnable task = new CheckedRunnable() { public void realRun() { done.countDown(); }}; p.execute(task); assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); } }
execute successfully executes a runnable
ScheduledExecutorTest::testExecute
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSchedule1() throws Exception { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final long startTime = System.nanoTime(); final CountDownLatch done = new CountDownLatch(1); Callable task = new CheckedCallable<Boolean>() { public Boolean realCall() { done.countDown(); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); return Boolean.TRUE; }}; Future f = p.schedule(task, timeoutMillis(), MILLISECONDS); assertSame(Boolean.TRUE, f.get()); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); assertTrue(done.await(0L, MILLISECONDS)); } }
delayed schedule of callable successfully executes after delay
ScheduledExecutorTest::testSchedule1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSchedule3() throws Exception { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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()); }}; Future f = p.schedule(task, timeoutMillis(), MILLISECONDS); await(done); assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); } }
delayed schedule of runnable successfully executes after delay
ScheduledExecutorTest::testSchedule3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSchedule4() throws Exception { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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.scheduleAtFixedRate(task, timeoutMillis(), LONG_DELAY_MS, MILLISECONDS); await(done); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); f.cancel(true); } }
scheduleAtFixedRate executes runnable after given initial delay
ScheduledExecutorTest::testSchedule4
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSchedule5() throws Exception { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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
ScheduledExecutorTest::testSchedule5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testFixedRateSequence() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testFixedDelaySequence() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testExecuteNull() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { try { p.execute(null); shouldThrow(); } catch (NullPointerException success) {} } }
execute(null) throws NPE
RunnableCounter::testExecuteNull
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testScheduleNull() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSchedule1_RejectedExecutionException() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { try { p.shutdown(); p.schedule(new NoOpRunnable(), MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (RejectedExecutionException success) { } catch (SecurityException ok) {} } }
execute throws RejectedExecutionException if shutdown
RunnableCounter::testSchedule1_RejectedExecutionException
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSchedule2_RejectedExecutionException() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSchedule3_RejectedExecutionException() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testScheduleAtFixedRate1_RejectedExecutionException() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetActiveCount() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(p, done)) { final CountDownLatch threadStarted = new CountDownLatch(1); assertEquals(0, p.getActiveCount()); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); assertEquals(1, p.getActiveCount()); await(done); }}); await(threadStarted); assertEquals(1, p.getActiveCount()); } }
getActiveCount increases but doesn't overestimate, when a thread becomes active
RunnableCounter::testGetActiveCount
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetCompletedTaskCount() throws InterruptedException { final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch threadProceed = new CountDownLatch(1); final CountDownLatch threadDone = new CountDownLatch(1); assertEquals(0, p.getCompletedTaskCount()); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); assertEquals(0, p.getCompletedTaskCount()); threadProceed.await(); threadDone.countDown(); }}); await(threadStarted); assertEquals(0, p.getCompletedTaskCount()); threadProceed.countDown(); threadDone.await(); long startTime = System.nanoTime(); while (p.getCompletedTaskCount() != 1) { if (millisElapsedSince(startTime) > LONG_DELAY_MS) fail("timed out"); Thread.yield(); } } }
getCompletedTaskCount increases, but doesn't overestimate, when tasks complete
RunnableCounter::testGetCompletedTaskCount
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetCorePoolSize() throws InterruptedException { ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { assertEquals(1, p.getCorePoolSize()); } }
getCorePoolSize returns size given in constructor if not otherwise set
RunnableCounter::testGetCorePoolSize
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetLargestPoolSize() throws InterruptedException { final int THREADS = 3; final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(THREADS); final CountDownLatch threadsStarted = new CountDownLatch(THREADS); final CountDownLatch done = new CountDownLatch(1); try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(0, p.getLargestPoolSize()); for (int i = 0; i < THREADS; i++) p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadsStarted.countDown(); await(done); assertEquals(THREADS, p.getLargestPoolSize()); }}); await(threadsStarted); assertEquals(THREADS, p.getLargestPoolSize()); } assertEquals(THREADS, p.getLargestPoolSize()); }
getLargestPoolSize increases, but doesn't overestimate, when multiple threads active
RunnableCounter::testGetLargestPoolSize
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetPoolSize() throws InterruptedException { final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(1); try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(0, p.getPoolSize()); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); assertEquals(1, p.getPoolSize()); await(done); }}); await(threadStarted); assertEquals(1, p.getPoolSize()); } }
getPoolSize increases, but doesn't overestimate, when threads become active
RunnableCounter::testGetPoolSize
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetTaskCount() throws InterruptedException { final int TASKS = 3; final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetThreadFactory() throws InterruptedException { final ThreadFactory threadFactory = new SimpleThreadFactory(); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, threadFactory); try (PoolCleaner cleaner = cleaner(p)) { assertSame(threadFactory, p.getThreadFactory()); } }
getThreadFactory returns factory in constructor if not set
RunnableCounter::testGetThreadFactory
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSetThreadFactory() throws InterruptedException { ThreadFactory threadFactory = new SimpleThreadFactory(); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { p.setThreadFactory(threadFactory); assertSame(threadFactory, p.getThreadFactory()); } }
setThreadFactory sets the thread factory returned by getThreadFactory
RunnableCounter::testSetThreadFactory
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSetThreadFactoryNull() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { try { p.setThreadFactory(null); shouldThrow(); } catch (NullPointerException success) {} } }
setThreadFactory(null) throws NPE
RunnableCounter::testSetThreadFactoryNull
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testIsShutdown() { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try { assertFalse(p.isShutdown()); } finally { try { p.shutdown(); } catch (SecurityException ok) { return; } } assertTrue(p.isShutdown()); }
isShutdown is false before shutdown, true after
RunnableCounter::testIsShutdown
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testIsTerminated() throws InterruptedException { final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(1); assertFalse(p.isTerminated()); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { assertFalse(p.isTerminated()); threadStarted.countDown(); await(done); }}); await(threadStarted); assertFalse(p.isTerminating()); done.countDown(); try { p.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); assertTrue(p.isTerminated()); } }
isTerminated is false before termination, true after
RunnableCounter::testIsTerminated
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testIsTerminating() throws InterruptedException { final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(1); try (PoolCleaner cleaner = cleaner(p)) { assertFalse(p.isTerminating()); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { assertFalse(p.isTerminating()); threadStarted.countDown(); await(done); }}); await(threadStarted); assertFalse(p.isTerminating()); done.countDown(); try { p.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); assertTrue(p.isTerminated()); assertFalse(p.isTerminating()); } }
isTerminating is not true when running or when terminated
RunnableCounter::testIsTerminating
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testGetQueue() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p, done)) { final CountDownLatch threadStarted = new CountDownLatch(1); ScheduledFuture[] tasks = new ScheduledFuture[5]; for (int i = 0; i < tasks.length; i++) { Runnable r = new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); await(done); }}; tasks[i] = p.schedule(r, 1, MILLISECONDS); } await(threadStarted); BlockingQueue<Runnable> q = p.getQueue(); assertTrue(q.contains(tasks[tasks.length - 1])); assertFalse(q.contains(tasks[0])); } }
getQueue returns the work queue, which contains queued tasks
RunnableCounter::testGetQueue
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testRemove() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p, done)) { ScheduledFuture[] tasks = new ScheduledFuture[5]; final CountDownLatch threadStarted = new CountDownLatch(1); for (int i = 0; i < tasks.length; i++) { Runnable r = new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); await(done); }}; tasks[i] = p.schedule(r, 1, MILLISECONDS); } await(threadStarted); BlockingQueue<Runnable> q = p.getQueue(); assertFalse(p.remove((Runnable)tasks[0])); assertTrue(q.contains((Runnable)tasks[4])); assertTrue(q.contains((Runnable)tasks[3])); assertTrue(p.remove((Runnable)tasks[4])); assertFalse(p.remove((Runnable)tasks[4])); assertFalse(q.contains((Runnable)tasks[4])); assertTrue(q.contains((Runnable)tasks[3])); assertTrue(p.remove((Runnable)tasks[3])); assertFalse(q.contains((Runnable)tasks[3])); } }
remove(task) removes queued task, and fails to remove active task
RunnableCounter::testRemove
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testPurge() throws InterruptedException { final ScheduledFuture[] tasks = new ScheduledFuture[5]; final Runnable releaser = new Runnable() { public void run() { for (ScheduledFuture task : tasks) if (task != null) task.cancel(true); }}; final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p, releaser)) { for (int i = 0; i < tasks.length; i++) tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), LONG_DELAY_MS, MILLISECONDS); int max = tasks.length; if (tasks[4].cancel(true)) --max; if (tasks[3].cancel(true)) --max; // There must eventually be an interference-free point at // which purge will not fail. (At worst, when queue is empty.) long startTime = System.nanoTime(); do { p.purge(); long count = p.getTaskCount(); if (count == max) return; } while (millisElapsedSince(startTime) < LONG_DELAY_MS); fail("Purge failed to remove cancelled tasks"); } }
purge eventually removes cancelled tasks from the queue
RunnableCounter::testPurge
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testShutdownNow() throws InterruptedException { final int poolSize = 2; final int count = 5; final AtomicInteger ran = new AtomicInteger(0); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(poolSize); final CountDownLatch threadsStarted = new CountDownLatch(poolSize); Runnable waiter = new CheckedRunnable() { public void realRun() { threadsStarted.countDown(); try { MILLISECONDS.sleep(2 * LONG_DELAY_MS); } catch (InterruptedException success) {} ran.getAndIncrement(); }}; for (int i = 0; i < count; i++) p.execute(waiter); await(threadsStarted); assertEquals(poolSize, p.getActiveCount()); assertEquals(0, p.getCompletedTaskCount()); final List<Runnable> queuedTasks; try { queuedTasks = p.shutdownNow(); } catch (SecurityException ok) { return; // Allowed in case test doesn't have privs } assertTrue(p.isShutdown()); assertTrue(p.getQueue().isEmpty()); assertEquals(count - poolSize, queuedTasks.size()); assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); assertTrue(p.isTerminated()); assertEquals(poolSize, ran.get()); assertEquals(poolSize, p.getCompletedTaskCount()); }
shutdownNow returns a list containing tasks that were not run, and those tasks are drained from the queue
RunnableCounter::testShutdownNow
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testShutdownNow_delayedTasks() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); List<ScheduledFuture> tasks = new ArrayList<>(); for (int i = 0; i < 3; i++) { Runnable r = new NoOpRunnable(); tasks.add(p.schedule(r, 9, SECONDS)); tasks.add(p.scheduleAtFixedRate(r, 9, 9, SECONDS)); tasks.add(p.scheduleWithFixedDelay(r, 9, 9, SECONDS)); } if (testImplementationDetails) assertEquals(new HashSet(tasks), new HashSet(p.getQueue())); final List<Runnable> queuedTasks; try { queuedTasks = p.shutdownNow(); } catch (SecurityException ok) { return; // Allowed in case test doesn't have privs } assertTrue(p.isShutdown()); assertTrue(p.getQueue().isEmpty()); if (testImplementationDetails) assertEquals(new HashSet(tasks), new HashSet(queuedTasks)); assertEquals(tasks.size(), queuedTasks.size()); for (ScheduledFuture task : tasks) { assertFalse(task.isDone()); assertFalse(task.isCancelled()); } assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); assertTrue(p.isTerminated()); }
shutdownNow returns a list containing tasks that were not run, and those tasks are drained from the queue
RunnableCounter::testShutdownNow_delayedTasks
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.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 ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSubmitCallable() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { Future<String> future = e.submit(new StringTask()); String result = future.get(); assertSame(TEST_STRING, result); } }
completed submit of callable returns result
RunnableCounter::testSubmitCallable
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSubmitRunnable() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { Future<?> future = e.submit(new NoOpRunnable()); future.get(); assertTrue(future.isDone()); } }
completed submit of runnable returns successfully
RunnableCounter::testSubmitRunnable
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testSubmitRunnable2() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING); String result = future.get(); assertSame(TEST_STRING, result); } }
completed submit of (runnable, result) returns result
RunnableCounter::testSubmitRunnable2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAny1() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(null); shouldThrow(); } catch (NullPointerException success) {} } }
invokeAny(null) throws NPE
RunnableCounter::testInvokeAny1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAny2() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(new ArrayList<Callable<String>>()); shouldThrow(); } catch (IllegalArgumentException success) {} } }
invokeAny(empty collection) throws IAE
RunnableCounter::testInvokeAny2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAny3() throws Exception { CountDownLatch latch = new CountDownLatch(1); final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(latchAwaitingStringTask(latch)); l.add(null); try { e.invokeAny(l); shouldThrow(); } catch (NullPointerException success) {} latch.countDown(); } }
invokeAny(c) throws NPE if c has null elements
RunnableCounter::testInvokeAny3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAny4() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new NPETask()); try { e.invokeAny(l); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); } } }
invokeAny(c) throws ExecutionException if no task completes
RunnableCounter::testInvokeAny4
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAny5() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l); assertSame(TEST_STRING, result); } }
invokeAny(c) returns result of some task
RunnableCounter::testInvokeAny5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAll1() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAll(null); shouldThrow(); } catch (NullPointerException success) {} } }
invokeAll(null) throws NPE
RunnableCounter::testInvokeAll1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAll2() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); assertTrue(r.isEmpty()); } }
invokeAll(empty collection) returns empty collection
RunnableCounter::testInvokeAll2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAll3() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); l.add(null); try { e.invokeAll(l); shouldThrow(); } catch (NullPointerException success) {} } }
invokeAll(c) throws NPE if c has null elements
RunnableCounter::testInvokeAll3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAll4() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(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/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testInvokeAll5() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); l.add(new StringTask()); List<Future<String>> futures = e.invokeAll(l); assertEquals(2, futures.size()); for (Future<String> future : futures) assertSame(TEST_STRING, future.get()); } }
invokeAll(c) returns results of all completed tasks
RunnableCounter::testInvokeAll5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAny1() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) {} } }
timed invokeAny(null) throws NPE
RunnableCounter::testTimedInvokeAny1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAnyNullTimeUnit() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); try { e.invokeAny(l, MEDIUM_DELAY_MS, null); shouldThrow(); } catch (NullPointerException success) {} } }
timed invokeAny(,,null) throws NPE
RunnableCounter::testTimedInvokeAnyNullTimeUnit
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAny2() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (IllegalArgumentException success) {} } }
timed invokeAny(empty collection) throws IAE
RunnableCounter::testTimedInvokeAny2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAny3() throws Exception { CountDownLatch latch = new CountDownLatch(1); final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(latchAwaitingStringTask(latch)); l.add(null); try { e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) {} latch.countDown(); } }
timed invokeAny(c) throws NPE if c has null elements
RunnableCounter::testTimedInvokeAny3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAny4() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { long startTime = System.nanoTime(); List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new NPETask()); try { e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); } assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } }
timed invokeAny(c) throws ExecutionException if no task completes
RunnableCounter::testTimedInvokeAny4
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAny5() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { long startTime = System.nanoTime(); List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); l.add(new StringTask()); String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); assertSame(TEST_STRING, result); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } }
timed invokeAny(c) returns result of some task
RunnableCounter::testTimedInvokeAny5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAll1() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) {} } }
timed invokeAll(null) throws NPE
RunnableCounter::testTimedInvokeAll1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAllNullTimeUnit() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); try { e.invokeAll(l, MEDIUM_DELAY_MS, null); shouldThrow(); } catch (NullPointerException success) {} } }
timed invokeAll(,,null) throws NPE
RunnableCounter::testTimedInvokeAllNullTimeUnit
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAll2() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS); assertTrue(r.isEmpty()); } }
timed invokeAll(empty collection) returns empty collection
RunnableCounter::testTimedInvokeAll2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAll3() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); l.add(null); try { e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) {} } }
timed invokeAll(c) throws NPE if c has null elements
RunnableCounter::testTimedInvokeAll3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAll4() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(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, LONG_DELAY_MS, MILLISECONDS); assertEquals(1, futures.size()); try { futures.get(0).get(); shouldThrow(); } catch (ExecutionException success) { assertTrue(success.getCause() instanceof NullPointerException); } } }
get of element of invokeAll(c) throws exception on failed task
RunnableCounter::testTimedInvokeAll4
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAll5() throws Exception { final ExecutorService e = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(e)) { List<Callable<String>> l = new ArrayList<Callable<String>>(); l.add(new StringTask()); l.add(new StringTask()); List<Future<String>> futures = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); assertEquals(2, futures.size()); for (Future<String> future : futures) assertSame(TEST_STRING, future.get()); } }
timed invokeAll(c) returns results of all completed tasks
RunnableCounter::testTimedInvokeAll5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testTimedInvokeAll6() throws Exception { for (long timeout = timeoutMillis();;) { final CountDownLatch done = new CountDownLatch(1); final Callable<String> waiter = new CheckedCallable<String>() { public String realCall() { try { done.await(LONG_DELAY_MS, MILLISECONDS); } catch (InterruptedException ok) {} return "1"; }}; final ExecutorService p = new ScheduledThreadPoolExecutor(2); try (PoolCleaner cleaner = cleaner(p, done)) { List<Callable<String>> tasks = new ArrayList<>(); tasks.add(new StringTask("0")); tasks.add(waiter); tasks.add(new StringTask("2")); long startTime = System.nanoTime(); List<Future<String>> futures = p.invokeAll(tasks, timeout, MILLISECONDS); assertEquals(tasks.size(), futures.size()); assertTrue(millisElapsedSince(startTime) >= timeout); for (Future future : futures) assertTrue(future.isDone()); assertTrue(futures.get(1).isCancelled()); try { assertEquals("0", futures.get(0).get()); assertEquals("2", futures.get(2).get()); break; } catch (CancellationException retryWithLongerTimeout) { timeout *= 2; if (timeout >= LONG_DELAY_MS / 2) fail("expected exactly one task to be cancelled"); } } } }
timed invokeAll(c) cancels tasks not completed by timeout
RunnableCounter::testTimedInvokeAll6
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testScheduleWithFixedDelay_overflow() throws Exception { final CountDownLatch delayedDone = new CountDownLatch(1); final CountDownLatch immediateDone = new CountDownLatch(1); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final Runnable immediate = new Runnable() { public void run() { immediateDone.countDown(); }}; final Runnable delayed = new Runnable() { public void run() { delayedDone.countDown(); p.submit(immediate); }}; p.scheduleWithFixedDelay(delayed, 0L, Long.MAX_VALUE, SECONDS); await(delayedDone); await(immediateDone); } }
A fixed delay task with overflowing period should not prevent a one-shot task from executing. https://bugs.openjdk.java.net/browse/JDK-8051859
RunnableCounter::testScheduleWithFixedDelay_overflow
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ScheduledExecutorTest.java
Apache-2.0
public void testNanoTime1() throws InterruptedException { long m1 = System.currentTimeMillis(); Thread.sleep(1); long n1 = System.nanoTime(); Thread.sleep(SHORT_DELAY_MS); long n2 = System.nanoTime(); Thread.sleep(1); long m2 = System.currentTimeMillis(); long millis = m2 - m1; long nanos = n2 - n1; assertTrue(nanos >= 0); long nanosAsMillis = nanos / 1000000; assertTrue(nanosAsMillis <= millis + MILLIS_ROUND); }
Nanos between readings of millis is no longer than millis (plus possible rounding). This shows only that nano timing not (much) worse than milli.
SystemTest::testNanoTime1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SystemTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SystemTest.java
Apache-2.0
public void testNanoTime2() throws InterruptedException { long n1 = System.nanoTime(); Thread.sleep(1); long m1 = System.currentTimeMillis(); Thread.sleep(SHORT_DELAY_MS); long m2 = System.currentTimeMillis(); Thread.sleep(1); long n2 = System.nanoTime(); long millis = m2 - m1; long nanos = n2 - n1; assertTrue(nanos >= 0); long nanosAsMillis = nanos / 1000000; assertTrue(millis <= nanosAsMillis + MILLIS_ROUND); }
Millis between readings of nanos is less than nanos, adjusting for rounding. This shows only that nano timing not (much) worse than milli.
SystemTest::testNanoTime2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SystemTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/SystemTest.java
Apache-2.0
private ConcurrentLinkedQueue<Integer> populatedQueue(int n) { ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<Integer>(); assertTrue(q.isEmpty()); for (int i = 0; i < n; ++i) assertTrue(q.offer(new Integer(i))); assertFalse(q.isEmpty()); assertEquals(n, q.size()); return q; }
Returns a new queue of given size containing consecutive Integers 0 ... n.
ConcurrentLinkedQueueTest::populatedQueue
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testConstructor1() { assertEquals(0, new ConcurrentLinkedQueue().size()); }
new queue is empty
ConcurrentLinkedQueueTest::testConstructor1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testConstructor3() { try { new ConcurrentLinkedQueue((Collection)null); shouldThrow(); } catch (NullPointerException success) {} }
Initializing from null Collection throws NPE
ConcurrentLinkedQueueTest::testConstructor3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testConstructor4() { try { new ConcurrentLinkedQueue(Arrays.asList(new Integer[SIZE])); shouldThrow(); } catch (NullPointerException success) {} }
Initializing from Collection of null elements throws NPE
ConcurrentLinkedQueueTest::testConstructor4
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testConstructor5() { Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); try { new ConcurrentLinkedQueue(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} }
Initializing from Collection with some null elements throws NPE
ConcurrentLinkedQueueTest::testConstructor5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testConstructor6() { Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i); ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(Arrays.asList(ints)); for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll()); }
Queue contains all elements of collection used to initialize
ConcurrentLinkedQueueTest::testConstructor6
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testEmpty() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); assertTrue(q.isEmpty()); q.add(one); assertFalse(q.isEmpty()); q.add(two); q.remove(); q.remove(); assertTrue(q.isEmpty()); }
isEmpty is true before add, false after
ConcurrentLinkedQueueTest::testEmpty
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testSize() { ConcurrentLinkedQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(SIZE - i, q.size()); q.remove(); } for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.size()); q.add(new Integer(i)); } }
size changes when elements added and removed
ConcurrentLinkedQueueTest::testSize
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testOfferNull() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); try { q.offer(null); shouldThrow(); } catch (NullPointerException success) {} }
offer(null) throws NPE
ConcurrentLinkedQueueTest::testOfferNull
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testAddNull() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); try { q.add(null); shouldThrow(); } catch (NullPointerException success) {} }
add(null) throws NPE
ConcurrentLinkedQueueTest::testAddNull
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testOffer() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); assertTrue(q.offer(zero)); assertTrue(q.offer(one)); }
Offer returns true
ConcurrentLinkedQueueTest::testOffer
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testAdd() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.size()); assertTrue(q.add(new Integer(i))); } }
add returns true
ConcurrentLinkedQueueTest::testAdd
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testAddAll1() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); try { q.addAll(null); shouldThrow(); } catch (NullPointerException success) {} }
addAll(null) throws NPE
ConcurrentLinkedQueueTest::testAddAll1
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testAddAllSelf() { ConcurrentLinkedQueue q = populatedQueue(SIZE); try { q.addAll(q); shouldThrow(); } catch (IllegalArgumentException success) {} }
addAll(this) throws IAE
ConcurrentLinkedQueueTest::testAddAllSelf
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testAddAll2() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); try { q.addAll(Arrays.asList(new Integer[SIZE])); shouldThrow(); } catch (NullPointerException success) {} }
addAll of a collection with null elements throws NPE
ConcurrentLinkedQueueTest::testAddAll2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testAddAll3() { ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); try { q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} }
addAll of a collection with any null elements throws NPE after possibly adding some elements
ConcurrentLinkedQueueTest::testAddAll3
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testAddAll5() { Integer[] empty = new Integer[0]; Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i); ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); assertFalse(q.addAll(Arrays.asList(empty))); assertTrue(q.addAll(Arrays.asList(ints))); for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll()); }
Queue contains all elements, in traversal order, of successful addAll
ConcurrentLinkedQueueTest::testAddAll5
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testPoll() { ConcurrentLinkedQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.poll()); } assertNull(q.poll()); }
poll succeeds unless empty
ConcurrentLinkedQueueTest::testPoll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testPeek() { ConcurrentLinkedQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.peek()); assertEquals(i, q.poll()); assertTrue(q.peek() == null || !q.peek().equals(i)); } assertNull(q.peek()); }
peek returns next element, or null if empty
ConcurrentLinkedQueueTest::testPeek
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testElement() { ConcurrentLinkedQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.element()); assertEquals(i, q.poll()); } try { q.element(); shouldThrow(); } catch (NoSuchElementException success) {} }
element returns next element, or throws NSEE if empty
ConcurrentLinkedQueueTest::testElement
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testRemove() { ConcurrentLinkedQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.remove()); } try { q.remove(); shouldThrow(); } catch (NoSuchElementException success) {} }
remove removes next element, or throws NSEE if empty
ConcurrentLinkedQueueTest::testRemove
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testRemoveElement() { ConcurrentLinkedQueue q = populatedQueue(SIZE); for (int i = 1; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); assertTrue(q.contains(i - 1)); } for (int i = 0; i < SIZE; i += 2) { assertTrue(q.contains(i)); assertTrue(q.remove(i)); assertFalse(q.contains(i)); assertFalse(q.remove(i + 1)); assertFalse(q.contains(i + 1)); } assertTrue(q.isEmpty()); }
remove(x) removes x and returns true if present
ConcurrentLinkedQueueTest::testRemoveElement
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testContains() { ConcurrentLinkedQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertTrue(q.contains(new Integer(i))); q.poll(); assertFalse(q.contains(new Integer(i))); } }
contains(x) reports true when elements added but not yet removed
ConcurrentLinkedQueueTest::testContains
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testClear() { ConcurrentLinkedQueue q = populatedQueue(SIZE); q.clear(); assertTrue(q.isEmpty()); assertEquals(0, q.size()); q.add(one); assertFalse(q.isEmpty()); q.clear(); assertTrue(q.isEmpty()); }
clear removes all elements
ConcurrentLinkedQueueTest::testClear
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testContainsAll() { ConcurrentLinkedQueue q = populatedQueue(SIZE); ConcurrentLinkedQueue p = new ConcurrentLinkedQueue(); for (int i = 0; i < SIZE; ++i) { assertTrue(q.containsAll(p)); assertFalse(p.containsAll(q)); p.add(new Integer(i)); } assertTrue(p.containsAll(q)); }
containsAll(c) is true when c contains a subset of elements
ConcurrentLinkedQueueTest::testContainsAll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testRetainAll() { ConcurrentLinkedQueue q = populatedQueue(SIZE); ConcurrentLinkedQueue p = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { boolean changed = q.retainAll(p); if (i == 0) assertFalse(changed); else assertTrue(changed); assertTrue(q.containsAll(p)); assertEquals(SIZE - i, q.size()); p.remove(); } }
retainAll(c) retains only those elements of c and reports true if change
ConcurrentLinkedQueueTest::testRetainAll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testRemoveAll() { for (int i = 1; i < SIZE; ++i) { ConcurrentLinkedQueue q = populatedQueue(SIZE); ConcurrentLinkedQueue p = populatedQueue(i); assertTrue(q.removeAll(p)); assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.remove()); assertFalse(q.contains(x)); } } }
removeAll(c) removes only those elements of c and reports true if changed
ConcurrentLinkedQueueTest::testRemoveAll
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testToArray() { ConcurrentLinkedQueue q = populatedQueue(SIZE); Object[] o = q.toArray(); for (int i = 0; i < o.length; i++) assertSame(o[i], q.poll()); }
toArray contains all elements in FIFO order
ConcurrentLinkedQueueTest::testToArray
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testToArray2() { ConcurrentLinkedQueue<Integer> q = populatedQueue(SIZE); Integer[] ints = new Integer[SIZE]; Integer[] array = q.toArray(ints); assertSame(ints, array); for (int i = 0; i < ints.length; i++) assertSame(ints[i], q.poll()); }
toArray(a) contains all elements in FIFO order
ConcurrentLinkedQueueTest::testToArray2
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testToArray_NullArg() { ConcurrentLinkedQueue q = populatedQueue(SIZE); try { q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} }
toArray(null) throws NullPointerException
ConcurrentLinkedQueueTest::testToArray_NullArg
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testToArray1_BadArg() { ConcurrentLinkedQueue q = populatedQueue(SIZE); try { q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} }
toArray(incompatible array type) throws ArrayStoreException
ConcurrentLinkedQueueTest::testToArray1_BadArg
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testIterator() { ConcurrentLinkedQueue q = populatedQueue(SIZE); Iterator it = q.iterator(); int i; for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next())); assertEquals(i, SIZE); assertIteratorExhausted(it); }
iterator iterates through all elements
ConcurrentLinkedQueueTest::testIterator
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testEmptyIterator() { assertIteratorExhausted(new ConcurrentLinkedQueue().iterator()); }
iterator of empty collection has no elements
ConcurrentLinkedQueueTest::testEmptyIterator
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testIteratorOrdering() { final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); q.add(one); q.add(two); q.add(three); int k = 0; for (Iterator it = q.iterator(); it.hasNext();) { assertEquals(++k, it.next()); } assertEquals(3, k); }
iterator ordering is FIFO
ConcurrentLinkedQueueTest::testIteratorOrdering
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testWeaklyConsistentIteration() { final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); q.add(one); q.add(two); q.add(three); for (Iterator it = q.iterator(); it.hasNext();) { q.remove(); it.next(); } assertEquals("queue should be empty again", 0, q.size()); }
Modifications do not cause iterators to fail
ConcurrentLinkedQueueTest::testWeaklyConsistentIteration
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testIteratorRemove() { final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); q.add(one); q.add(two); q.add(three); Iterator it = q.iterator(); it.next(); it.remove(); it = q.iterator(); assertSame(it.next(), two); assertSame(it.next(), three); assertFalse(it.hasNext()); }
iterator.remove removes current element
ConcurrentLinkedQueueTest::testIteratorRemove
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0
public void testToString() { ConcurrentLinkedQueue q = populatedQueue(SIZE); String s = q.toString(); for (int i = 0; i < SIZE; ++i) { assertTrue(s.contains(String.valueOf(i))); } }
toString contains toStrings of elements
ConcurrentLinkedQueueTest::testToString
java
google/j2objc
jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
https://github.com/google/j2objc/blob/master/jre_emul/android/platform/libcore/jsr166-tests/src/test/java/jsr166/ConcurrentLinkedQueueTest.java
Apache-2.0