aboutsummaryrefslogtreecommitdiffstats
path: root/guava-tests/test/com/google/common/util/concurrent/ExecutionListTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/util/concurrent/ExecutionListTest.java')
-rw-r--r--guava-tests/test/com/google/common/util/concurrent/ExecutionListTest.java64
1 files changed, 13 insertions, 51 deletions
diff --git a/guava-tests/test/com/google/common/util/concurrent/ExecutionListTest.java b/guava-tests/test/com/google/common/util/concurrent/ExecutionListTest.java
index 92d9768..a4a2a8d 100644
--- a/guava-tests/test/com/google/common/util/concurrent/ExecutionListTest.java
+++ b/guava-tests/test/com/google/common/util/concurrent/ExecutionListTest.java
@@ -27,7 +27,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
/**
* Unit tests for {@link ExecutionList}.
@@ -37,10 +36,10 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class ExecutionListTest extends TestCase {
- private final ExecutionList list = new ExecutionList();
+ protected ExecutionList list = new ExecutionList();
+ protected Executor exec = Executors.newCachedThreadPool();
public void testRunOnPopulatedList() throws Exception {
- Executor exec = Executors.newCachedThreadPool();
CountDownLatch countDownLatch = new CountDownLatch(3);
list.add(new MockRunnable(countDownLatch), exec);
list.add(new MockRunnable(countDownLatch), exec);
@@ -53,56 +52,13 @@ public class ExecutionListTest extends TestCase {
assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
}
- public void testExecute_idempotent() {
- final AtomicInteger runCalled = new AtomicInteger();
- list.add(new Runnable() {
- @Override public void run() {
- runCalled.getAndIncrement();
- }
- }, MoreExecutors.sameThreadExecutor());
- list.execute();
- assertEquals(1, runCalled.get());
- list.execute();
- assertEquals(1, runCalled.get());
- }
-
- public void testExecute_idempotentConcurrently() throws InterruptedException {
- final CountDownLatch okayToRun = new CountDownLatch(1);
- final AtomicInteger runCalled = new AtomicInteger();
- list.add(new Runnable() {
- @Override public void run() {
- try {
- okayToRun.await();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new RuntimeException(e);
- }
- runCalled.getAndIncrement();
- }
- }, MoreExecutors.sameThreadExecutor());
- Runnable execute = new Runnable() {
- @Override public void run() {
- list.execute();
- }
- };
- Thread thread1 = new Thread(execute);
- Thread thread2 = new Thread(execute);
- thread1.start();
- thread2.start();
- assertEquals(0, runCalled.get());
- okayToRun.countDown();
- thread1.join();
- thread2.join();
- assertEquals(1, runCalled.get());
- }
-
public void testAddAfterRun() throws Exception {
// Run the previous test
testRunOnPopulatedList();
// If it passed, then verify an Add will be executed without calling run
CountDownLatch countDownLatch = new CountDownLatch(1);
- list.add(new MockRunnable(countDownLatch), Executors.newCachedThreadPool());
+ list.add(new MockRunnable(countDownLatch), exec);
assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
}
@@ -113,19 +69,24 @@ public class ExecutionListTest extends TestCase {
this.countDownLatch = countDownLatch;
}
- @Override public void run() {
+ @Override
+ public void run() {
countDownLatch.countDown();
}
}
public void testExceptionsCaught() {
+ ExecutionList list = new ExecutionList();
list.add(THROWING_RUNNABLE, sameThreadExecutor());
list.execute();
list.add(THROWING_RUNNABLE, sameThreadExecutor());
}
- public void testNulls() {
- new NullPointerTester().testAllPublicInstanceMethods(new ExecutionList());
+ public void testNulls() throws Exception {
+ NullPointerTester tester = new NullPointerTester();
+ tester.setDefault(Executor.class, sameThreadExecutor());
+ tester.setDefault(Runnable.class, DO_NOTHING);
+ tester.testAllPublicInstanceMethods(new ExecutionList());
}
private static final Runnable THROWING_RUNNABLE = new Runnable() {
@@ -134,6 +95,7 @@ public class ExecutionListTest extends TestCase {
}
};
private static final Runnable DO_NOTHING = new Runnable() {
- @Override public void run() {}
+ @Override public void run() {
+ }
};
}