use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class CommonsSystemCommandExecutorServiceTest method testDoService_ExceedsTimeout.
@Test
public void testDoService_ExceedsTimeout() throws Exception {
Thread.currentThread().setName(getName());
SystemCommandExecutorService service = new SystemCommandExecutorService(createTimeoutCommand(), new OverwritePayload());
service.setTimeout(new TimeInterval(2L, TimeUnit.SECONDS));
AdaptrisMessage msg = createMessage();
try {
execute(service, msg);
fail();
} catch (ServiceException expected) {
System.err.println(getName() + "=" + msg.getContent());
expected.printStackTrace(System.err);
}
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class AddValueToCache method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = retrieveCache();
Optional<Expiry> hasExpiry = buildExpiry(msg);
String cacheKey = msg.resolve(getKey());
// should be hasExpiry.ifPresentOrElse() once we goto J11...
if (hasExpiry.isPresent()) {
TimeInterval expiryInterval = hasExpiry.get().expiresIn();
log.trace("[{}] will expire in {}", cacheKey, expiryInterval);
cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg), hasExpiry.get().expiresIn());
} else {
log.trace("Expiry for [{}] taken from cache settings", cacheKey);
cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg));
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.util.TimeInterval in project interlok by adaptris.
the class PoolingMessageSplitterService method closeService.
@Override
protected void closeService() {
ManagedThreadFactory.shutdownQuietly(executor, new TimeInterval());
Closer.closeQuietly(objectPool);
super.closeService();
}
use of com.adaptris.util.TimeInterval 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.util.TimeInterval in project interlok by adaptris.
the class PoolingWorkflowTest method testInitWaitTime.
@Test
public void testInitWaitTime() throws Exception {
PoolingWorkflow workflow = new PoolingWorkflow();
TimeInterval defaultInterval = new TimeInterval(60L, TimeUnit.SECONDS.name());
assertNull(workflow.getInitWaitTime());
assertEquals(defaultInterval.toMilliseconds(), workflow.initWaitTimeMs());
TimeInterval interval = new TimeInterval(200L, TimeUnit.MILLISECONDS.name());
workflow.setInitWaitTime(interval);
assertEquals(interval, workflow.getInitWaitTime());
assertNotSame(defaultInterval.toMilliseconds(), workflow.initWaitTimeMs());
assertEquals(interval.toMilliseconds(), workflow.initWaitTimeMs());
workflow.setThreadKeepAlive(null);
assertNull(workflow.getThreadKeepAlive());
assertEquals(defaultInterval.toMilliseconds(), workflow.threadLifetimeMs());
}
Aggregations