Search in sources :

Example 96 with AdaptrisMessage

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

the class MessageMetricsInterceptorTest method testProduceAfterNewTimeSlice.

@Test
public void testProduceAfterNewTimeSlice() throws Exception {
    ProducingStatisticManager producingStatisticManager = new ProducingStatisticManager();
    producingStatisticManager.setMarshaller(mockMarshaller);
    producingStatisticManager.setProducer(mockStandaloneProducer);
    metricsInterceptor.setStatisticManager(producingStatisticManager);
    LifecycleHelper.init(metricsInterceptor);
    LifecycleHelper.start(metricsInterceptor);
    AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
    // A minus time will expire the time slice immediately after the first message
    metricsInterceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS));
    assertEquals(0, metricsInterceptor.getStats().size());
    submitMessage(message);
    assertEquals(1, metricsInterceptor.getStats().size());
    submitMessage(message);
    verify(mockMarshaller).marshal(any());
    verify(mockStandaloneProducer).produce(any());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 97 with AdaptrisMessage

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

the class MetadataTotalsInterceptorTest method testNoProduceBeforeNewTimeSlice.

@Test
public void testNoProduceBeforeNewTimeSlice() throws Exception {
    ProducingStatisticManager producingStatisticManager = new ProducingStatisticManager();
    producingStatisticManager.setMarshaller(mockMarshaller);
    producingStatisticManager.setProducer(mockStandaloneProducer);
    metricsInterceptor.setStatisticManager(producingStatisticManager);
    LifecycleHelper.init(metricsInterceptor);
    LifecycleHelper.start(metricsInterceptor);
    AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
    // A minus time will expire the time slice immediately after the first message
    metricsInterceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS));
    assertEquals(0, metricsInterceptor.getStats().size());
    submitMessage(message);
    assertEquals(1, metricsInterceptor.getStats().size());
    verify(mockMarshaller, times(0)).marshal(any());
    verify(mockStandaloneProducer, times(0)).produce(any());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 98 with AdaptrisMessage

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

the class SlowMessageNotificationTest method testNotification_SentAsPartOfCleanup.

@Test
public void testNotification_SentAsPartOfCleanup() throws Exception {
    SlowMessageNotification notif = new SlowMessageNotification(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)));
    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("-1", userData.getProperty(SlowMessageNotification.KEY_MESSAGE_DURATION));
        assertEquals("-1", userData.getProperty(SlowMessageNotification.KEY_MESSAGE_END));
        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) 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 99 with AdaptrisMessage

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

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

the class PooledConnectionHelper method executeTest.

public static void executeTest(List<Service> serviceList, final int iterations, final MessageCreator creator) throws Exception {
    MyExceptionHandler handler = new MyExceptionHandler();
    List<Thread> threads = new ArrayList<>();
    for (final Service s : serviceList) {
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    for (int j = 0; j < iterations; j++) {
                        final AdaptrisMessage msg = creator.createMsgForPooledConnectionTest();
                        s.doService(msg);
                        TimeUnit.MILLISECONDS.sleep(DEFAULT_PAUSE.toMilliseconds());
                    }
                } catch (Exception e) {
                    Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
                }
            }
        });
        t.setUncaughtExceptionHandler(handler);
        threads.add(t);
        t.start();
    }
    for (Thread t : threads) {
        if (t.isAlive())
            t.join();
    }
    if (handler.hasError()) {
        throw handler.lastCaughtException();
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) Service(com.adaptris.core.Service)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1495 Test (org.junit.Test)1362 ServiceException (com.adaptris.core.ServiceException)171 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)158 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)156 StandaloneProducer (com.adaptris.core.StandaloneProducer)125 Channel (com.adaptris.core.Channel)122 MetadataElement (com.adaptris.core.MetadataElement)94 File (java.io.File)89 TimeInterval (com.adaptris.util.TimeInterval)77 CoreException (com.adaptris.core.CoreException)67 Session (javax.jms.Session)62 StandardWorkflow (com.adaptris.core.StandardWorkflow)57 GuidGenerator (com.adaptris.util.GuidGenerator)56 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)49 Message (javax.jms.Message)47 XPath (com.adaptris.util.text.xml.XPath)45 ServiceList (com.adaptris.core.ServiceList)43 Document (org.w3c.dom.Document)40