diff options
Diffstat (limited to 'guava-tests/test/com/google/common/eventbus/EventBusTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/eventbus/EventBusTest.java | 58 |
1 files changed, 6 insertions, 52 deletions
diff --git a/guava-tests/test/com/google/common/eventbus/EventBusTest.java b/guava-tests/test/com/google/common/eventbus/EventBusTest.java index 0180557..2a11784 100644 --- a/guava-tests/test/com/google/common/eventbus/EventBusTest.java +++ b/guava-tests/test/com/google/common/eventbus/EventBusTest.java @@ -16,17 +16,11 @@ package com.google.common.eventbus; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; - -import junit.framework.TestCase; - import java.util.Collection; import java.util.List; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; +import junit.framework.TestCase; /** * Test case for {@link EventBus}. @@ -47,6 +41,11 @@ public class EventBusTest extends TestCase { public void testBasicCatcherDistribution() { StringCatcher catcher = new StringCatcher(); bus.register(catcher); + + Set<EventHandler> wrappers = bus.getHandlersForEventType(String.class); + assertNotNull("Should have at least one method registered.", wrappers); + assertEquals("One method should be registered.", 1, wrappers.size()); + bus.post(EVENT); List<String> events = catcher.getEvents(); @@ -210,57 +209,12 @@ public class EventBusTest extends TestCase { expectedEvents, catcher2.getEvents()); } - // NOTE: This test will always pass if register() is thread-safe but may also - // pass if it isn't, though this is unlikely. - - public void testRegisterThreadSafety() throws Exception { - List<StringCatcher> catchers = Lists.newCopyOnWriteArrayList(); - List<Future<?>> futures = Lists.newArrayList(); - ExecutorService executor = Executors.newFixedThreadPool(10); - int numberOfCatchers = 10000; - for (int i = 0; i < numberOfCatchers; i++) { - futures.add(executor.submit(new Registrator(bus, catchers))); - } - for (int i = 0; i < numberOfCatchers; i++) { - futures.get(i).get(); - } - assertEquals("Unexpected number of catchers in the list", - numberOfCatchers, catchers.size()); - bus.post(EVENT); - List<String> expectedEvents = ImmutableList.of(EVENT); - for (StringCatcher catcher : catchers) { - assertEquals("One of the registered catchers did not receive an event.", - expectedEvents, catcher.getEvents()); - } - } - private <T> void assertContains(T element, Collection<T> collection) { assertTrue("Collection must contain " + element, collection.contains(element)); } /** - * Runnable which registers a StringCatcher on an event bus and adds it to a - * list. - */ - private static class Registrator implements Runnable { - private final EventBus bus; - private final List<StringCatcher> catchers; - - Registrator(EventBus bus, List<StringCatcher> catchers) { - this.bus = bus; - this.catchers = catchers; - } - - @Override - public void run() { - StringCatcher catcher = new StringCatcher(); - bus.register(catcher); - catchers.add(catcher); - } - } - - /** * A collector for DeadEvents. * * @author cbiffle |