Search in sources :

Example 6 with EventTopic

use of org.apache.cloudstack.framework.events.EventTopic in project cloudstack by apache.

the class InMemoryEventBusTest method testPublish.

@Test
public void testPublish() throws Exception {
    EventTopic topic = mock(EventTopic.class);
    EventSubscriber subscriber = mock(EventSubscriber.class);
    Event event = mock(Event.class);
    InMemoryEventBus bus = new InMemoryEventBus();
    UUID uuid = bus.subscribe(topic, subscriber);
    assertNotNull(uuid);
    String uuidStr = uuid.toString();
    assertTrue(UuidUtils.validateUUID(uuidStr));
    assertTrue(bus.totalSubscribers() == 1);
    bus.publish(event);
    verify(subscriber, times(1)).onEvent(event);
    bus.unsubscribe(uuid, subscriber);
    assertTrue(bus.totalSubscribers() == 0);
}
Also used : EventSubscriber(org.apache.cloudstack.framework.events.EventSubscriber) EventTopic(org.apache.cloudstack.framework.events.EventTopic) Event(org.apache.cloudstack.framework.events.Event) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

EventTopic (org.apache.cloudstack.framework.events.EventTopic)6 UUID (java.util.UUID)5 EventSubscriber (org.apache.cloudstack.framework.events.EventSubscriber)5 Test (org.junit.Test)4 Event (org.apache.cloudstack.framework.events.Event)1 EventBusException (org.apache.cloudstack.framework.events.EventBusException)1