use of org.cache2k.integration.ResiliencePolicy in project cache2k by cache2k.
the class EntryProcessorTest method setException_policy_called.
@Test
public void setException_policy_called() {
final String _TEXT = "set inside process";
final AtomicLong _retryLoadAfter = new AtomicLong();
final ResiliencePolicy<Integer, Integer> _policy = new ResiliencePolicy<Integer, Integer>() {
@Override
public long suppressExceptionUntil(final Integer key, final ExceptionInformation exceptionInformation, final CacheEntry<Integer, Integer> cachedContent) {
return 0;
}
@Override
public long retryLoadAfter(final Integer key, final ExceptionInformation exceptionInformation) {
_retryLoadAfter.incrementAndGet();
return ETERNAL;
}
};
Cache<Integer, Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() {
@Override
public void extend(final Cache2kBuilder<Integer, Integer> b) {
b.resiliencePolicy(_policy);
}
});
c.invoke(KEY, new EntryProcessor<Integer, Integer, Object>() {
@Override
public Object process(final MutableCacheEntry<Integer, Integer> e) throws Exception {
e.setException(new IllegalStateException(_TEXT));
return null;
}
});
try {
c.get(KEY);
fail();
} catch (CacheLoaderException ex) {
assertTrue(ex.getCause().toString().contains(_TEXT));
}
assertEquals(1, _retryLoadAfter.get());
}
use of org.cache2k.integration.ResiliencePolicy in project cache2k by cache2k.
the class DefaultResiliencePolicyTest method extractDefaultPolicy.
DefaultResiliencePolicy extractDefaultPolicy() {
TimingHandler h = extractHandler();
if (!(h instanceof TimingHandler.Static)) {
fail(TimingHandler.Static.class + " expected");
}
ResiliencePolicy p = ((TimingHandler.Static) h).resiliencePolicy;
if (!(p instanceof DefaultResiliencePolicy)) {
fail(DefaultResiliencePolicy.class + " expected");
}
return (DefaultResiliencePolicy) p;
}
Aggregations