Search in sources :

Example 1 with AppendingMessageAggregator

use of com.adaptris.core.services.aggregator.AppendingMessageAggregator 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 2 with AppendingMessageAggregator

use of com.adaptris.core.services.aggregator.AppendingMessageAggregator 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 3 with AppendingMessageAggregator

use of com.adaptris.core.services.aggregator.AppendingMessageAggregator 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 4 with AppendingMessageAggregator

use of com.adaptris.core.services.aggregator.AppendingMessageAggregator in project interlok by adaptris.

the class PooledSplitJoinServiceTest method testService_WithException.

@Test(expected = ServiceException.class)
public void testService_WithException() throws Exception {
    PooledSplitJoinService service = new PooledSplitJoinService();
    service.setAggregator(new AppendingMessageAggregator());
    service.setSplitter(new LineCountSplitter(1));
    service.setPoolsize(10);
    service.setTimeout(new TimeInterval(5L, TimeUnit.SECONDS));
    service.setService(new ThrowExceptionService(new ConfiguredException("always-fail")));
    service.registerEventHandler(LifecycleHelper.initAndStart(new DefaultEventHandler()));
    AdaptrisMessage msg = createLineCountMessageInput(50);
    try {
        ExampleServiceCase.execute(service, msg);
    } catch (ServiceException e) {
        assertEquals("always-fail", e.getMessage());
        throw e;
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) ServiceException(com.adaptris.core.ServiceException) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Example 5 with AppendingMessageAggregator

use of com.adaptris.core.services.aggregator.AppendingMessageAggregator 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());
}
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)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 AppendingMessageAggregator (com.adaptris.core.services.aggregator.AppendingMessageAggregator)8 TimeInterval (com.adaptris.util.TimeInterval)8 Test (org.junit.Test)8 DefaultEventHandler (com.adaptris.core.DefaultEventHandler)6 WaitService (com.adaptris.core.services.WaitService)4 ServiceException (com.adaptris.core.ServiceException)2 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)1 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)1 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)1