use of com.adaptris.core.stubs.MockMessageProducer 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();
}
}
use of com.adaptris.core.stubs.MockMessageProducer 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();
}
}
use of com.adaptris.core.stubs.MockMessageProducer 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();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class WorkflowManagerTest method testProcessAsync.
@Test
public void testProcessAsync() 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();
SerializableMessage msg = createSM(msgUniqueId);
try {
register(mBeans);
MessageProcessor workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.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();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class RetryMessageErrorHandlerMonitorTest method testMBean_FailAllMessages.
@Test
public void testMBean_FailAllMessages() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
MockMessageProducer failProducer = new MockMessageProducer();
RetryMessageErrorHandler handler = new RetryMessageErrorHandler(getName(), new StandaloneProducer(failProducer));
adapter.setMessageErrorHandler(handler);
AdapterManager adapterManager = new AdapterManager(adapter);
try {
registerMBeans(adapterManager);
adapterManager.requestStart();
ObjectName retryObjectName = ObjectName.getInstance(JMX_RETRY_MONITOR_TYPE + adapterManager.createObjectHierarchyString() + ID_PREFIX + getName());
RetryMessageErrorHandlerMonitorMBean mbean = JMX.newMBeanProxy(mBeanServer, retryObjectName, RetryMessageErrorHandlerMonitorMBean.class);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
// 10 retries 10 minutes apart, so it should be waiting.
handler.handleProcessingException(msg);
assertEquals(1, mbean.waitingForRetry().size());
assertTrue(mbean.waitingForRetry().contains(msg.getUniqueId()));
mbean.failAllMessages(true);
assertEquals(1, failProducer.messageCount());
handler.handleProcessingException(AdaptrisMessageFactory.getDefaultInstance().newMessage());
// All msgs Fail.
assertEquals(0, mbean.waitingForRetry().size());
assertEquals(2, failProducer.messageCount());
} finally {
adapterManager.requestClose();
}
}
Aggregations