Search in sources :

Example 1 with ExtensionNotification

use of org.mule.runtime.api.notification.ExtensionNotification in project mule by mulesoft.

the class ExtensionNotificationsTestCase method sourceFiresNotificationsOnBackPressure.

@Test
public void sourceFiresNotificationsOnBackPressure() throws Exception {
    Latch latch = new Latch();
    String batchFailed = "BATCH_FAILED";
    setUpListener(notification -> {
        if (batchFailed.equals(notification.getAction().getIdentifier())) {
            latch.release();
        }
    });
    Flow flow = (Flow) getFlowConstruct("sourceNotificationsBackPressure");
    flow.start();
    latch.await(10000, MILLISECONDS);
    flow.stop();
    assertThat(listener.getNotifications(), hasSize(greaterThan(3)));
    // Find first BATCH_FAILED
    ExtensionNotification backPressureNotification = listener.getNotifications().stream().filter(n -> batchFailed.equals(n.getAction().getIdentifier())).findFirst().get();
    // Find matching event notifications
    List<ExtensionNotification> notifications = listener.getNotifications().stream().filter(n -> backPressureNotification.getEvent().getCorrelationId().equals(n.getEvent().getCorrelationId())).collect(toList());
    assertThat(notifications, hasSize(4));
    int batchNumber = (Integer) backPressureNotification.getData().getValue();
    ExtensionNotification notification1 = notifications.get(0);
    verifyNewBatch(notification1, batchNumber);
    ExtensionNotification notification2 = notifications.get(1);
    verifyNextBatch(notification2, 10L);
    ExtensionNotification notification3 = notifications.get(2);
    verifyNotificationAndValue(notification3, batchFailed, batchNumber);
    ExtensionNotification notification4 = notifications.get(3);
    verifyBatchTerminated(notification4, batchNumber);
}
Also used : PersonalInfo(org.mule.test.heisenberg.extension.model.PersonalInfo) AbstractExtensionFunctionalTestCase(org.mule.test.module.extension.AbstractExtensionFunctionalTestCase) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ExtensionNotificationListener(org.mule.runtime.api.notification.ExtensionNotificationListener) ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) Flow(org.mule.runtime.core.api.construct.Flow) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) Consumer(java.util.function.Consumer) Inject(javax.inject.Inject) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Collectors.toList(java.util.stream.Collectors.toList) Latch(org.mule.runtime.api.util.concurrent.Latch) List(java.util.List) SimpleKnockeableDoor(org.mule.test.heisenberg.extension.model.SimpleKnockeableDoor) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) LinkedList(java.util.LinkedList) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) CountDownLatch(java.util.concurrent.CountDownLatch) Latch(org.mule.runtime.api.util.concurrent.Latch) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 2 with ExtensionNotification

use of org.mule.runtime.api.notification.ExtensionNotification in project mule by mulesoft.

the class ExtensionNotificationsTestCase method sourceFiresNotificationsOnSuccess.

@Test
public void sourceFiresNotificationsOnSuccess() throws Exception {
    CountDownLatch latch = new CountDownLatch(4);
    setUpListener(notification -> latch.countDown());
    Flow flow = (Flow) getFlowConstruct("sourceNotifications");
    flow.start();
    latch.await(4000, MILLISECONDS);
    assertThat(listener.getNotifications(), hasSize(4));
    ExtensionNotification notification1 = listener.getNotifications().get(0);
    verifyNewBatch(notification1, 1);
    String correlationId = notification1.getEvent().getCorrelationId();
    ExtensionNotification notification2 = listener.getNotifications().get(1);
    verifyNextBatch(notification2, 100000L);
    assertThat(notification2.getEvent().getCorrelationId(), is(correlationId));
    ExtensionNotification notification3 = listener.getNotifications().get(2);
    verifyNotificationAndValue(notification3, "BATCH_DELIVERED", 100L);
    assertThat(notification3.getEvent().getCorrelationId(), is(correlationId));
    ExtensionNotification notification4 = listener.getNotifications().get(3);
    verifyBatchTerminated(notification4, 1);
    assertThat(notification4.getEvent().getCorrelationId(), is(correlationId));
}
Also used : ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) CountDownLatch(java.util.concurrent.CountDownLatch) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 3 with ExtensionNotification

use of org.mule.runtime.api.notification.ExtensionNotification in project mule by mulesoft.

the class ExtensionNotificationsTestCase method sourceFiresNotificationsOnError.

