use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class CacheConditionTest method testExists.
@Test
public void testExists() throws Exception {
CacheConnection conn = new CacheConnection().withCacheInstance(new ExpiringMapCache());
ExistsInCache condition = new ExistsInCache().withConnection(conn).withKey("%message{key}");
try {
AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
LifecycleHelper.initAndStart(condition);
Cache cache = conn.retrieveCache();
cache.put("key", "VALUE");
message.addMessageHeader("key", "key");
assertTrue(condition.evaluate(message));
} finally {
LifecycleHelper.stopAndClose(condition);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class CacheConditionTest method testDoesNotExist.
@Test
public void testDoesNotExist() throws Exception {
CacheConnection conn = new CacheConnection().withCacheInstance(new ExpiringMapCache());
ExistsInCache condition = new ExistsInCache().withConnection(conn).withKey("does-not-exist");
try {
AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
LifecycleHelper.initAndStart(condition);
Cache cache = conn.retrieveCache();
cache.put("key", "VALUE");
assertFalse(condition.evaluate(message));
} finally {
LifecycleHelper.stopAndClose(condition);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class XmlValidationServiceTest method testValidXmlSchema_Expression.
@Test
public void testValidXmlSchema_Expression() throws Exception {
String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
// if (!ExternalResourcesHelper.isExternalServerAvailable(new URLString(schemaUrl))) {
// log.debug(schemaUrl + " not available, ignoring testMetadataSchemaKeyIsEmpty test");
// return;
// }
BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema("%message{schema-key}").withSchemaCache(new CacheConnection(new ExpiringMapCache().withMaxEntries(1)));
AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
msg.addMetadata("schema-key", schemaUrl);
XmlValidationService service = new XmlValidationService(validator);
try {
LifecycleHelper.initAndStart(service);
service.doService(msg);
// Hits the cache the 2nd time round
service.doService(msg);
} finally {
LifecycleHelper.stopAndClose(service);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class BasicSchemaValidationTest method testBasicSchemaValidator.
@Test
public void testBasicSchemaValidator() 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 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
AdaptrisMessage m2 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
service.doService(m1);
service.doService(m2);
} finally {
LifecycleHelper.stopAndClose(service);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class AddValueToCacheTest method testDoService_AbsoluteExpiry_Date.
@Test
public void testDoService_AbsoluteExpiry_Date() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
ExpiringMapCache cache = createCacheInstanceForTests();
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);
// Expire in 2 seconds or so.
Date expiry = new Date(System.currentTimeMillis() + ThreadLocalRandom.current().nextInt(1000) + 1000);
msg.addMetadata("expiry", DateFormatUtil.format(expiry));
service.doService(msg);
Object value = cache.get(msg.getUniqueId());
assertEquals("Hello World", value);
// Default expiration is > 5 seconds.
await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(listener::expiredCount, greaterThanOrEqualTo(1));
assertEquals(0, cache.size());
} finally {
stop(service);
}
}
Aggregations