use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class AddValueToCacheTest method testDoService_RelativeExpiry.
@Test
public void testDoService_RelativeExpiry() 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);
// relative expiry, 500ms
msg.addMetadata("expiry", "500");
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);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class CheckAndRetrieveCacheTest 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();
CheckAndRetrieve 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());
assertEquals(LOOKED_UP_VALUE, msg.getMetadataValue(LOOKUP_METADATA_KEY));
} finally {
stop(service);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class CheckAndRetrieveCacheTest 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 = createCacheInstanceForTests();
CheckAndRetrieve 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());
assertEquals(LOOKED_UP_VALUE, msg.getMetadataValue(LOOKUP_METADATA_KEY));
} finally {
stop(service);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class CheckAndRetrieveCacheTest method testDoService_DoesNotUseKeys.
@Test
public void testDoService_DoesNotUseKeys() throws Exception {
AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
ExpiringMapCache cache = new CheckCacheServiceTest.KeysSizeUnsupportedCache().withMaxEntries(10).withExpiration(new TimeInterval(10L, TimeUnit.SECONDS));
CheckAndRetrieve 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());
assertEquals(LOOKED_UP_VALUE, msg.getMetadataValue(LOOKUP_METADATA_KEY));
} finally {
stop(service);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class CheckAndRetrieveCacheTest 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());
assertFalse(msg.headersContainsKey(LOOKUP_METADATA_KEY));
} finally {
stop(service);
}
}
Aggregations