Search in sources :

Example 1 with DefaultEventHandler

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;
}
Also used : DefaultEventHandler(com.adaptris.core.DefaultEventHandler)

Example 2 with DefaultEventHandler

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();
}
Also used : DefaultEventHandler(com.adaptris.core.DefaultEventHandler) StaticMockEventProducer(com.adaptris.core.stubs.StaticMockEventProducer) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Adapter(com.adaptris.core.Adapter) URLString(com.adaptris.util.URLString) BootstrapProperties(com.adaptris.core.management.BootstrapProperties) JunitBootstrapProperties(com.adaptris.core.stubs.JunitBootstrapProperties) Properties(java.util.Properties) AdapterShutdownEvent(com.adaptris.core.event.AdapterShutdownEvent) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 3 with DefaultEventHandler

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"));
}
Also used : DefaultEventHandler(com.adaptris.core.DefaultEventHandler) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 4 with DefaultEventHandler

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);
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) Test(org.junit.Test)

Example 5 with DefaultEventHandler

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());
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) Test(org.junit.Test)

Aggregations

DefaultEventHandler (com.adaptris.core.DefaultEventHandler)21 Test (org.junit.Test)18 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)12 AppendingMessageAggregator (com.adaptris.core.services.aggregator.AppendingMessageAggregator)6 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 TimeInterval (com.adaptris.util.TimeInterval)6 ServiceException (com.adaptris.core.ServiceException)3 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)3 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)3 Adapter (com.adaptris.core.Adapter)2 Channel (com.adaptris.core.Channel)2 NullService (com.adaptris.core.NullService)2 StandaloneProducer (com.adaptris.core.StandaloneProducer)2 AdapterShutdownEvent (com.adaptris.core.event.AdapterShutdownEvent)2 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)2 WaitService (com.adaptris.core.services.WaitService)2 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)2 StaticMockEventProducer (com.adaptris.core.stubs.StaticMockEventProducer)2 URLString (com.adaptris.util.URLString)2 Properties (java.util.Properties)2