Search in sources :

Example 81 with TimeInterval

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);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 82 with TimeInterval

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);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CacheExpiry(com.adaptris.core.cache.CacheExpiry) Expiry(com.adaptris.core.cache.CacheExpiry.Expiry) ServiceException(com.adaptris.core.ServiceException) UnresolvedMetadataException(com.adaptris.core.UnresolvedMetadataException) Cache(com.adaptris.core.cache.Cache)

Example 83 with TimeInterval

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();
}
Also used : TimeInterval(com.adaptris.util.TimeInterval)

Example 84 with TimeInterval

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);
}
Also used : WaitService(com.adaptris.core.services.WaitService) TimeInterval(com.adaptris.util.TimeInterval) CheckComponentStateService(com.adaptris.core.stubs.CheckComponentStateService) Test(org.junit.Test)

Example 85 with TimeInterval

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());
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Aggregations

TimeInterval (com.adaptris.util.TimeInterval)310 Test (org.junit.Test)249 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)86 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)49 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)42 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)40 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)38 Channel (com.adaptris.core.Channel)36 MockChannel (com.adaptris.core.stubs.MockChannel)32 File (java.io.File)28 StandardWorkflow (com.adaptris.core.StandardWorkflow)27 Adapter (com.adaptris.core.Adapter)26 GuidGenerator (com.adaptris.util.GuidGenerator)25 FilenameFilter (java.io.FilenameFilter)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 StandaloneProducer (com.adaptris.core.StandaloneProducer)23 CoreException (com.adaptris.core.CoreException)22 WaitService (com.adaptris.core.services.WaitService)22 RandomAccessFile (java.io.RandomAccessFile)21 ObjectName (javax.management.ObjectName)21