Search in sources :

Example 11 with WaitService

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

the class ServiceCollectionCase method testAddAtPosition.

@Test
public void testAddAtPosition() throws Exception {
    ServiceCollectionImp sc = createServiceCollection();
    sc.addService(new NullService(UUID.randomUUID().toString()));
    sc.addService(new NullService(UUID.randomUUID().toString()));
    sc.add(1, new WaitService(UUID.randomUUID().toString()));
    assertEquals(3, sc.size());
    assertEquals(WaitService.class, sc.get(1).getClass());
}
Also used : WaitService(com.adaptris.core.services.WaitService) ServiceCollectionImp(com.adaptris.core.ServiceCollectionImp) NullService(com.adaptris.core.NullService) Test(org.junit.Test)

Example 12 with WaitService

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

the class ServiceCollectionCase method testAddAllAtPosition.

@Test
public void testAddAllAtPosition() throws Exception {
    ServiceCollectionImp sc = createServiceCollection();
    sc.addService(new NullService(UUID.randomUUID().toString()));
    sc.addService(new NullService(UUID.randomUUID().toString()));
    ServiceCollectionImp sc2 = createServiceCollection();
    sc2.addService(new WaitService(UUID.randomUUID().toString()));
    sc2.addService(new WaitService(UUID.randomUUID().toString()));
    sc.addAll(1, sc2);
    assertEquals(4, sc.size());
    assertEquals(WaitService.class, sc.get(1).getClass());
    assertEquals(WaitService.class, sc.get(2).getClass());
}
Also used : WaitService(com.adaptris.core.services.WaitService) ServiceCollectionImp(com.adaptris.core.ServiceCollectionImp) NullService(com.adaptris.core.NullService) Test(org.junit.Test)

Example 13 with WaitService

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

the class ServiceListTest method testBug2055.

@Test
public void testBug2055() throws Exception {
    String name = Thread.currentThread().getName();
    Thread.currentThread().setName("testBug2055");
    final ServiceList services = new ServiceList();
    MarkerService marker = new MarkerService();
    services.addService(marker);
    services.addService(new WaitService(new TimeInterval(3L, TimeUnit.SECONDS)));
    services.addService(new CheckComponentStateService());
    start(services);
    final ExceptionContainer c = new ExceptionContainer();
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
                services.doService(msg);
            } catch (ServiceException e) {
                c.setException(e);
            }
        }
    });
    t.start();
    while (!marker.hasTriggered) {
        Thread.sleep(10);
    }
    stop(services);
    t.join();
    if (c.getException() != null) {
        fail("Services failed, " + c.getException().getMessage());
    }
    Thread.currentThread().setName(name);
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) CheckComponentStateService(com.adaptris.core.stubs.CheckComponentStateService) Test(org.junit.Test)

Example 14 with WaitService

use of com.adaptris.core.services.WaitService 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());
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) 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 15 with WaitService

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

the class PooledSplitJoinServiceTest method testTimeout.

@Test(expected = ServiceException.class)
public void testTimeout() throws Exception {
    PooledSplitJoinService service = new PooledSplitJoinService();
    service.setAggregator(new AppendingMessageAggregator());
    service.setSplitter(new LineCountSplitter(1));
    service.setPoolsize(10);
    service.setTimeout(new TimeInterval(50L, TimeUnit.MILLISECONDS));
    service.setService(new WaitService(new TimeInterval(100L, TimeUnit.MILLISECONDS), false));
    service.setSendEvents(true);
    AdaptrisMessage msg = createLineCountMessageInput(50);
    try {
        ExampleServiceCase.execute(service, msg);
    } catch (ServiceException e) {
        // This will be a RuntimeException (from hasNext()?) that wraps a TimeoutException
        // That's in turn wrapped by a ServiceException.
        assertNotNull(e.getCause().getCause());
        throw e;
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) AppendingMessageAggregator(com.adaptris.core.services.aggregator.AppendingMessageAggregator) 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