Search in sources :

Example 56 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class AdapterManagerTest method testInitialise_WithTimeout.

@Test
public void testInitialise_WithTimeout() throws Exception {
    TimeInterval standardTimeout = new TimeInterval(2L, TimeUnit.SECONDS);
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    MockConnection conn = new MockConnection(getName(), new TimeInterval(250L, TimeUnit.MILLISECONDS).toMilliseconds());
    adapter.getSharedComponents().addConnection(conn);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
        try {
            manager.requestInit(-1);
            fail();
        } catch (IllegalArgumentException expected) {
        }
        manager.requestInit(standardTimeout.toMilliseconds());
        assertEquals(InitialisedState.getInstance(), manager.getComponentState());
        adapterManager.requestClose();
        try {
            manager.requestInit(new TimeInterval(100L, TimeUnit.MILLISECONDS).toMilliseconds());
            fail();
        } catch (TimeoutException expected) {
        }
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Adapter(com.adaptris.core.Adapter) MockConnection(com.adaptris.core.stubs.MockConnection) ObjectName(javax.management.ObjectName) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 57 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class DefaultFailedMessageRetrierJmxTest method testMBean_RetryWhen_Retrier_Closed.

@Test
public void testMBean_RetryWhen_Retrier_Closed() throws Exception {
    Adapter adapter = createAdapter(getName());
    Channel channel = createChannel(getName());
    StandardWorkflow wf = createWorkflow(getName());
    MockMessageProducer mock = new MockMessageProducer();
    wf.setProducer(mock);
    channel.getWorkflowList().add(wf);
    adapter.getChannelList().add(channel);
    DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
    retrier.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS));
    adapter.setFailedMessageRetrier(retrier);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@" + getName());
    SerializableMessage serialized = new DefaultSerializableMessageTranslator().translate(msg);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        adapterManager.requestStart();
        // Close the workflow directly
        LifecycleHelper.stop(retrier);
        LifecycleHelper.close(retrier);
        ObjectName retrierObjName = createRetrierObjectName(adapterManager);
        DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
        assertFalse(jmxBean.retryMessage(serialized));
        assertEquals(0, mock.messageCount());
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : DefaultFailedMessageRetrierJmxMBean(com.adaptris.core.DefaultFailedMessageRetrierJmxMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) DefaultSerializableMessageTranslator(com.adaptris.core.DefaultSerializableMessageTranslator) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 58 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class AddValueToCacheTest method testDoService_NoExpiryMetadata.

@Test
public void testDoService_NoExpiryMetadata() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
    ExpiringMapCache cache = createCacheInstanceForTests().withExpiration(new TimeInterval(1L, TimeUnit.SECONDS));
    MyCacheEventListener listener = new MyCacheEventListener();
    cache.getEventListener().addEventListener(listener);
    AddValueToCache service = new AddValueToCache().withExpiry("%message{expiry}").withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
    try {
        start(service);
        // msg.addMetadata("expiry", "a"); // empty expiry should not expire.
        service.doService(msg);
        Object value = cache.get(msg.getUniqueId());
        assertEquals("Hello World", value);
        await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(listener::expiredCount, greaterThanOrEqualTo(1));
        assertEquals(0, cache.size());
    } finally {
        stop(service);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) StringPayloadCacheTranslator(com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator) MyCacheEventListener(com.adaptris.core.cache.MyCacheEventListener) Test(org.junit.Test)

Example 59 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class AddValueToCacheTest method testDoService_Expiry_Unsupported.

@Test
public void testDoService_Expiry_Unsupported() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
    ExpiringMapCache cache = createCacheInstanceForTests().withExpiration(new TimeInterval(1L, TimeUnit.SECONDS));
    MyCacheEventListener listener = new MyCacheEventListener();
    cache.getEventListener().addEventListener(listener);
    AddValueToCache service = new AddValueToCache().withExpiry("%message{expiry}").withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
    try {
        start(service);
        // unparseable expiry should not expire.
        msg.addMetadata("expiry", "a");
        service.doService(msg);
        Object value = cache.get(msg.getUniqueId());
        assertEquals("Hello World", value);
        await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(listener::expiredCount, greaterThanOrEqualTo(1));
        assertEquals(0, cache.size());
    } finally {
        stop(service);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) StringPayloadCacheTranslator(com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator) MyCacheEventListener(com.adaptris.core.cache.MyCacheEventListener) Test(org.junit.Test)

Example 60 with TimeInterval

use of com.adaptris.util.TimeInterval in project interlok by adaptris.

the class CheckCacheServiceTest method testDoService_Error.

@Test
public void testDoService_Error() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
    ExpiringMapCache cache = new KeysSizeUnsupportedCache().withMaxEntries(10).withExpiration(new TimeInterval(10L, TimeUnit.SECONDS));
    CheckCacheService service = new CheckCacheService() {

        @Override
        protected boolean eval(AdaptrisMessage msg, FoundInCache callback) throws CoreException {
            throw new CoreException();
        }
    };
    try {
        service.withConnection(new CacheConnection().withCacheInstance(cache));
        service.setKeysFoundServiceId(FOUND);
        service.setKeysNotFoundServiceId(NOT_FOUND);
        start(service);
        cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
        service.doService(msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) MetadataElement(com.adaptris.core.MetadataElement) 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