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 testPrestartCoreThread() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 6, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertEquals(0, p.getPoolSize()); assertTrue(p.prestartCoreThread()); assertEquals(1, p.getPoolSize()); assertTrue(p.prestartCoreThread()); assertEquals(2, p.getPoolSize()); assertFalse(p.prestartCoreThread()); assertEquals(2, p.getPoolSize()); p.setCorePoolSize(4); assertTrue(p.prestartCoreThread()); assertEquals(3, p.getPoolSize()); assertTrue(p.prestartCoreThread()); assertEquals(4, p.getPoolSize()); assertFalse(p.prestartCoreThread()); assertEquals(4, p.getPoolSize()); } }
prestartCoreThread starts a thread if under corePoolSize, else doesn't
FailingThreadFactory::testPrestartCoreThread
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
public void testPrestartAllCoreThreads() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 6, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertEquals(0, p.getPoolSize()); p.prestartAllCoreThreads(); assertEquals(2, p.getPoolSize()); p.prestartAllCoreThreads(); assertEquals(2, p.getPoolSize()); p.setCorePoolSize(4); p.prestartAllCoreThreads(); assertEquals(4, p.getPoolSize()); p.prestartAllCoreThreads(); assertEquals(4, p.getPoolSize()); } }
prestartAllCoreThreads starts all corePoolSize threads
FailingThreadFactory::testPrestartAllCoreThreads
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
public void testGetCompletedTaskCount() throws InterruptedException { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testGetCompletedTaskCount
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
public void testGetCorePoolSize() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertEquals(1, p.getCorePoolSize()); } }
getCorePoolSize returns size given in constructor if not otherwise set
FailingThreadFactory::testGetCorePoolSize
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
public void testGetKeepAliveTime() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertEquals(1, p.getKeepAliveTime(SECONDS)); } }
getKeepAliveTime returns value given in constructor if not otherwise set
FailingThreadFactory::testGetKeepAliveTime
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
public void testGetThreadFactory() { ThreadFactory threadFactory = new SimpleThreadFactory(); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), threadFactory, new NoOpREHandler()); try (PoolCleaner cleaner = cleaner(p)) { assertSame(threadFactory, p.getThreadFactory()); } }
getThreadFactory returns factory in constructor if not set
FailingThreadFactory::testGetThreadFactory
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
public void testSetThreadFactory() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { ThreadFactory threadFactory = new SimpleThreadFactory(); p.setThreadFactory(threadFactory); assertSame(threadFactory, p.getThreadFactory()); } }
setThreadFactory sets the thread factory returned by getThreadFactory
FailingThreadFactory::testSetThreadFactory
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
public void testSetThreadFactoryNull() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.setThreadFactory(null); shouldThrow(); } catch (NullPointerException success) {} } }
setThreadFactory(null) throws NPE
FailingThreadFactory::testSetThreadFactoryNull
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
public void testGetRejectedExecutionHandler() { final RejectedExecutionHandler handler = new NoOpREHandler(); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), handler); try (PoolCleaner cleaner = cleaner(p)) { assertSame(handler, p.getRejectedExecutionHandler()); } }
getRejectedExecutionHandler returns handler in constructor if not set
FailingThreadFactory::testGetRejectedExecutionHandler
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
public void testSetRejectedExecutionHandler() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { RejectedExecutionHandler handler = new NoOpREHandler(); p.setRejectedExecutionHandler(handler); assertSame(handler, p.getRejectedExecutionHandler()); } }
setRejectedExecutionHandler sets the handler returned by getRejectedExecutionHandler
FailingThreadFactory::testSetRejectedExecutionHandler
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
public void testSetRejectedExecutionHandlerNull() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.setRejectedExecutionHandler(null); shouldThrow(); } catch (NullPointerException success) {} } }
setRejectedExecutionHandler(null) throws NPE
FailingThreadFactory::testSetRejectedExecutionHandlerNull
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
public void testGetLargestPoolSize() throws InterruptedException { final int THREADS = 3; final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(THREADS, THREADS, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(0, p.getLargestPoolSize()); final CountDownLatch threadsStarted = new CountDownLatch(THREADS); 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
FailingThreadFactory::testGetLargestPoolSize
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
public void testGetMaximumPoolSize() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 3, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertEquals(3, p.getMaximumPoolSize()); p.setMaximumPoolSize(5); assertEquals(5, p.getMaximumPoolSize()); p.setMaximumPoolSize(4); assertEquals(4, p.getMaximumPoolSize()); } }
getMaximumPoolSize returns value given in constructor if not otherwise set
FailingThreadFactory::testGetMaximumPoolSize
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
public void testGetPoolSize() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(0, p.getPoolSize()); final CountDownLatch threadStarted = new CountDownLatch(1); 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
FailingThreadFactory::testGetPoolSize
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
public void testGetTaskCount() throws InterruptedException { final int TASKS = 3; final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testGetTaskCount
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
public void testIsShutdown() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertFalse(p.isShutdown()); try { p.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p.isShutdown()); } }
isShutdown is false before shutdown, true after
FailingThreadFactory::testIsShutdown
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
public void testAwaitTermination_timesOut() throws InterruptedException { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertFalse(p.isTerminated()); assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS)); assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); assertFalse(p.awaitTermination(-1L, NANOSECONDS)); assertFalse(p.awaitTermination(-1L, MILLISECONDS)); assertFalse(p.awaitTermination(0L, NANOSECONDS)); assertFalse(p.awaitTermination(0L, MILLISECONDS)); long timeoutNanos = 999999L; long startTime = System.nanoTime(); assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); assertTrue(System.nanoTime() - startTime >= timeoutNanos); assertFalse(p.isTerminated()); startTime = System.nanoTime(); long timeoutMillis = timeoutMillis(); assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) >= timeoutMillis); assertFalse(p.isTerminated()); try { p.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); assertTrue(p.isTerminated()); } }
awaitTermination on a non-shutdown pool times out
FailingThreadFactory::testAwaitTermination_timesOut
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
public void testIsTerminated() throws InterruptedException { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(1); 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()); } }
isTerminated is false before termination, true after
FailingThreadFactory::testIsTerminated
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
public void testIsTerminating() throws InterruptedException { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(1); 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
FailingThreadFactory::testIsTerminating
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
public void testGetQueue() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, q); try (PoolCleaner cleaner = cleaner(p, done)) { final CountDownLatch threadStarted = new CountDownLatch(1); FutureTask[] tasks = new FutureTask[5]; for (int i = 0; i < tasks.length; i++) { Callable task = new CheckedCallable<Boolean>() { public Boolean realCall() throws InterruptedException { threadStarted.countDown(); assertSame(q, p.getQueue()); await(done); return Boolean.TRUE; }}; tasks[i] = new FutureTask(task); p.execute(tasks[i]); } await(threadStarted); assertSame(q, p.getQueue()); assertFalse(q.contains(tasks[0])); assertTrue(q.contains(tasks[tasks.length - 1])); assertEquals(tasks.length - 1, q.size()); } }
getQueue returns the work queue, which contains queued tasks
FailingThreadFactory::testGetQueue
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
public void testRemove() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, q); try (PoolCleaner cleaner = cleaner(p, done)) { Runnable[] tasks = new Runnable[6]; final CountDownLatch threadStarted = new CountDownLatch(1); for (int i = 0; i < tasks.length; i++) { tasks[i] = new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); await(done); }}; p.execute(tasks[i]); } await(threadStarted); assertFalse(p.remove(tasks[0])); assertTrue(q.contains(tasks[4])); assertTrue(q.contains(tasks[3])); assertTrue(p.remove(tasks[4])); assertFalse(p.remove(tasks[4])); assertFalse(q.contains(tasks[4])); assertTrue(q.contains(tasks[3])); assertTrue(p.remove(tasks[3])); assertFalse(q.contains(tasks[3])); } }
remove(task) removes queued task, and fails to remove active task
FailingThreadFactory::testRemove
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
public void testPurge() throws InterruptedException { final CountDownLatch threadStarted = new CountDownLatch(1); final CountDownLatch done = new CountDownLatch(1); final BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, q); try (PoolCleaner cleaner = cleaner(p, done)) { FutureTask[] tasks = new FutureTask[5]; for (int i = 0; i < tasks.length; i++) { Callable task = new CheckedCallable<Boolean>() { public Boolean realCall() throws InterruptedException { threadStarted.countDown(); await(done); return Boolean.TRUE; }}; tasks[i] = new FutureTask(task); p.execute(tasks[i]); } await(threadStarted); assertEquals(tasks.length, p.getTaskCount()); assertEquals(tasks.length - 1, q.size()); assertEquals(1L, p.getActiveCount()); assertEquals(0L, p.getCompletedTaskCount()); tasks[4].cancel(true); tasks[3].cancel(false); p.purge(); assertEquals(tasks.length - 3, q.size()); assertEquals(tasks.length - 2, p.getTaskCount()); p.purge(); // Nothing to do assertEquals(tasks.length - 3, q.size()); assertEquals(tasks.length - 2, p.getTaskCount()); } }
purge removes cancelled tasks from the queue
FailingThreadFactory::testPurge
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
public void testShutdownNow() throws InterruptedException { final int poolSize = 2; final int count = 5; final AtomicInteger ran = new AtomicInteger(0); final ThreadPoolExecutor p = new ThreadPoolExecutor(poolSize, poolSize, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testShutdownNow
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
public void testConstructor1() { try { new ThreadPoolExecutor(-1, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10)); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize argument is less than zero
FailingThreadFactory::testConstructor1
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
public void testConstructor2() { try { new ThreadPoolExecutor(1, -1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10)); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is less than zero
FailingThreadFactory::testConstructor2
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
public void testConstructor3() { try { new ThreadPoolExecutor(1, 0, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10)); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is equal to zero
FailingThreadFactory::testConstructor3
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
public void testConstructor4() { try { new ThreadPoolExecutor(1, 2, -1L, SECONDS, new ArrayBlockingQueue<Runnable>(10)); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if keepAliveTime is less than zero
FailingThreadFactory::testConstructor4
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
public void testConstructor5() { try { new ThreadPoolExecutor(2, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10)); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize is greater than the maximumPoolSize
FailingThreadFactory::testConstructor5
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
public void testConstructorNullPointerException() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, (BlockingQueue) null); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if workQueue is set to null
FailingThreadFactory::testConstructorNullPointerException
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
public void testConstructor6() { try { new ThreadPoolExecutor(-1, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize argument is less than zero
FailingThreadFactory::testConstructor6
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
public void testConstructor7() { try { new ThreadPoolExecutor(1, -1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is less than zero
FailingThreadFactory::testConstructor7
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
public void testConstructor8() { try { new ThreadPoolExecutor(1, 0, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is equal to zero
FailingThreadFactory::testConstructor8
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
public void testConstructor9() { try { new ThreadPoolExecutor(1, 2, -1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if keepAliveTime is less than zero
FailingThreadFactory::testConstructor9
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
public void testConstructor10() { try { new ThreadPoolExecutor(2, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize is greater than the maximumPoolSize
FailingThreadFactory::testConstructor10
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
public void testConstructorNullPointerException2() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, (BlockingQueue) null, new SimpleThreadFactory()); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if workQueue is set to null
FailingThreadFactory::testConstructorNullPointerException2
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
public void testConstructorNullPointerException3() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), (ThreadFactory) null); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if threadFactory is set to null
FailingThreadFactory::testConstructorNullPointerException3
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
public void testConstructor11() { try { new ThreadPoolExecutor(-1, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize argument is less than zero
FailingThreadFactory::testConstructor11
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
public void testConstructor12() { try { new ThreadPoolExecutor(1, -1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is less than zero
FailingThreadFactory::testConstructor12
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
public void testConstructor13() { try { new ThreadPoolExecutor(1, 0, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is equal to zero
FailingThreadFactory::testConstructor13
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
public void testConstructor14() { try { new ThreadPoolExecutor(1, 2, -1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if keepAliveTime is less than zero
FailingThreadFactory::testConstructor14
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
public void testConstructor15() { try { new ThreadPoolExecutor(2, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize is greater than the maximumPoolSize
FailingThreadFactory::testConstructor15
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
public void testConstructorNullPointerException4() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, (BlockingQueue) null, new NoOpREHandler()); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if workQueue is set to null
FailingThreadFactory::testConstructorNullPointerException4
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
public void testConstructorNullPointerException5() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), (RejectedExecutionHandler) null); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if handler is set to null
FailingThreadFactory::testConstructorNullPointerException5
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
public void testConstructor16() { try { new ThreadPoolExecutor(-1, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory(), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize argument is less than zero
FailingThreadFactory::testConstructor16
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
public void testConstructor17() { try { new ThreadPoolExecutor(1, -1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory(), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is less than zero
FailingThreadFactory::testConstructor17
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
public void testConstructor18() { try { new ThreadPoolExecutor(1, 0, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory(), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if maximumPoolSize is equal to zero
FailingThreadFactory::testConstructor18
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
public void testConstructor19() { try { new ThreadPoolExecutor(1, 2, -1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory(), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if keepAliveTime is less than zero
FailingThreadFactory::testConstructor19
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
public void testConstructor20() { try { new ThreadPoolExecutor(2, 1, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory(), new NoOpREHandler()); shouldThrow(); } catch (IllegalArgumentException success) {} }
Constructor throws if corePoolSize is greater than the maximumPoolSize
FailingThreadFactory::testConstructor20
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
public void testConstructorNullPointerException6() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, (BlockingQueue) null, new SimpleThreadFactory(), new NoOpREHandler()); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if workQueue is null
FailingThreadFactory::testConstructorNullPointerException6
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
public void testConstructorNullPointerException7() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), new SimpleThreadFactory(), (RejectedExecutionHandler) null); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if handler is null
FailingThreadFactory::testConstructorNullPointerException7
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
public void testConstructorNullPointerException8() { try { new ThreadPoolExecutor(1, 2, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10), (ThreadFactory) null, new NoOpREHandler()); shouldThrow(); } catch (NullPointerException success) {} }
Constructor throws if ThreadFactory is null
FailingThreadFactory::testConstructorNullPointerException8
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
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
public void testSaturatedExecute() { final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); try (PoolCleaner cleaner = cleaner(p, done)) { Runnable task = new CheckedRunnable() { public void realRun() throws InterruptedException { await(done); }}; for (int i = 0; i < 2; ++i) p.execute(task); for (int i = 0; i < 2; ++i) { try { p.execute(task); shouldThrow(); } catch (RejectedExecutionException success) {} assertTrue(p.getTaskCount() <= 2); } } }
execute throws RejectedExecutionException if saturated.
FailingThreadFactory::testSaturatedExecute
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
public void testSaturatedSubmitRunnable() { final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); try (PoolCleaner cleaner = cleaner(p, done)) { Runnable task = new CheckedRunnable() { public void realRun() throws InterruptedException { await(done); }}; for (int i = 0; i < 2; ++i) p.submit(task); for (int i = 0; i < 2; ++i) { try { p.execute(task); shouldThrow(); } catch (RejectedExecutionException success) {} assertTrue(p.getTaskCount() <= 2); } } }
submit(runnable) throws RejectedExecutionException if saturated.
FailingThreadFactory::testSaturatedSubmitRunnable
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
public void testSaturatedSubmitCallable() { final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); try (PoolCleaner cleaner = cleaner(p, done)) { Runnable task = new CheckedRunnable() { public void realRun() throws InterruptedException { await(done); }}; for (int i = 0; i < 2; ++i) p.submit(Executors.callable(task)); for (int i = 0; i < 2; ++i) { try { p.execute(task); shouldThrow(); } catch (RejectedExecutionException success) {} assertTrue(p.getTaskCount() <= 2); } } }
submit(callable) throws RejectedExecutionException if saturated.
FailingThreadFactory::testSaturatedSubmitCallable
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
public void testSaturatedExecute2() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), new ThreadPoolExecutor.CallerRunsPolicy()); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch done = new CountDownLatch(1); Runnable blocker = new CheckedRunnable() { public void realRun() throws InterruptedException { await(done); }}; p.execute(blocker); TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; for (int i = 0; i < tasks.length; i++) tasks[i] = new TrackedNoOpRunnable(); for (int i = 0; i < tasks.length; i++) p.execute(tasks[i]); for (int i = 1; i < tasks.length; i++) assertTrue(tasks[i].done); assertFalse(tasks[0].done); // waiting in queue done.countDown(); } }
executor using CallerRunsPolicy runs task if saturated.
FailingThreadFactory::testSaturatedExecute2
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
public void testSaturatedExecute3() { final CountDownLatch done = new CountDownLatch(1); final TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; for (int i = 0; i < tasks.length; ++i) tasks[i] = new TrackedNoOpRunnable(); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), new ThreadPoolExecutor.DiscardPolicy()); try (PoolCleaner cleaner = cleaner(p, done)) { p.execute(awaiter(done)); for (TrackedNoOpRunnable task : tasks) p.execute(task); for (int i = 1; i < tasks.length; i++) assertFalse(tasks[i].done); } for (int i = 1; i < tasks.length; i++) assertFalse(tasks[i].done); assertTrue(tasks[0].done); // was waiting in queue }
executor using DiscardPolicy drops task if saturated.
FailingThreadFactory::testSaturatedExecute3
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
public void testSaturatedExecute4() { final CountDownLatch done = new CountDownLatch(1); LatchAwaiter r1 = awaiter(done); LatchAwaiter r2 = awaiter(done); LatchAwaiter r3 = awaiter(done); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), new ThreadPoolExecutor.DiscardOldestPolicy()); try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(LatchAwaiter.NEW, r1.state); assertEquals(LatchAwaiter.NEW, r2.state); assertEquals(LatchAwaiter.NEW, r3.state); p.execute(r1); p.execute(r2); assertTrue(p.getQueue().contains(r2)); p.execute(r3); assertFalse(p.getQueue().contains(r2)); assertTrue(p.getQueue().contains(r3)); } assertEquals(LatchAwaiter.DONE, r1.state); assertEquals(LatchAwaiter.NEW, r2.state); assertEquals(LatchAwaiter.DONE, r3.state); }
executor using DiscardOldestPolicy drops oldest task if saturated.
FailingThreadFactory::testSaturatedExecute4
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
public void testRejectedExecutionExceptionOnShutdown() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); try { p.shutdown(); } catch (SecurityException ok) { return; } try (PoolCleaner cleaner = cleaner(p)) { try { p.execute(new NoOpRunnable()); shouldThrow(); } catch (RejectedExecutionException success) {} } }
execute throws RejectedExecutionException if shutdown
FailingThreadFactory::testRejectedExecutionExceptionOnShutdown
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
public void testCallerRunsOnShutdown() { RejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy(); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), h); try { p.shutdown(); } catch (SecurityException ok) { return; } try (PoolCleaner cleaner = cleaner(p)) { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); } }
execute using CallerRunsPolicy drops task on shutdown
FailingThreadFactory::testCallerRunsOnShutdown
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
public void testDiscardOnShutdown() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), new ThreadPoolExecutor.DiscardPolicy()); try { p.shutdown(); } catch (SecurityException ok) { return; } try (PoolCleaner cleaner = cleaner(p)) { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); } }
execute using DiscardPolicy drops task on shutdown
FailingThreadFactory::testDiscardOnShutdown
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
public void testDiscardOldestOnShutdown() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1), new ThreadPoolExecutor.DiscardOldestPolicy()); try { p.shutdown(); } catch (SecurityException ok) { return; } try (PoolCleaner cleaner = cleaner(p)) { TrackedNoOpRunnable r = new TrackedNoOpRunnable(); p.execute(r); assertFalse(r.done); } }
execute using DiscardOldestPolicy drops task on shutdown
FailingThreadFactory::testDiscardOldestOnShutdown
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
public void testExecuteNull() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, 1L, SECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.execute(null); shouldThrow(); } catch (NullPointerException success) {} } }
execute(null) throws NPE
FailingThreadFactory::testExecuteNull
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
public void testCorePoolSizeIllegalArgumentException() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.setCorePoolSize(-1); shouldThrow(); } catch (IllegalArgumentException success) {} } }
setCorePoolSize of negative value throws IllegalArgumentException
FailingThreadFactory::testCorePoolSizeIllegalArgumentException
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
public void testMaximumPoolSizeIllegalArgumentException() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 3, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.setMaximumPoolSize(1); shouldThrow(); } catch (IllegalArgumentException success) {} } }
setMaximumPoolSize(int) throws IllegalArgumentException if given a value less the core pool size
FailingThreadFactory::testMaximumPoolSizeIllegalArgumentException
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
public void testMaximumPoolSizeIllegalArgumentException2() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 3, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.setMaximumPoolSize(-1); shouldThrow(); } catch (IllegalArgumentException success) {} } }
setMaximumPoolSize throws IllegalArgumentException if given a negative value
FailingThreadFactory::testMaximumPoolSizeIllegalArgumentException2
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
public void testPoolSizeInvariants() { final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { for (int s = 1; s < 5; s++) { p.setMaximumPoolSize(s); p.setCorePoolSize(s); try { p.setMaximumPoolSize(s - 1); shouldThrow(); } catch (IllegalArgumentException success) {} assertEquals(s, p.getCorePoolSize()); assertEquals(s, p.getMaximumPoolSize()); try { p.setCorePoolSize(s + 1); // Android-changed: changeset dfec9b5386ca028cc1468f3e2717120ab6274702 // disables this check for compatibility reason. // shouldThrow(); } catch (IllegalArgumentException success) {} // Android-changed: changeset dfec9b5386ca028cc1468f3e2717120ab6274702 // disables maximumpoolsize check for compatibility reason. // assertEquals(s, p.getCorePoolSize()); assertEquals(s + 1, p.getCorePoolSize()); assertEquals(s, p.getMaximumPoolSize()); } } }
Configuration changes that allow core pool size greater than max pool size result in IllegalArgumentException.
FailingThreadFactory::testPoolSizeInvariants
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
public void testKeepAliveTimeIllegalArgumentException() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 3, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { try { p.setKeepAliveTime(-1, MILLISECONDS); shouldThrow(); } catch (IllegalArgumentException success) {} } }
setKeepAliveTime throws IllegalArgumentException when given a negative value
FailingThreadFactory::testKeepAliveTimeIllegalArgumentException
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
public void testTerminated() { ExtendedTPE p = new ExtendedTPE(); try (PoolCleaner cleaner = cleaner(p)) { try { p.shutdown(); } catch (SecurityException ok) { return; } assertTrue(p.terminatedCalled()); assertTrue(p.isShutdown()); } }
terminated() is called on termination
FailingThreadFactory::testTerminated
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
public void testBeforeAfter() throws InterruptedException { ExtendedTPE p = new ExtendedTPE(); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch done = new CountDownLatch(1); p.execute(new CheckedRunnable() { public void realRun() { done.countDown(); }}); await(p.afterCalled); assertEquals(0, done.getCount()); assertTrue(p.afterCalled()); assertTrue(p.beforeCalled()); } }
beforeExecute and afterExecute are called when executing task
FailingThreadFactory::testBeforeAfter
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
public void testSubmitCallable() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testSubmitCallable
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
public void testSubmitRunnable() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(e)) { Future<?> future = e.submit(new NoOpRunnable()); future.get(); assertTrue(future.isDone()); } }
completed submit of runnable returns successfully
FailingThreadFactory::testSubmitRunnable
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
public void testSubmitRunnable2() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testSubmitRunnable2
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
public void testInvokeAny1() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(null); shouldThrow(); } catch (NullPointerException success) {} } }
invokeAny(null) throws NPE
FailingThreadFactory::testInvokeAny1
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
public void testInvokeAny2() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(new ArrayList<Callable<String>>()); shouldThrow(); } catch (IllegalArgumentException success) {} } }
invokeAny(empty collection) throws IAE
FailingThreadFactory::testInvokeAny2
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
public void testInvokeAny3() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testInvokeAny3
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
public void testInvokeAny4() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testInvokeAny4
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
public void testInvokeAny5() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testInvokeAny5
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
public void testInvokeAll1() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAll(null); shouldThrow(); } catch (NullPointerException success) {} } }
invokeAll(null) throws NPE
FailingThreadFactory::testInvokeAll1
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
public void testInvokeAll2() throws InterruptedException { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(e)) { List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>()); assertTrue(r.isEmpty()); } }
invokeAll(empty collection) returns empty collection
FailingThreadFactory::testInvokeAll2
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
public void testInvokeAll3() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testInvokeAll3
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
public void testInvokeAll4() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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 element of invokeAll(c) throws exception on failed task
FailingThreadFactory::testInvokeAll4
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
public void testInvokeAll5() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testInvokeAll5
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
public void testTimedInvokeAny1() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) {} } }
timed invokeAny(null) throws NPE
FailingThreadFactory::testTimedInvokeAny1
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
public void testTimedInvokeAnyNullTimeUnit() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAnyNullTimeUnit
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
public void testTimedInvokeAny2() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAny2
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
public void testTimedInvokeAny3() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAny3
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
public void testTimedInvokeAny4() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAny4
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
public void testTimedInvokeAny5() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAny5
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
public void testTimedInvokeAll1() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(e)) { try { e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (NullPointerException success) {} } }
timed invokeAll(null) throws NPE
FailingThreadFactory::testTimedInvokeAll1
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
public void testTimedInvokeAllNullTimeUnit() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAllNullTimeUnit
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
public void testTimedInvokeAll2() throws InterruptedException { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAll2
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
public void testTimedInvokeAll3() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAll3
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
public void testTimedInvokeAll4() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAll4
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
public void testTimedInvokeAll5() throws Exception { final ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAll5
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
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 ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); 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
FailingThreadFactory::testTimedInvokeAll6
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
public void testFailingThreadFactory() throws InterruptedException { final ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory()); try (PoolCleaner cleaner = cleaner(e)) { final int TASKS = 100; final CountDownLatch done = new CountDownLatch(TASKS); for (int k = 0; k < TASKS; ++k) e.execute(new CheckedRunnable() { public void realRun() { done.countDown(); }}); assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); } }
Execution continues if there is at least one thread even if thread factory fails to create more
FailingThreadFactory::testFailingThreadFactory
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
public void testAllowsCoreThreadTimeOut() { final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { assertFalse(p.allowsCoreThreadTimeOut()); } }
allowsCoreThreadTimeOut is by default false.
FailingThreadFactory::testAllowsCoreThreadTimeOut
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
public void testAllowCoreThreadTimeOut_true() throws Exception { long keepAliveTime = timeoutMillis(); final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 10, keepAliveTime, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch threadStarted = new CountDownLatch(1); p.allowCoreThreadTimeOut(true); p.execute(new CheckedRunnable() { public void realRun() { threadStarted.countDown(); assertEquals(1, p.getPoolSize()); }}); await(threadStarted); delay(keepAliveTime); long startTime = System.nanoTime(); while (p.getPoolSize() > 0 && millisElapsedSince(startTime) < LONG_DELAY_MS) Thread.yield(); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); assertEquals(0, p.getPoolSize()); } }
allowCoreThreadTimeOut(true) causes idle threads to time out
FailingThreadFactory::testAllowCoreThreadTimeOut_true
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
public void testAllowCoreThreadTimeOut_false() throws Exception { long keepAliveTime = timeoutMillis(); final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 10, keepAliveTime, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); try (PoolCleaner cleaner = cleaner(p)) { final CountDownLatch threadStarted = new CountDownLatch(1); p.allowCoreThreadTimeOut(false); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); assertTrue(p.getPoolSize() >= 1); }}); delay(2 * keepAliveTime); assertTrue(p.getPoolSize() >= 1); } }
allowCoreThreadTimeOut(false) causes idle threads not to time out
FailingThreadFactory::testAllowCoreThreadTimeOut_false
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