Search in sources :

Example 6 with Adapter

use of com.adaptris.core.Adapter 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 7 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_BelowThreshold.

@Test
public void testNotification_BelowThreshold() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    notif.setMessageCount(2);
    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(3);
        assertEquals(3, 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 8 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_AboveThreshold.

@Test
public void testNotification_AboveThreshold() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    notif.setMessageCount(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, 5);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        assertTrue(notification.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_ABOVE_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 9 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class MessageCountNotificationTest method testNotification_AboveThreshold_MaxExceeded.

@Test
public void testNotification_AboveThreshold_MaxExceeded() throws Exception {
    MessageCountNotification notif = new MessageCountNotification(getName(), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    notif.setMessageCount(1);
    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();
    System.err.println(notifObjName);
    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, 10, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 6, 5);
        LifecycleHelper.waitQuietly(200);
        submitWithDelay(msg, workflow, 1, 0);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        assertTrue(notification.getMessage().startsWith(MessageCountNotification.NOTIF_MESSAGE_ABOVE_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 10 with Adapter

use of com.adaptris.core.Adapter in project interlok by adaptris.

the class MessageThresholdNotificationTest method testNotification_SizeThresholdExceeded.

@Test
public void testNotification_SizeThresholdExceeded() throws Exception {
    MessageThresholdNotification notif = new MessageThresholdNotification(getName());
    notif.setSizeThreshold(1L);
    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);
        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("0", 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) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

Adapter (com.adaptris.core.Adapter)342 Test (org.junit.Test)318 ObjectName (javax.management.ObjectName)234 Channel (com.adaptris.core.Channel)136 StandardWorkflow (com.adaptris.core.StandardWorkflow)93 ArrayList (java.util.ArrayList)80 URLString (com.adaptris.util.URLString)48 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)47 Properties (java.util.Properties)46 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)43 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)41 Workflow (com.adaptris.core.Workflow)40 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)40 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)38 File (java.io.File)37 CoreException (com.adaptris.core.CoreException)32 Notification (javax.management.Notification)28 TimeInterval (com.adaptris.util.TimeInterval)26 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)25 NullConnection (com.adaptris.core.NullConnection)21