use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testMessagesCommittedUsingQueue.
@Test
public void testMessagesCommittedUsingQueue() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
Channel channel = createStartableChannel(activeMqBroker, true, "testMessagesCommittedUsingQueue", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue(destination));
send(sender, msgCount);
waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
} finally {
channel.requestClose();
}
assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testWorkflow_SkipProducer.
@Test
public void testWorkflow_SkipProducer() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
Channel channel = createStartableChannel(activeMqBroker, true, "testWorkflow_SkipProducer", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer serviceProducer = new MockMessageProducer();
workflow.getServiceCollection().addAll(Arrays.asList(new Service[] { new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
waitForMessages(serviceProducer, msgCount);
assertEquals(msgCount, serviceProducer.messageCount());
assertEquals(0, workflowProducer.messageCount());
} finally {
channel.requestClose();
}
assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testMessagesOrderedUsingQueue.
@Test
public void testMessagesOrderedUsingQueue() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
Channel channel = createStartableChannel(activeMqBroker, true, "testMessagesOrderedUsingQueue", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.getServiceCollection().addService(new RandomlyFail());
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
start(sender);
for (int i = 0; i < msgCount; i++) {
sender.doService(AdaptrisMessageFactory.getDefaultInstance().newMessage("" + i));
}
stop(sender);
waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
List<AdaptrisMessage> receivedList = ((MockMessageProducer) workflow.getProducer()).getMessages();
assertEquals(msgCount, receivedList.size());
for (int i = 0; i < msgCount; i++) {
assertEquals(String.valueOf(i), receivedList.get(i).getContent());
}
} finally {
channel.requestClose();
}
assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class JmsConnectionErrorHandlerTest method testRestartSharedConnection_ChannelNotStarted.
@Test
public void testRestartSharedConnection_ChannelNotStarted() throws Exception {
Adapter adapter = new Adapter();
adapter.setUniqueId(testName.getMethodName());
JmsConnection connection = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true);
connection.setConnectionErrorHandler(new JmsConnectionErrorHandler());
connection.setUniqueId(testName.getMethodName());
connection.setConnectionRetryInterval(new TimeInterval(5L, "SECONDS"));
connection.setConnectionAttempts(null);
adapter.getSharedComponents().addConnection(connection);
MockChannel started = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName());
MockChannel neverStarted = createChannel(activeMqBroker, new SharedConnection(testName.getMethodName()), testName.getMethodName() + "_2");
neverStarted.setAutoStart(false);
MockMessageProducer producer = (MockMessageProducer) started.getWorkflowList().get(0).getProducer();
adapter.getChannelList().add(started);
adapter.getChannelList().add(neverStarted);
try {
adapter.requestStart();
assertEquals(StartedState.getInstance(), started.retrieveComponentState());
assertEquals(ClosedState.getInstance(), neverStarted.retrieveComponentState());
// Now try and send a message
ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
waitForMessages(producer, 1);
activeMqBroker.stop();
log.trace(testName.getMethodName() + ": Waiting for channel death (i.e. !StartedState)");
long totalWaitTime = waitForChannelToChangeState(StartedState.getInstance(), started);
log.trace(testName.getMethodName() + ": Channel appears to be not started now, and I waited for " + totalWaitTime);
activeMqBroker.start();
totalWaitTime = waitForChannelToMatchState(StartedState.getInstance(), started);
log.trace(testName.getMethodName() + ": Channel now started now, and I waited for " + totalWaitTime);
assertEquals(StartedState.getInstance(), started.retrieveComponentState());
// Now try and send a message
ExampleServiceCase.execute(createProducer(activeMqBroker, testName.getMethodName()), AdaptrisMessageFactory.getDefaultInstance().newMessage("ABC"));
waitForMessages(producer, 2);
assertEquals(ClosedState.getInstance(), neverStarted.retrieveComponentState());
assertEquals(0, neverStarted.getInitCount());
} finally {
adapter.requestClose();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class LargeMessageWorkflowTest method testServiceException.
@Override
@Test
public void testServiceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer meh = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2), new ThrowExceptionService(new ConfiguredException("Fail")) }));
try {
LargeMessageWorkflow workflow = (LargeMessageWorkflow) channel.getWorkflowList().get(0);
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals("Make none produced", 0, producer.getMessages().size());
assertEquals(1, meh.getMessages().size());
for (AdaptrisMessage m : meh.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION));
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
assertEquals(ThrowExceptionService.class.getSimpleName(), m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
}
} finally {
stop(channel);
}
}
Aggregations