Search in sources :

Example 51 with StandardWorkflow

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

the class WorkflowManagerTest method testAddChildRuntimeComponent.

@Test
public void testAddChildRuntimeComponent() 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);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.setDisableDefaultMessageCount(true);
    WorkflowManager workflowManager = new WorkflowManager(workflow, channelManager);
    WorkflowChild child = new WorkflowChild(workflowManager);
    new WorkflowChild(workflowManager);
    assertTrue(workflowManager.addChildJmxComponent(child));
    assertFalse(workflowManager.addChildJmxComponent(child));
    try {
        workflowManager.addChildJmxComponent(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(1, workflowManager.getChildRuntimeInfoComponents().size());
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) Test(org.junit.Test)

Example 52 with StandardWorkflow

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

the class WorkflowManagerTest method testInjectMessage.

@Test
public void testInjectMessage() 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);
    StandardWorkflow workflow = createWorkflow("w1");
    MockMessageProducer mockProducer = new MockMessageProducer();
    workflow.setProducer(mockProducer);
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableAdaptrisMessage msg = createSAM(msgUniqueId);
    try {
        register(mBeans);
        WorkflowManagerMBean workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
        adapterManager.requestStart();
        workflowManagerProxy.processAsync(msg);
        assertEquals(1, mockProducer.getMessages().size());
        AdaptrisMessage procMsg = mockProducer.getMessages().get(0);
        assertEquals(msgUniqueId, procMsg.getUniqueId());
        assertEquals(PAYLOAD, procMsg.getContent());
        assertEquals(PAYLOAD_ENCODING, procMsg.getContentEncoding());
        assertTrue(procMsg.headersContainsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, procMsg.getMetadataValue(METADATA_KEY));
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) SerializableAdaptrisMessage(com.adaptris.core.SerializableAdaptrisMessage) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) SerializableAdaptrisMessage(com.adaptris.core.SerializableAdaptrisMessage) ObjectName(javax.management.ObjectName) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 53 with StandardWorkflow

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

the class WorkflowManagerTest method testProcess.

@Test
public void testProcess() 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);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.getServiceCollection().add(new AddMetadataService(Arrays.asList(new MetadataElement(getName(), getName()))));
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableMessage msg = createSM(msgUniqueId);
    try {
        register(mBeans);
        MessageProcessor workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        adapterManager.requestStart();
        SerializableMessage reply = workflowManagerProxy.process(msg);
        assertEquals(msgUniqueId, reply.getUniqueId());
        assertEquals(PAYLOAD, reply.getContent());
        assertEquals(PAYLOAD_ENCODING, reply.getContentEncoding());
        Map<String, String> headers = reply.getMessageHeaders();
        assertTrue(headers.containsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, headers.get(METADATA_KEY));
        assertTrue(headers.containsKey(getName()));
        assertEquals(getName(), headers.get(getName()));
        assertEquals("", reply.getNextServiceId());
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) ObjectName(javax.management.ObjectName) StubSerializableMessage(com.adaptris.core.stubs.StubSerializableMessage) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 54 with StandardWorkflow

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

the class WorkflowManagerTest method testWorkflowManager_HasRetryMonitor.

@Test
public void testWorkflowManager_HasRetryMonitor() 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);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.setMessageErrorHandler(new RetryMessageErrorHandler(getName()));
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    try {
        adapterManager.registerMBean();
        adapterManager.requestStart();
        ObjectName handlerObjectName = ObjectName.getInstance(JMX_RETRY_MONITOR_TYPE + realWorkflowManager.createObjectHierarchyString() + ID_PREFIX + getName());
        WorkflowManagerMBean workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
        assertTrue(workflowManagerProxy.getChildRuntimeInfoComponents().contains(handlerObjectName));
        RetryMessageErrorHandlerMonitorMBean monitor = JMX.newMBeanProxy(mBeanServer, handlerObjectName, RetryMessageErrorHandlerMonitorMBean.class);
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) RetryMessageErrorHandlerMonitorMBean(com.adaptris.core.RetryMessageErrorHandlerMonitorMBean) Adapter(com.adaptris.core.Adapter) RetryMessageErrorHandler(com.adaptris.core.RetryMessageErrorHandler) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 55 with StandardWorkflow

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

the class WorkflowManagerTest method testRemoveChildRuntimeComponent.

@Test
public void testRemoveChildRuntimeComponent() 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);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.setDisableDefaultMessageCount(true);
    WorkflowManager workflowManager = new WorkflowManager(workflow, channelManager);
    WorkflowChild child = new WorkflowChild(workflowManager);
    WorkflowChild child2 = new WorkflowChild(workflowManager);
    assertTrue(workflowManager.addChildJmxComponent(child));
    try {
        workflowManager.removeChildJmxComponent(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertTrue(workflowManager.removeChildJmxComponent(child));
    assertFalse(workflowManager.removeChildJmxComponent(child2));
    assertEquals(0, workflowManager.getChildRuntimeInfoComponents().size());
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) Test(org.junit.Test)

Aggregations

StandardWorkflow (com.adaptris.core.StandardWorkflow)102 Test (org.junit.Test)78 Channel (com.adaptris.core.Channel)67 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)55 Adapter (com.adaptris.core.Adapter)53 ObjectName (javax.management.ObjectName)41 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)38 TimeInterval (com.adaptris.util.TimeInterval)25 StandaloneProducer (com.adaptris.core.StandaloneProducer)20 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)16 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)16 ArrayList (java.util.ArrayList)14 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)12 MockChannel (com.adaptris.core.stubs.MockChannel)11 Notification (javax.management.Notification)11 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)10 ServiceList (com.adaptris.core.ServiceList)10 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)10 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)9 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)9