Search in sources :

Example 11 with EventSubscriber

use of org.apache.cloudstack.framework.events.EventSubscriber 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

EventSubscriber (org.apache.cloudstack.framework.events.EventSubscriber)11 UUID (java.util.UUID)7 Test (org.junit.Test)6 EventTopic (org.apache.cloudstack.framework.events.EventTopic)5 Channel (com.rabbitmq.client.Channel)3 IOException (java.io.IOException)3 Event (org.apache.cloudstack.framework.events.Event)3 EventBusException (org.apache.cloudstack.framework.events.EventBusException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 AlreadyClosedException (com.rabbitmq.client.AlreadyClosedException)2 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)2 ConnectException (java.net.ConnectException)2 ConfigurationException (javax.naming.ConfigurationException)2 Ternary (com.cloud.utils.Ternary)1 AMQP (com.rabbitmq.client.AMQP)1 Connection (com.rabbitmq.client.Connection)1 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)1 Envelope (com.rabbitmq.client.Envelope)1