Search in sources :

Example 11 with SimpleNotificationListener

use of com.adaptris.core.runtime.SimpleNotificationListener in project interlok by adaptris.

the class MessageThresholdNotificationTest method testNotification_SizeThresholdNotExceeded.

@Test
public void testNotification_SizeThresholdNotExceeded() throws Exception {
    MessageThresholdNotification notif = new MessageThresholdNotification(getName());
    notif.setSizeThreshold(100L);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
    } finally {
        stop(adapter);
    }
    assertEquals(0, listener.getNotifications().size());
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 12 with SimpleNotificationListener

use of com.adaptris.core.runtime.SimpleNotificationListener in project interlok by adaptris.

the class MessageThresholdNotificationTest method testNotification_CountThresholdNotExceeded.

@Test
public void testNotification_CountThresholdNotExceeded() throws Exception {
    MessageThresholdNotification notif = new MessageThresholdNotification(getName());
    notif.setCountThreshold(100L);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
        workflow.onAdaptrisMessage(msg);
    } finally {
        stop(adapter);
    }
    assertEquals(0, listener.getNotifications().size());
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 13 with SimpleNotificationListener

use of com.adaptris.core.runtime.SimpleNotificationListener in project interlok by adaptris.

the class SlowMessageNotificationTest method testNotification_SlowMessage_Success.

@Test
public void testNotification_SlowMessage_Success() throws Exception {
    SlowMessageNotification notif = new SlowMessageNotification(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS), new TimeInterval(1L, TimeUnit.MINUTES));
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        workflow.onAdaptrisMessage(msg);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        Properties userData = (Properties) notification.getUserData();
        assertEquals(msg.getUniqueId(), userData.getProperty(SlowMessageNotification.KEY_MESSAGE_ID));
    // assertEquals("true", userData.getProperty(SlowMessageNotification.KEY_MESSAGE_SUCCESS));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) WaitService(com.adaptris.core.services.WaitService) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Properties(java.util.Properties) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 14 with SimpleNotificationListener

use of com.adaptris.core.runtime.SimpleNotificationListener in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_BelowThreshold_MaxExceeded.

@Test
public void testNotification_BelowThreshold_MaxExceeded() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    notif.setMessageCount(2);
    notif.setMaxNotifications(1);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
        submitWithDelay(msg, workflow, 6, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 0);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 0);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 0);
        listener.waitForMessages(2);
        assertEquals(2, listener.getNotifications().size());
        Notification n1 = listener.getNotifications().get(0);
        Notification n2 = listener.getNotifications().get(1);
        assertTrue(n1.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_ABOVE_THRESHOLD));
        assertTrue(n2.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_BELOW_THRESHOLD));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 15 with SimpleNotificationListener

use of com.adaptris.core.runtime.SimpleNotificationListener in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_StaysBelowThreshold.

@Test
public void testNotification_StaysBelowThreshold() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(1L, TimeUnit.SECONDS));
    notif.setMessageCount(5);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
        submitWithDelay(msg, workflow, 1, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 5);
    } finally {
        stop(adapter);
    }
    assertEquals(0, listener.getNotifications().size());
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

Adapter (com.adaptris.core.Adapter)16 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)16 StandardWorkflow (com.adaptris.core.StandardWorkflow)16 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)16 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)16 ObjectName (javax.management.ObjectName)16 Test (org.junit.Test)16 Notification (javax.management.Notification)10 TimeInterval (com.adaptris.util.TimeInterval)9 Properties (java.util.Properties)6 AlwaysFailService (com.adaptris.core.services.AlwaysFailService)3 WaitService (com.adaptris.core.services.WaitService)3