Search in sources :

Example 1 with AlwaysFailService

use of com.adaptris.core.services.AlwaysFailService in project interlok by adaptris.

the class SlowMessageNotificationTest method testNotification_SlowMessage_Failure.

@Test
public void testNotification_SlowMessage_Failure() throws Exception {
    SlowMessageNotification notif = new SlowMessageNotification(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)));
    workflow.getServiceCollection().add(new AlwaysFailService());
    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("false", 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) Adapter(com.adaptris.core.Adapter) Properties(java.util.Properties) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) AlwaysFailService(com.adaptris.core.services.AlwaysFailService) Test(org.junit.Test)

Example 2 with AlwaysFailService

use of com.adaptris.core.services.AlwaysFailService in project interlok by adaptris.

the class MessageThresholdNotificationTest method testNotification_ErrorThresholdNotExceeded.

@Test
public void testNotification_ErrorThresholdNotExceeded() throws Exception {
    MessageThresholdNotification notif = new MessageThresholdNotification(getName());
    notif.setErrorThreshold(100L);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new AlwaysFailService());
    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) AlwaysFailService(com.adaptris.core.services.AlwaysFailService) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 3 with AlwaysFailService

use of com.adaptris.core.services.AlwaysFailService in project interlok by adaptris.

the class PoolingMessageSplitterServiceTest method testServiceWithFailures.

@Test
public void testServiceWithFailures() throws Exception {
    PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new AlwaysFailService()).withWaitWhileBusy(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
    XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AlwaysFailService(com.adaptris.core.services.AlwaysFailService) Test(org.junit.Test)

Example 4 with AlwaysFailService

use of com.adaptris.core.services.AlwaysFailService in project interlok by adaptris.

the class MessageThresholdNotificationTest method testNotification_ErrorThresholdExceeded.

@Test
public void testNotification_ErrorThresholdExceeded() throws Exception {
    MessageThresholdNotification notif = new MessageThresholdNotification(getName());
    notif.setErrorThreshold(0L);
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new AlwaysFailService());
    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);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        Properties userData = (Properties) notification.getUserData();
        assertEquals("11", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_SIZE));
        assertEquals("1", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_COUNT));
        assertEquals("1", userData.getProperty(MessageThresholdNotification.KEY_MESSAGE_ERROR));
    } finally {
        stop(adapter);
    }
}
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) Properties(java.util.Properties) Notification(javax.management.Notification) AlwaysFailService(com.adaptris.core.services.AlwaysFailService) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 AlwaysFailService (com.adaptris.core.services.AlwaysFailService)4 Test (org.junit.Test)4 Adapter (com.adaptris.core.Adapter)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)3 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)3 ObjectName (javax.management.ObjectName)3 Properties (java.util.Properties)2 Notification (javax.management.Notification)2 ServiceException (com.adaptris.core.ServiceException)1 WaitService (com.adaptris.core.services.WaitService)1 TimeInterval (com.adaptris.util.TimeInterval)1