Search in sources :

Example 6 with DefaultFailedMessageRetrier

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

the class DefaultFailedMessageRetrierJmxTest method testMBean_Retry_File_WorkflowNotFound.

@Test
public void testMBean_Retry_File_WorkflowNotFound() throws Exception {
    Adapter adapter = createAdapter(getName());
    Channel c = createChannel(getName());
    StandardWorkflow wf = createWorkflow(getName());
    MockMessageProducer mock = new MockMessageProducer();
    wf.setProducer(mock);
    c.getWorkflowList().add(wf);
    adapter.getChannelList().add(c);
    DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
    adapter.setFailedMessageRetrier(retrier);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@BLAHBLAH");
    File fileToRetry = writeFile(msg, new MimeEncoder());
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        adapterManager.requestStart();
        ObjectName retrierObjName = createRetrierObjectName(adapterManager);
        DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
        assertFalse(jmxBean.retryMessage(fileToRetry));
        assertEquals(0, mock.messageCount());
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : DefaultFailedMessageRetrierJmxMBean(com.adaptris.core.DefaultFailedMessageRetrierJmxMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) File(java.io.File) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 7 with DefaultFailedMessageRetrier

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

the class DefaultFailedMessageRetrierJmxTest method testMBean_Retry_File_NotFoundException.

@Test
public void testMBean_Retry_File_NotFoundException() throws Exception {
    Adapter adapter = createAdapter(getName());
    Channel c = createChannel(getName());
    StandardWorkflow wf = createWorkflow(getName());
    MockMessageProducer mock = new MockMessageProducer();
    wf.setProducer(mock);
    c.getWorkflowList().add(wf);
    adapter.getChannelList().add(c);
    DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
    adapter.setFailedMessageRetrier(retrier);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@BLAHBLAH");
    File fileToRetry = writeFile(msg, new MimeEncoder());
    fileToRetry.delete();
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        adapterManager.requestStart();
        ObjectName retrierObjName = createRetrierObjectName(adapterManager);
        DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
        try {
            jmxBean.retryMessage(fileToRetry);
            fail();
        } catch (IOException expected) {
        }
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : DefaultFailedMessageRetrierJmxMBean(com.adaptris.core.DefaultFailedMessageRetrierJmxMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) IOException(java.io.IOException) File(java.io.File) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 8 with DefaultFailedMessageRetrier

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

the class DefaultFailedMessageRetrierJmxTest method testMBean_GetParentId.

@Test
public void testMBean_GetParentId() throws Exception {
    Adapter adapter = createAdapter(getName());
    DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
    adapter.setFailedMessageRetrier(retrier);
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName retrierObjName = createRetrierObjectName(adapterManager);
    try {
        adapterManager.registerMBean();
        DefaultFailedMessageRetrierJmxMBean proxy = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
        assertNotNull(proxy);
        assertEquals(getName(), proxy.getParentId());
    } finally {
        adapterManager.unregisterMBean();
    }
}
Also used : DefaultFailedMessageRetrierJmxMBean(com.adaptris.core.DefaultFailedMessageRetrierJmxMBean) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 9 with DefaultFailedMessageRetrier

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

the class AdapterManagerTest method testMBean_NotificationOnSetFailedMessageRetrier.

@Test
public void testMBean_NotificationOnSetFailedMessageRetrier() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 1, 1);
    String newCompXml = DefaultMarshaller.getDefaultMarshaller().marshal(new DefaultFailedMessageRetrier());
    AdapterManager adapterManager = new AdapterManager(adapter);
    ObjectName adapterObj = adapterManager.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);
        adapterManagerProxy.setFailedMessageRetrier(newCompXml);
        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 : NotificationFilterSupport(javax.management.NotificationFilterSupport) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 10 with DefaultFailedMessageRetrier

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

the class AdapterManagerTest method testMBean_SetFailedMessageRetrier.

@Test
public void testMBean_SetFailedMessageRetrier() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    DefaultFailedMessageRetrier meh = new DefaultFailedMessageRetrier();
    meh.setUniqueId(getName());
    ObjectName adapterObj = adapterManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    try {
        register(mBeans);
        AdapterManagerMBean adapterManagerProxy = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        adapterManagerProxy.setFailedMessageRetrier(DefaultMarshaller.getDefaultMarshaller().marshal(meh));
        Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(adapterManagerProxy.getConfiguration());
        assertEquals(DefaultFailedMessageRetrier.class, marshalledAdapter.getFailedMessageRetrier().getClass());
        assertEquals(meh.getUniqueId(), ((DefaultFailedMessageRetrier) marshalledAdapter.getFailedMessageRetrier()).getUniqueId());
    } finally {
    }
}
Also used : ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

Adapter (com.adaptris.core.Adapter)13 DefaultFailedMessageRetrier (com.adaptris.core.DefaultFailedMessageRetrier)13 ObjectName (javax.management.ObjectName)13 Test (org.junit.Test)13 DefaultFailedMessageRetrierJmxMBean (com.adaptris.core.DefaultFailedMessageRetrierJmxMBean)10 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 Channel (com.adaptris.core.Channel)8 StandardWorkflow (com.adaptris.core.StandardWorkflow)8 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)8 DefaultSerializableMessageTranslator (com.adaptris.core.DefaultSerializableMessageTranslator)4 SerializableMessage (com.adaptris.interlok.types.SerializableMessage)4 File (java.io.File)4 MimeEncoder (com.adaptris.core.MimeEncoder)3 TimeInterval (com.adaptris.util.TimeInterval)2 CoreException (com.adaptris.core.CoreException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Notification (javax.management.Notification)1 NotificationFilterSupport (javax.management.NotificationFilterSupport)1