Search in sources :

Example 6 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class SlowMessageNotificationTest method testNotification_SlowMessage_Failure.

@Test
public void testNotification_SlowMessage_Failure() throws Exception {
    SlowMessageNotification notif = new SlowMessageNotification(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)));
    workflow.getServiceCollection().add(new AlwaysFailService());
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        workflow.onAdaptrisMessage(msg);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        Properties userData = (Properties) notification.getUserData();
        assertEquals(msg.getUniqueId(), userData.getProperty(SlowMessageNotification.KEY_MESSAGE_ID));
        assertEquals("false", userData.getProperty(SlowMessageNotification.KEY_MESSAGE_SUCCESS));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) WaitService(com.adaptris.core.services.WaitService) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Adapter(com.adaptris.core.Adapter) Properties(java.util.Properties) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) AlwaysFailService(com.adaptris.core.services.AlwaysFailService) Test(org.junit.Test)

Example 7 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class PooledSplitJoinServiceTest method testService.

@Test
public void testService() throws Exception {
    PooledSplitJoinService service = new PooledSplitJoinService();
    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));
    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());
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) Test(org.junit.Test)

Example 8 with WaitService

use of com.adaptris.core.services.WaitService 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)

Example 9 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class PoolingMessageSplitterServiceTest method testServiceWithXmlSplitter_WarmStart_WaitWhileBusy.

@Test
public void testServiceWithXmlSplitter_WarmStart_WaitWhileBusy() throws Exception {
    MockMessageProducer producer = createMockProducer();
    PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)), new StandaloneProducer(producer)).withWarmStart(true).withMaxThreads(1).withWaitWhileBusy(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
    XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
    execute(service, msg);
    assertEquals("Number of messages", 3, producer.getMessages().size());
}
Also used : WaitService(com.adaptris.core.services.WaitService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 10 with WaitService

use of com.adaptris.core.services.WaitService in project interlok by adaptris.

the class ServiceCollectionCase method testLastIndexOf.

@Test
public void testLastIndexOf() throws Exception {
    ServiceCollectionImp sc = createServiceCollection();
    sc.addService(new NullService(UUID.randomUUID().toString()));
    WaitService s = new WaitService(UUID.randomUUID().toString());
    sc.addService(new NullService(UUID.randomUUID().toString()));
    sc.addService(s);
    assertEquals(2, sc.lastIndexOf(s));
}
Also used : WaitService(com.adaptris.core.services.WaitService) ServiceCollectionImp(com.adaptris.core.ServiceCollectionImp) NullService(com.adaptris.core.NullService) Test(org.junit.Test)

Aggregations

WaitService (com.adaptris.core.services.WaitService)28 Test (org.junit.Test)26 TimeInterval (com.adaptris.util.TimeInterval)21 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)16 Channel (com.adaptris.core.Channel)11 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)8 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)8 NullService (com.adaptris.core.NullService)7 ServiceCollectionImp (com.adaptris.core.ServiceCollectionImp)7 StandardWorkflow (com.adaptris.core.StandardWorkflow)5 Adapter (com.adaptris.core.Adapter)4 AppendingMessageAggregator (com.adaptris.core.services.aggregator.AppendingMessageAggregator)4 ServiceException (com.adaptris.core.ServiceException)3 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)3 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)3 DefaultEventHandler (com.adaptris.core.DefaultEventHandler)2 ProduceException (com.adaptris.core.ProduceException)2 Service (com.adaptris.core.Service)2