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());
}
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());
}
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);
}
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());
}
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;
}
}
Aggregations