use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class PooledSplitJoinServiceTest method testService_IgnoreExceptions.
@Test
public void testService_IgnoreExceptions() throws Exception {
PooledSplitJoinService service = new PooledSplitJoinService();
service.setServiceErrorHandler(new IgnoreAllExceptions());
service.setSplitter(new LineCountSplitter(1));
service.setService(asCollection(new MockExceptionStrategyService(MockExceptionStrategyService.MODE.ERROR)));
service.setPoolsize(10);
service.setTimeout(new TimeInterval(5L, TimeUnit.SECONDS));
service.setAggregator(new AppendingMessageAggregator());
service.registerEventHandler(LifecycleHelper.initAndStart(new DefaultEventHandler()));
AdaptrisMessage msg = createLineCountMessageInput(50);
execute(service, msg);
List<String> result = IOUtils.readLines(msg.getReader());
// Using an appending message aggregator just means that we double up on the original message...
// Since we aren't doing any filtering... then we will always get 100 msgs.
assertEquals(50 * 2, result.size());
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class PooledSplitJoinServiceTest method testService_Events.
@Test
public void testService_Events() throws Exception {
PooledSplitJoinService service = new PooledSplitJoinService();
MockMessageProducer events = new MockMessageProducer();
service.setAggregator(new AppendingMessageAggregator());
service.setSplitter(new LineCountSplitter(1));
service.setPoolsize(10);
service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
service.setService(new WaitService(new TimeInterval(100L, TimeUnit.MILLISECONDS), true));
service.setSendEvents(true);
service.registerEventHandler(LifecycleHelper.initAndStart(new DefaultEventHandler(events)));
AdaptrisMessage msg = createLineCountMessageInput(50);
ExampleServiceCase.execute(service, msg);
List<String> result = IOUtils.readLines(msg.getReader());
// Using an appending message aggregator just means that we double up on the original message...
assertEquals(50 * 2, result.size());
// Check we got 50 events.
assertEquals(50, events.getMessages().size());
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class PooledSplitJoinServiceTest method testService_DidSomeWork.
@Test
public void testService_DidSomeWork() throws Exception {
PooledSplitJoinService service = new PooledSplitJoinService();
service.setServiceErrorHandler(new NoExceptionIfWorkDone().withMetadataKey(NoExceptionIfWorkDone.DEFAULT_METADATA_KEY));
service.setSplitter(new LineCountSplitter(1));
service.setService(asCollection(new MockExceptionStrategyService(MockExceptionStrategyService.MODE.MIXED)));
service.setPoolsize(10);
service.setTimeout(new TimeInterval(5L, TimeUnit.SECONDS));
service.setAggregator(new AppendingMessageAggregator());
service.registerEventHandler(LifecycleHelper.initAndStart(new DefaultEventHandler()));
AdaptrisMessage msg = createLineCountMessageInput(50);
execute(service, msg);
List<String> result = IOUtils.readLines(msg.getReader());
// Using an appending message aggregator just means that we double up on the original message...
// Since we aren't doing any filtering... then we will always get 100 msgs.
assertEquals(50 * 2, result.size());
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_SendEventsFalse.
@Test
public void testDoServiceWithFailures_SendEventsFalse() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
AdaptrisMessage msg = createMessage(REGEXP_DATA);
AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
DefaultEventHandler eh = new DefaultEventHandler();
MockMessageProducer ehp = new MockMessageProducer();
eh.setProducer(ehp);
LifecycleHelper.initAndStart(eh);
service.registerEventHandler(eh);
service.setSendEvents(false);
try {
ExampleServiceCase.execute(service, msg);
fail("Expecting failure from AlwaysFailService");
} catch (ServiceException expected) {
;
}
LifecycleHelper.stopAndClose(eh);
assertEvents(ehp, 0, MessageLifecycleEvent.class);
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class AdvancedMessageSplitterServiceTest method testDoServiceWithEventHandler_SendEventsTrue.
@Test
public void testDoServiceWithEventHandler_SendEventsTrue() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
AdvancedMessageSplitterService service = createServiceImpl(new SimpleRegexpMessageSplitter("\\|"), producer);
AdaptrisMessage msg = createMessage(REGEXP_DATA);
DefaultEventHandler eh = new DefaultEventHandler();
MockMessageProducer ehp = new MockMessageProducer();
eh.setProducer(ehp);
eh.requestStart();
service.registerEventHandler(eh);
service.setSendEvents(true);
ExampleServiceCase.execute(service, msg);
eh.requestClose();
assertEquals("Number of messages", 4, producer.getMessages().size());
assertEquals("splitCount metadata", 4, Integer.parseInt(msg.getMetadataValue(MessageSplitterServiceImp.KEY_SPLIT_MESSAGE_COUNT)));
assertEvents(ehp, 4, MessageLifecycleEvent.class);
int count = 0;
for (AdaptrisMessage m : producer.getMessages()) {
count++;
assertEquals(count, Integer.parseInt(m.getMetadataValue(KEY_CURRENT_SPLIT_MESSAGE_COUNT)));
}
}
Aggregations