Search in sources :

Example 11 with PoolingWorkflow

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

the class WorkflowManagerTest method testJettyInterceptor_AutoAdded.

@Test
public void testJettyInterceptor_AutoAdded() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel channel = createChannel("c1");
    ChannelManager channelManager = new ChannelManager(channel, adapterManager);
    PoolingWorkflow workflow = new PoolingWorkflow("w1");
    workflow.setConsumer(new JettyMessageConsumer());
    new WorkflowManager(workflow, channelManager);
    assertEquals(3, workflow.getInterceptors().size());
    assertEquals(MessageMetricsInterceptor.class, workflow.getInterceptors().get(0).getClass());
    assertEquals(InFlightWorkflowInterceptor.class, workflow.getInterceptors().get(1).getClass());
    assertEquals(JettyPoolingWorkflowInterceptor.class, workflow.getInterceptors().get(2).getClass());
}
Also used : Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Test(org.junit.Test)

Example 12 with PoolingWorkflow

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

the class JettyNoBacklogInterceptor method init.

@Override
public void init() throws CoreException {
    Workflow w = parentWorkflow();
    if (PoolingWorkflow.class.isAssignableFrom(w.getClass())) {
        maxWorkers = ((PoolingWorkflow) w).poolSize();
    }
    log.trace("503 Server Error will be sent when there are {} messages in flight", maxWorkers);
}
Also used : PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Workflow(com.adaptris.core.Workflow)

Example 13 with PoolingWorkflow

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

the class ChannelManagerTest method testMBean_NotificationOnRemoveWorkflow.

@Test
public void testMBean_NotificationOnRemoveWorkflow() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    String workflowXml = DefaultMarshaller.getDefaultMarshaller().marshal(new PoolingWorkflow(getName() + "_wf1"));
    Channel channel = createChannel(getName() + "_1");
    StandardWorkflow workflow = createWorkflow(getName() + "_1");
    channel.getWorkflowList().add(workflow);
    ChannelManager child1 = new ChannelManager(channel, adapterManager);
    SimpleNotificationListener listener = new SimpleNotificationListener();
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(NOTIF_TYPE_CHANNEL_CONFIG);
    ObjectName adapterObj = adapterManager.createObjectName();
    ObjectName channelObj = child1.createObjectName();
    try {
        adapterManager.registerMBean();
        mBeanServer.addNotificationListener(channelObj, listener, null, null);
        ChannelManagerMBean channelManagerProxy = JMX.newMBeanProxy(mBeanServer, channelObj, ChannelManagerMBean.class);
        channelManagerProxy.removeWorkflow(workflow.getUniqueId());
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification n = listener.getNotifications().get(0);
        assertEquals(NOTIF_TYPE_CHANNEL_CONFIG, n.getType());
        assertEquals(NOTIF_MSG_CONFIG_UPDATED, n.getMessage());
        assertEquals(channelManagerProxy.getConfiguration(), n.getUserData());
    } finally {
        mBeanServer.removeNotificationListener(channelObj, listener);
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) NotificationFilterSupport(javax.management.NotificationFilterSupport) Adapter(com.adaptris.core.Adapter) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 14 with PoolingWorkflow

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

the class MessagesInFlightTest method testInFlightMessageCount.

@Test
public void testInFlightMessageCount() throws Exception {
    PoolingWorkflow workflow = new PoolingWorkflow(getName());
    Adapter adapter = buildAdapter(workflow);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        ObjectName objName = createInFlightObjectName(adapterManager);
        MessageInFlightMBean mbean = JMX.newMBeanProxy(mBeanServer, objName, MessageInFlightMBean.class);
        assertNotNull(mbean);
        assertEquals(0, mbean.messagesInFlightCount());
        adapterManager.requestStart();
        workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        LifecycleHelper.waitQuietly(100L);
        assertEquals(1, mbean.messagesInFlightCount());
        assertTrue(mbean.messagesInFlight());
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : MessageInFlightMBean(com.adaptris.core.interceptor.MessageInFlightMBean) Adapter(com.adaptris.core.Adapter) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 15 with PoolingWorkflow

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

the class MessagesInFlightTest method testPendingMessageCount.

@Test
public void testPendingMessageCount() throws Exception {
    final PoolingWorkflow workflow = new PoolingWorkflow(getName());
    Adapter adapter = buildAdapter(workflow);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        ObjectName objName = createInFlightObjectName(adapterManager);
        MessageInFlightMBean mbean = JMX.newMBeanProxy(mBeanServer, objName, MessageInFlightMBean.class);
        assertNotNull(mbean);
        assertEquals(0, mbean.messagesInFlightCount());
        adapterManager.requestStart();
        workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        new Thread(new Runnable() {

            @Override
            public void run() {
                workflow.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
            }
        }).start();
        LifecycleHelper.waitQuietly(200L);
        assertEquals(1, mbean.messagesInFlightCount());
        assertTrue(mbean.messagesInFlight());
        assertEquals(1, mbean.messagesPendingCount());
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : MessageInFlightMBean(com.adaptris.core.interceptor.MessageInFlightMBean) Adapter(com.adaptris.core.Adapter) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

PoolingWorkflow (com.adaptris.core.PoolingWorkflow)21 Test (org.junit.Test)17 Channel (com.adaptris.core.Channel)15 TimeInterval (com.adaptris.util.TimeInterval)10 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)9 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)8 WaitService (com.adaptris.core.services.WaitService)8 Adapter (com.adaptris.core.Adapter)7 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)6 ObjectName (javax.management.ObjectName)5 HttpRequestService (com.adaptris.core.http.client.net.HttpRequestService)4 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 Notification (javax.management.Notification)3 NotificationFilterSupport (javax.management.NotificationFilterSupport)3 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)2 MessageInFlightMBean (com.adaptris.core.interceptor.MessageInFlightMBean)2 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)2 CoreException (com.adaptris.core.CoreException)1 ProduceException (com.adaptris.core.ProduceException)1