Search in sources :

Example 1 with BuggyListener

use of org.motechproject.event.domain.BuggyListener 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 BuggyListener

use of org.motechproject.event.domain.BuggyListener 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)

Example 3 with BuggyListener

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

the class ServerEventRelayTest method shouldPreserveEventDestinationIfListenerFails.

@Test
public void shouldPreserveEventDestinationIfListenerFails() {
    when(motechEventConfig.getMessageMaxRedeliveryCount()).thenReturn(2);
    BuggyListener buggyListener = new BuggyListener(1);
    setUpListeners(SUBJECT, buggyListener);
    MotechEvent event = createEvent(buggyListener.getIdentifier());
    eventRelay.relayQueueEvent(event);
    assertThat(event.getMessageDestination().toString(), is(buggyListener.getIdentifier()));
}
Also used : BuggyListener(org.motechproject.event.domain.BuggyListener) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Aggregations

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