use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class JettyHelper method createEventHandler.
private static EventHandler createEventHandler() throws Exception {
DefaultEventHandler sch = new DefaultEventHandler();
sch.requestStart();
return sch;
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class AdapterRegistryTest method testSendShutdownEvent.
@Test
public void testSendShutdownEvent() throws Exception {
AdapterRegistry adapterRegistry = (AdapterRegistry) AdapterRegistry.findInstance(new JunitBootstrapProperties(new Properties()));
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 2, 2);
DefaultEventHandler evh = new DefaultEventHandler();
StaticMockEventProducer producer = new StaticMockEventProducer(Arrays.asList(new Class[] { AdapterShutdownEvent.class }));
producer.getMessages().clear();
evh.setProducer(producer);
adapter.setEventHandler(evh);
String xml = DefaultMarshaller.getDefaultMarshaller().marshal(adapter);
int expectedCount = adapterRegistry.getAdapters().size() + 1;
ObjectName objName = adapterRegistry.createAdapter(xml);
assertEquals(expectedCount, adapterRegistry.getAdapters().size());
AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, objName, AdapterManagerMBean.class);
manager.requestStart();
assertEquals(0, producer.messageCount());
// This should send an extra event.
AdapterRegistry.sendShutdownEvent(adapterRegistry.getAdapters());
waitForMessages(producer, 1);
assertEquals(1, producer.messageCount());
AdapterRegistry.close(adapterRegistry.getAdapters());
producer.getMessages().clear();
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class ExceptionHandlingServiceWrapperTest method testWithExceptionFromWrappedServices.
@Test
public void testWithExceptionFromWrappedServices() throws Exception {
ExceptionHandlingServiceWrapper service = create();
service.registerEventHandler(new DefaultEventHandler());
service.setService(new ServiceList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("servicesComplete", "true") })) }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
assertNotNull(service.wrappedServices());
// ExceptionService defaults to NullService
assertEquals(2, service.wrappedServices().length);
execute(service, msg);
assertEquals("true", msg.getMetadataValue("exceptionServiceTriggered"));
assertNull(msg.getMetadataValue("servicesComplete"));
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class PooledSplitJoinServiceTest method testService_DidNoWork.
@Test(expected = ServiceException.class)
public void testService_DidNoWork() 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.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);
}
use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.
the class PooledSplitJoinServiceTest method testService_DidWorkSuccessfully.
@Test
public void testService_DidWorkSuccessfully() throws Exception {
PooledSplitJoinService service = new PooledSplitJoinService();
service.setServiceErrorHandler(new NoExceptionIfWorkDone().withMetadataKey(NoExceptionIfWorkDone.DEFAULT_METADATA_KEY));
service.setSplitter(new LineCountSplitter(1));
service.setService(asCollection(new WaitService(new TimeInterval(10L, TimeUnit.MILLISECONDS), false), new MockExceptionStrategyService(MockExceptionStrategyService.MODE.NEUTRAL)));
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());
}
Aggregations