use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class CheckCacheServiceTest 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 KeysSizeUnsupportedCache().withMaxEntries(10).withExpiration(new TimeInterval(10L, TimeUnit.SECONDS));
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);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class GetAndCacheOauthTokenTest method testService_Expiry.
@Test
public void testService_Expiry() throws Exception {
ExpiringMapCache cache = new ExpiringMapCache().withExpiration(new TimeInterval(5L, TimeUnit.SECONDS));
AccessToken t = new AccessToken(getName());
GetAndCacheOauthToken service = new GetAndCacheOauthToken().withCacheKey("OauthToken").withConnection(new CacheConnection(cache)).withAccessTokenBuilder(new ExpiringAccessToken(t, 1000));
try {
AdaptrisMessage m1 = new DefaultMessageFactory().newMessage(TEXT);
LifecycleHelper.initAndStart(service);
service.doService(m1);
AccessToken t1 = (AccessToken) cache.get("OauthToken");
assertNotNull(t1);
await().atMost(Duration.ofSeconds(3)).with().pollInterval(Duration.ofMillis(100)).until(() -> cache.size() == 0);
AdaptrisMessage m2 = new DefaultMessageFactory().newMessage(TEXT);
service.doService(m2);
AccessToken t2 = (AccessToken) cache.get("OauthToken");
assertNotNull(t2);
assertNotSame(t1, t2);
} finally {
LifecycleHelper.stopAndClose(service);
}
}
use of com.adaptris.core.cache.ExpiringMapCache in project interlok by adaptris.
the class GetAndCacheOauthTokenTest method testService.
@Test
public void testService() throws Exception {
ExpiringMapCache cache = new ExpiringMapCache().withExpiration(new TimeInterval(5L, TimeUnit.SECONDS));
AccessToken t = new AccessToken(getName());
GetAndCacheOauthToken service = new GetAndCacheOauthToken().withCacheKey("OauthToken").withConnection(new CacheConnection(cache)).withAccessTokenBuilder(new DummyAccessTokenBuilder(t));
try {
AdaptrisMessage m1 = new DefaultMessageFactory().newMessage(TEXT);
LifecycleHelper.initAndStart(service);
service.doService(m1);
assertTrue(m1.headersContainsKey("Authorization"));
assertEquals("Bearer " + getName(), m1.getMetadataValue("Authorization"));
AccessToken t1 = (AccessToken) cache.get("OauthToken");
assertNotNull(t1);
AdaptrisMessage m2 = new DefaultMessageFactory().newMessage(TEXT);
service.doService(m2);
assertTrue(m2.headersContainsKey("Authorization"));
assertEquals("Bearer " + getName(), m1.getMetadataValue("Authorization"));
AccessToken t2 = (AccessToken) cache.get("OauthToken");
assertNotNull(t2);
assertSame(t1, t2);
} finally {
LifecycleHelper.stopAndClose(service);
}
}
Aggregations