Search in sources :

Example 6 with PoolingWorkflow

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

the class JettyNoBacklogInterceptorTest method retrieveObjectForSampleConfig.

@Override
protected Channel retrieveObjectForSampleConfig() {
    Channel c = new Channel();
    PoolingWorkflow wf = new PoolingWorkflow();
    wf.addInterceptor(new JettyPoolingWorkflowInterceptor());
    wf.addInterceptor(new JettyNoBacklogInterceptor());
    c.setUniqueId(UUID.randomUUID().toString());
    wf.setUniqueId(UUID.randomUUID().toString());
    c.getWorkflowList().add(wf);
    return c;
}
Also used : Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow)

Example 7 with PoolingWorkflow

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

the class InFlightWorkflowInterceptorTest method testInterceptor.

@Test
public void testInterceptor() throws Exception {
    InFlightWorkflowInterceptor interceptor = new InFlightWorkflowInterceptor("testInterceptor");
    final PoolingWorkflow wf = createPoolingWorkflow("workflow", interceptor);
    wf.setPoolSize(1);
    wf.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS));
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new WaitService(new TimeInterval(2L, TimeUnit.SECONDS)));
    MockChannel c = new MockChannel();
    c.getWorkflowList().add(wf);
    try {
        LifecycleHelper.initAndStart(c);
        wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        assertEquals(1, interceptor.messagesInFlightCount());
        assertEquals(0, interceptor.messagesPendingCount());
        new Thread(new Runnable() {

            @Override
            public void run() {
                wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
            }
        }).start();
        LifecycleHelper.waitQuietly(100);
        assertEquals(1, interceptor.messagesInFlightCount());
        assertEquals(1, interceptor.messagesPendingCount());
        ExampleServiceCase.waitForMessages(prod, 2, 10000);
    } finally {
        LifecycleHelper.stopAndClose(c);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Test(org.junit.Test)

Example 8 with PoolingWorkflow

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

the class ChannelManagerTest method testMBean_NotificationOnAddWorkflow.

@Test
public void testMBean_NotificationOnAddWorkflow() 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"));
    ChannelManager child1 = new ChannelManager(createChannel(getName() + "_1"), 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.addWorkflow(workflowXml);
        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 : 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 9 with PoolingWorkflow

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

the class AdapterManagerTest method testMBean_NotificationOnAddWorkflow.

@Test
public void testMBean_NotificationOnAddWorkflow() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    Channel newChannel = createChannel(getName() + "_1");
    String workflowXml = DefaultMarshaller.getDefaultMarshaller().marshal(new PoolingWorkflow(getName() + "_wf1"));
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.createObjectName();
    ChannelManager channelManager = new ChannelManager(newChannel, adapterManager);
    ObjectName channelManagerObj = channelManager.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(NOTIF_TYPE_ADAPTER_CONFIG);
    try {
        adapterManager.registerMBean();
        mBeanServer.addNotificationListener(adapterObj, listener, filter, null);
        AdapterManagerMBean adapterManagerProxy = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        channelManager.addWorkflow(workflowXml);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification n = listener.getNotifications().get(0);
        assertEquals(NOTIF_TYPE_ADAPTER_CONFIG, n.getType());
        assertEquals(NOTIF_MSG_CONFIG_UPDATED, n.getMessage());
        assertEquals(adapterManagerProxy.getConfiguration(), n.getUserData());
    } finally {
    }
}
Also used : 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 10 with PoolingWorkflow

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

the class WorkflowManagerTest method testJettyInterceptor_AlreadyHasInterceptor.

@Test
public void testJettyInterceptor_AlreadyHasInterceptor() 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.addInterceptor(new JettyPoolingWorkflowInterceptor());
    workflow.setConsumer(new JettyMessageConsumer());
    new WorkflowManager(workflow, channelManager);
    assertEquals(3, workflow.getInterceptors().size());
    // Look the order should now be swapped.
    assertEquals(JettyPoolingWorkflowInterceptor.class, workflow.getInterceptors().get(0).getClass());
    assertEquals(MessageMetricsInterceptor.class, workflow.getInterceptors().get(1).getClass());
    assertEquals(InFlightWorkflowInterceptor.class, workflow.getInterceptors().get(2).getClass());
}
Also used : Channel(com.adaptris.core.Channel) JettyPoolingWorkflowInterceptor(com.adaptris.core.http.jetty.JettyPoolingWorkflowInterceptor) Adapter(com.adaptris.core.Adapter) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) 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