use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class RetryMessageErrorHandlerMonitorTest method testMBean_FailMessageById.
@Test
public void testMBean_FailMessageById() 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.failMessage("hello");
mbean.failMessage(msg.getUniqueId());
assertEquals(1, failProducer.messageCount());
} finally {
adapterManager.requestClose();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class StatelessServiceWrapperTest method testWrappedServiceCreateName.
@Test
public void testWrappedServiceCreateName() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
MockMessageProducer prod = new MockMessageProducer();
Service s = create(prod);
assertNotSame(StatelessServiceWrapper.class.getName(), s.createName());
assertEquals(MockMessageProducer.class.getName(), s.createName());
StatelessServiceWrapper sw = new StatelessServiceWrapper();
assertEquals(StatelessServiceWrapper.class.getName(), sw.createName());
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ExceptionReportServiceTest method testBug2356.
@Test
public void testBug2356() throws Exception {
ServiceImp failingService = new ThrowExceptionService(new ConfiguredException("Fail"));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new InsertNode(XPATH_ROOT)));
MockMessageProducer mockProducer = new MockMessageProducer();
StandardProcessingExceptionHandler speh = new StandardProcessingExceptionHandler(new ServiceList(new Service[] { service, new StandaloneProducer(mockProducer) }));
MockChannel channel = new MockChannel();
MockMessageConsumer consumer = new MockMessageConsumer();
StandardWorkflow wf = new StandardWorkflow();
wf.getServiceCollection().add(failingService);
wf.setConsumer(consumer);
channel.setMessageErrorHandler(speh);
channel.getWorkflowList().add(wf);
try {
channel.prepare();
channel.requestStart();
consumer.submitMessage(msg);
assertEquals(1, mockProducer.getMessages().size());
AdaptrisMessage failedMessage = mockProducer.getMessages().get(0);
assertNotSame(XML_PAYLOAD, failedMessage.getContent());
XmlUtils xml = XmlHelper.createXmlUtils(failedMessage);
assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
String xmlElement = xml.getSingleTextItem(XPATH_ROOT + "/Exception");
assertTrue(xmlElement.contains("com.adaptris.core.services.exception.ThrowExceptionService.doService"));
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class PoolingMessageSplitterServiceTest method testServiceWithXmlSplitter.
@Test
public void testServiceWithXmlSplitter() throws Exception {
MockMessageProducer producer = createMockProducer();
PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new StandaloneProducer(producer));
service.setMaxThreads(1);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
execute(service, msg);
assertEquals("Number of messages", 3, producer.getMessages().size());
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class PoolingMessageSplitterServiceTest method testServiceWithXmlSplitter_WarmStart_WaitWhileBusy.
@Test
public void testServiceWithXmlSplitter_WarmStart_WaitWhileBusy() throws Exception {
MockMessageProducer producer = createMockProducer();
PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)), new StandaloneProducer(producer)).withWarmStart(true).withMaxThreads(1).withWaitWhileBusy(true);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
execute(service, msg);
assertEquals("Number of messages", 3, producer.getMessages().size());
}
Aggregations