use of com.adaptris.core.Service in project interlok by adaptris.
the class LargeMessageWorkflowTest method testRuntimeException.
@Override
@Test
public void testRuntimeException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new RuntimeException();
}
};
;
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) }));
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));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class FirstRowMetadataTranslatorTest method testService_PooledConnection.
@Test
public void testService_PooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
final AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
List<Service> serviceList = new ArrayList<Service>();
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER), PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), poolsize);
try {
for (int i = 0; i < maxServices; i++) {
JdbcDataQueryService service = createMetadataService(false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return createMessage(entry);
}
});
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 FirstRowMetadataTranslatorTest method testService_AdvancedPooledConnection.
@Test
public void testService_AdvancedPooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
final AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
List<Service> serviceList = new ArrayList<Service>();
AdvancedJdbcPooledConnection conn = PooledConnectionHelper.createAdvancedPooledConnection(PROPERTIES.getProperty(JDBC_QUERYSERVICE_DRIVER), PROPERTIES.getProperty(JDBC_QUERYSERVICE_URL), poolsize);
try {
for (int i = 0; i < maxServices; i++) {
JdbcDataQueryService service = createMetadataService(false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
return createMessage(entry);
}
});
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 DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByContentId.
@Test
public void testDoService_MimeServiceExtractor_ByContentId() throws Exception {
AddMetadataService metadataService = new AddMetadataService();
metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
DynamicServiceExecutor dynamicService = createService();
dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByContentId("Service")));
AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_8BIT);
execute(dynamicService, msg);
assertEquals(getName(), msg.getMetadataValue(getName()));
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByPosition.
@Test
public void testDoService_MimeServiceExtractor_ByPosition() throws Exception {
AddMetadataService metadataService = new AddMetadataService();
metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
DynamicServiceExecutor dynamicService = createService();
dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByPosition(0)));
AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_7BIT);
execute(dynamicService, msg);
assertEquals(getName(), msg.getMetadataValue(getName()));
}
Aggregations