Search in sources :

Example 6 with ExpiringMapCache

use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.

the class CheckCacheServiceTest method testDoService_InCache.

@Test
public void testDoService_InCache() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
    ExpiringMapCache cache = createCacheInstanceForTests();
    CheckCacheService service = createServiceForTests();
    try {
        service.setConnection(new CacheConnection(cache));
        service.setKeysFoundServiceId(FOUND);
        service.setKeysNotFoundServiceId(NOT_FOUND);
        start(service);
        cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
        service.doService(msg);
        assertEquals(FOUND, msg.getNextServiceId());
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 7 with ExpiringMapCache

use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.

the class CheckCacheServiceTest method testDoService_NotInCache.

@Test
public void testDoService_NotInCache() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
    ExpiringMapCache cache = createCacheInstanceForTests();
    CheckCacheService service = createServiceForTests();
    try {
        service.setConnection(new CacheConnection(cache));
        service.setKeysFoundServiceId(FOUND);
        service.setKeysNotFoundServiceId(NOT_FOUND);
        start(service);
        service.doService(msg);
        assertEquals(NOT_FOUND, msg.getNextServiceId());
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 8 with ExpiringMapCache

use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.

the class ServiceFromCacheTest method createCache.

private CacheConnection createCache(String key) throws Exception {
    ExpiringMapCache cacheInstance = new ExpiringMapCache();
    CacheConnection conn = new CacheConnection();
    conn.setCacheInstance(cacheInstance);
    LifecycleHelper.initAndStart(conn);
    conn.retrieveCache().put(key, DynamicServiceExecutorTest.createMessage(new ServiceList(new LogMessageService())).getContent());
    return conn;
}
Also used : ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) ServiceList(com.adaptris.core.ServiceList) LogMessageService(com.adaptris.core.services.LogMessageService) CacheConnection(com.adaptris.core.services.cache.CacheConnection)

Example 9 with ExpiringMapCache

use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.

the class BasicSchemaValidationTest method testBasicSchemaValidator_Exception.

@Test(expected = ServiceException.class)
public void testBasicSchemaValidator_Exception() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
    BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema(schemaUrl).withSchemaCache(new CacheConnection().withCacheInstance(new ExpiringMapCache()));
    XmlValidationService service = new XmlValidationService(validator);
    try {
        LifecycleHelper.initAndStart(service);
        AdaptrisMessage m1 = new DefectiveMessageFactory(WhenToBreak.BOTH).newMessage();
        service.doService(m1);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) XmlValidationService(com.adaptris.core.transform.XmlValidationService) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 10 with ExpiringMapCache

use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.

the class XmlSchemaValidatorImpl method prepare.

@Override
public void prepare() throws CoreException {
    schemaCacheConnection = ObjectUtils.defaultIfNull(getSchemaCache(), new CacheConnection(new ExpiringMapCache().withExpiration(DEFAULT_CACHE_TTL).withMaxEntries(DEFAULT_CACHE_SIZE)));
    LifecycleHelper.prepare(schemaCacheConnection);
}
Also used : ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection)

Aggregations

ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)23 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)21 Test (org.junit.Test)21 CacheConnection (com.adaptris.core.services.cache.CacheConnection)10 MetadataElement (com.adaptris.core.MetadataElement)8 TimeInterval (com.adaptris.util.TimeInterval)8 MyCacheEventListener (com.adaptris.core.cache.MyCacheEventListener)5 StringPayloadCacheTranslator (com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator)5 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)3 Cache (com.adaptris.core.cache.Cache)2 XmlValidationService (com.adaptris.core.transform.XmlValidationService)2 CoreException (com.adaptris.core.CoreException)1 ServiceException (com.adaptris.core.ServiceException)1 ServiceList (com.adaptris.core.ServiceList)1 LogMessageService (com.adaptris.core.services.LogMessageService)1 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)1 BasicXmlSchemaValidator (com.adaptris.core.transform.schema.BasicXmlSchemaValidator)1 Date (java.util.Date)1