use of com.adaptris.core.Service in project interlok by adaptris.
the class StoredProcedureProducerTest method testProduce_PooledConnection.
@Test
public void testProduce_PooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
if (areTestsEnabled()) {
List<Service> serviceList = new ArrayList<Service>();
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_DRIVER), PROPERTIES.getProperty(JDBC_URL), poolsize);
conn.setUsername(PROPERTIES.getProperty(JDBC_USER));
conn.setPassword(PROPERTIES.getProperty(JDBC_PASSWORD));
try {
for (int i = 0; i < maxServices; i++) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in"));
JdbcStringPayloadParameter inParameter = new JdbcStringPayloadParameter();
inParameter.setName("xType");
inParameter.setType(ParameterValueType.VARCHAR);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Sold");
InParameters inParameters = new InParameters();
inParameters.add(inParameter);
spp.setInParameters(inParameters);
StandaloneProducer service = configureForTests(spp, false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return createMessage("Sold");
}
});
assertEquals(0, conn.currentBusyConnectionCount());
assertEquals(poolsize, conn.currentIdleConnectionCount());
assertEquals(poolsize, conn.currentConnectionCount());
} finally {
stop(serviceList.toArray(new ComponentLifecycle[0]));
Thread.currentThread().setName(name);
}
}
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class PooledConnectionHelper method executeTest.
public static void executeTest(List<Service> serviceList, final int iterations, final MessageCreator creator) throws Exception {
MyExceptionHandler handler = new MyExceptionHandler();
List<Thread> threads = new ArrayList<>();
for (final Service s : serviceList) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
for (int j = 0; j < iterations; j++) {
final AdaptrisMessage msg = creator.createMsgForPooledConnectionTest();
s.doService(msg);
TimeUnit.MILLISECONDS.sleep(DEFAULT_PAUSE.toMilliseconds());
}
} catch (Exception e) {
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
}
}
});
t.setUncaughtExceptionHandler(handler);
threads.add(t);
t.start();
}
for (Thread t : threads) {
if (t.isAlive())
t.join();
}
if (handler.hasError()) {
throw handler.lastCaughtException();
}
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionNonStrictWithErrorHandler.
// In Non-Strict Mode, if you have configured an error handler, then
// the transaction is successful.
@Test
public void testServiceExceptionNonStrictWithErrorHandler() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
MockMessageProducer meh = new MockMessageProducer();
Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionNonStrictWithErrorHandler", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setStrict(Boolean.FALSE);
workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
waitForMessages(meh, msgCount);
assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
} finally {
channel.requestClose();
}
assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.Service 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.Service 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