@Test public void testCacheOnErrorEvent() { CacheOnErrorEvent cacheOnErrorEvent = new CacheOnErrorEvent("test", new IOException()); assertThat(cacheOnErrorEvent.getCacheName()).isEqualTo("test"); assertThat(cacheOnErrorEvent.getThrowable()).isInstanceOf(IOException.class); assertThat(cacheOnErrorEvent.getEventType()).isEqualTo(Type.ERROR); assertThat(cacheOnErrorEvent.toString()).contains("Cache 'test' recorded an error: 'java.io.IOException'."); }
@Override public String toString() { return String.format("%s: Cache '%s' recorded an error: '%s'.", getCreationTime(), getCacheName(), getThrowable().toString()); } }
private void onError(Throwable throwable) { publishCacheEvent(() -> new CacheOnErrorEvent(cache.getName(), throwable)); }
@Test public void shouldConsumeOnErrorEvent() throws Throwable { // Given the cache does not contain the key given(cache.get("testKey")).willThrow(new WebServiceException("BLA")); Cache<String, String> cacheContext = Cache.of(cache); cacheContext.getEventPublisher().onError(event -> logger.info(event.getEventType().toString())); CheckedFunction1<String, String> cachedFunction = Cache.decorateCheckedSupplier(cacheContext, () -> "Hello world"); String value = cachedFunction.apply("testKey"); assertThat(value).isEqualTo("Hello world"); then(logger).should(times(1)).info("ERROR"); }
private void onError(Throwable throwable) { publishCacheEvent(() -> new CacheOnErrorEvent(cache.getName(), throwable)); }
@Override public String toString() { return String.format("%s: Cache '%s' recorded an error: '%s'.", getCreationTime(), getCacheName(), getThrowable().toString()); } }