@Test
public void sourceFiresNotificationsOnError() throws Exception {
    CountDownLatch latch = new CountDownLatch(4);
    setUpListener(notification -> latch.countDown());
    Flow flow = (Flow) getFlowConstruct("sourceNotificationsError");
    flow.start();
    latch.await(4000, MILLISECONDS);
    assertThat(listener.getNotifications(), hasSize(4));
    ExtensionNotification notification1 = listener.getNotifications().get(0);
    verifyNewBatch(notification1, 1);
    String correlationId = notification1.getEvent().getCorrelationId();
    ExtensionNotification notification2 = listener.getNotifications().get(1);
    verifyNextBatch(notification2, 100000L);
    assertThat(notification2.getEvent().getCorrelationId(), is(correlationId));
    ExtensionNotification notification3 = listener.getNotifications().get(2);
    assertThat(notification3.getAction().getNamespace(), is(HEISENBERG));
    assertThat(notification3.getAction().getIdentifier(), is("BATCH_DELIVERY_FAILED"));
    assertThat(notification3.getData().getValue(), instanceOf(PersonalInfo.class));
    assertThat(((PersonalInfo) notification3.getData().getValue()).getAge(), is(27));
    assertThat(notification3.getEvent().getCorrelationId(), is(correlationId));
    ExtensionNotification notification4 = listener.getNotifications().get(3);
    verifyBatchTerminated(notification4, 1);
    assertThat(notification4.getEvent().getCorrelationId(), is(correlationId));
}
Also used : ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) PersonalInfo(org.mule.test.heisenberg.extension.model.PersonalInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 4 with ExtensionNotification

use of org.mule.runtime.api.notification.ExtensionNotification in project mule by mulesoft.

the class ExtensionNotificationsTestCase method operationFiresNotificationsWithCustomData.

@Test
public void operationFiresNotificationsWithCustomData() throws Exception {
    CountDownLatch latch = new CountDownLatch(2);
    setUpListener(notification -> latch.countDown());
    String correlationId = flowRunner("operationNotification").run().getCorrelationId();
    latch.await(2000, MILLISECONDS);
    assertThat(listener.getNotifications(), hasSize(2));
    ExtensionNotification notification1 = listener.getNotifications().get(0);
    assertThat(notification1.getAction().getNamespace(), is(HEISENBERG));
    assertThat(notification1.getAction().getIdentifier(), is("KNOCKING_DOOR"));
    assertThat(notification1.getData().getValue(), instanceOf(SimpleKnockeableDoor.class));
    assertThat(((SimpleKnockeableDoor) notification1.getData().getValue()).getSimpleName(), is("Top Level Skyler @ 308 Negra Arroyo Lane"));
    assertThat(notification1.getEvent().getCorrelationId(), is(correlationId));
    ExtensionNotification notification2 = listener.getNotifications().get(1);
    assertThat(notification2.getAction().getNamespace(), is(HEISENBERG));
    assertThat(notification2.getAction().getIdentifier(), is("KNOCKED_DOOR"));
    assertThat(notification2.getData().getValue(), instanceOf(SimpleKnockeableDoor.class));
    assertThat(((SimpleKnockeableDoor) notification2.getData().getValue()).getSimpleName(), is("Top Level Skyler @ 308 Negra Arroyo Lane"));
    assertThat(notification2.getEvent().getCorrelationId(), is(correlationId));
}
Also used : ExtensionNotification(org.mule.runtime.api.notification.ExtensionNotification) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleKnockeableDoor(org.mule.test.heisenberg.extension.model.SimpleKnockeableDoor) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)4 Test (org.junit.Test)4 ExtensionNotification (org.mule.runtime.api.notification.ExtensionNotification)4 Flow (org.mule.runtime.core.api.construct.Flow)3 PersonalInfo (org.mule.test.heisenberg.extension.model.PersonalInfo)2 SimpleKnockeableDoor (org.mule.test.heisenberg.extension.model.SimpleKnockeableDoor)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 Consumer (java.util.function.Consumer)1 Collectors.toList (java.util.stream.Collectors.toList)1 Inject (javax.inject.Inject)1 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)1 Matchers.is (org.hamcrest.Matchers.is)1 Assert.assertThat (org.junit.Assert.assertThat)1 ExtensionNotificationListener (org.mule.runtime.api.notification.ExtensionNotificationListener)1 NotificationListenerRegistry (org.mule.runtime.api.notification.NotificationListenerRegistry)1 Latch (org.mule.runtime.api.util.concurrent.Latch)1