Search in sources :

Example 1 with TrackingListener

use of org.motechproject.event.domain.TrackingListener in project motech by motech.

the class ServerEventRelayBundleIT method shouldTriggerAllListenersIfOneListenerFailsWhenRelyingTopicEvent.

@Test
public void shouldTriggerAllListenersIfOneListenerFailsWhenRelyingTopicEvent() throws InterruptedException {
    TrackingListener buggyListener = new BuggyListener(1);
    TrackingListener firstGoodListener = new TrackingListener("first");
    TrackingListener secondGoodListener = new TrackingListener("second");
    eventListenerRegistry.registerListener(buggyListener, EXCEPTION_HANDLING_TEST);
    eventListenerRegistry.registerListener(firstGoodListener, EXCEPTION_HANDLING_TEST);
    eventListenerRegistry.registerListener(secondGoodListener, EXCEPTION_HANDLING_TEST);
    MotechEvent testMessage = new MotechEvent(EXCEPTION_HANDLING_TEST);
    eventRelay.broadcastEventMessage(testMessage);
    while (buggyListener.getCount() < 2) {
        Thread.sleep(1000);
    }
    Thread.sleep(2000);
    assertEquals(firstGoodListener.getCount(), 1);
    assertEquals(secondGoodListener.getCount(), 1);
}
Also used : BuggyListener(org.motechproject.event.domain.BuggyListener) TrackingListener(org.motechproject.event.domain.TrackingListener) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 2 with TrackingListener

use of org.motechproject.event.domain.TrackingListener in project motech by motech.

the class ServerEventRelayBundleIT method shouldNotTriggerAllListenersWhenOneListenerFails.

@Test
public void shouldNotTriggerAllListenersWhenOneListenerFails() throws InterruptedException {
    TrackingListener buggyListener = new BuggyListener(1);
    TrackingListener firstGoodListener = new TrackingListener("first");
    TrackingListener secondGoodListener = new TrackingListener("second");
    eventListenerRegistry.registerListener(buggyListener, EXCEPTION_HANDLING_TEST);
    eventListenerRegistry.registerListener(firstGoodListener, EXCEPTION_HANDLING_TEST);
    eventListenerRegistry.registerListener(secondGoodListener, EXCEPTION_HANDLING_TEST);
    MotechEvent testMessage = new MotechEvent(EXCEPTION_HANDLING_TEST);
    eventRelay.sendEventMessage(testMessage);
    while (buggyListener.getCount() < 2) {
        Thread.sleep(3000);
    }
    assertTrue(buggyListener.getCount() > 1);
    Thread.sleep(2000);
    assertEquals(1, firstGoodListener.getCount());
    assertEquals(1, secondGoodListener.getCount());
}
Also used : BuggyListener(org.motechproject.event.domain.BuggyListener) TrackingListener(org.motechproject.event.domain.TrackingListener) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 MotechEvent (org.motechproject.event.MotechEvent)2 BuggyListener (org.motechproject.event.domain.BuggyListener)2 TrackingListener (org.motechproject.event.domain.TrackingListener)2