From 4d8f4c2b16e6310ae114f54638c3cccf6ec98a0e Mon Sep 17 00:00:00 2001 From: oliviarla Date: Thu, 12 Sep 2024 17:25:57 +0900 Subject: [PATCH] INTERNAL: remove deprecation of wantToGetException --- docs/02-arcus-spring-concept.md | 4 ++-- .../arcus/spring/cache/ArcusCache.java | 10 ++++---- .../spring/cache/ArcusCacheConfiguration.java | 14 +++++++---- .../arcus/spring/cache/ArcusCacheTest.java | 23 +++++++++++++++++++ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/docs/02-arcus-spring-concept.md b/docs/02-arcus-spring-concept.md index fd5b56c..fb7e56f 100644 --- a/docs/02-arcus-spring-concept.md +++ b/docs/02-arcus-spring-concept.md @@ -83,8 +83,8 @@ ArcusCacheConfiguration 객체를 생성하고 아래 메소드를 통해 속성 - 인자로 null을 입력할 수 없다. - `enableGettingException()` / `disableGettingException()` - ARCUS Client의 연산에서 발생하는 예외를 받을지 여부를 설정한다. - - 기본적으로 disable 상태이며 예외가 발생하면 원본 메서드를 수행하도록 한다. - - enable시킬 경우 예외가 발생하면 그대로 반환하므로 직접 상황에 맞게 예외를 처리해주어야 한다. + - 기본적으로 disable 상태이며 예외가 발생하면 반환하지 않고 로깅만 하여, 원본 메서드가 수행되도록 한다. 단, InterruptedException의 경우 그대로 반환된다. + - enable시킬 경우 예외가 발생하면 그대로 반환하므로, 직접 상황에 맞게 예외를 처리해주어야 한다. - `enableCachingNullValues()` / `disableCachingNullValues()` - 캐시 아이템의 값으로 null을 허용할지 여부를 설정한다. - 기본적으로 enable 상태이며 null 값을 NullValue 객체로 변환하여 캐시에 저장한다. diff --git a/src/main/java/com/navercorp/arcus/spring/cache/ArcusCache.java b/src/main/java/com/navercorp/arcus/spring/cache/ArcusCache.java index ee7803f..d79f4fa 100644 --- a/src/main/java/com/navercorp/arcus/spring/cache/ArcusCache.java +++ b/src/main/java/com/navercorp/arcus/spring/cache/ArcusCache.java @@ -147,7 +147,7 @@ protected Object lookup(Object key) { try { return getValue(arcusKey); } catch (Exception e) { - if (configuration.isWantToGetException()) { + if (e instanceof InterruptedException || configuration.isWantToGetException()) { throw toRuntimeException(e); } logger.info("failed to lookup. error: {}, key: {}", e.getMessage(), arcusKey); @@ -200,7 +200,7 @@ public void put(final Object key, final Object value) { try { putValue(arcusKey, toStoreValue(value)); } catch (Exception e) { - if (configuration.isWantToGetException()) { + if (e instanceof InterruptedException || configuration.isWantToGetException()) { throw toRuntimeException(e); } logger.info("failed to put. error: {}, key: {}", e.getMessage(), arcusKey); @@ -229,7 +229,7 @@ public ValueWrapper putIfAbsent(Object key, Object value) { try { return putIfAbsentValue(arcusKey, toStoreValue(value)); } catch (Exception e) { - if (configuration.isWantToGetException()) { + if (e instanceof InterruptedException || configuration.isWantToGetException()) { throw toRuntimeException(e); } logger.info("failed to putIfAbsent. error: {}, key: {}", e.getMessage(), arcusKey); @@ -252,7 +252,7 @@ public void evict(final Object key) { logger.info("failed to evict a key: {}, status: {}", arcusKey, status.getMessage()); } } catch (Exception e) { - if (configuration.isWantToGetException()) { + if (e instanceof InterruptedException || configuration.isWantToGetException()) { throw toRuntimeException(e); } logger.info("failed to evict. error: {}, key: {}", e.getMessage(), arcusKey); @@ -281,7 +281,7 @@ public void clear() { logger.info("failed to clear a prefix: {}, status: {}", arcusPrefix, status.getMessage()); } } catch (Exception e) { - if (configuration.isWantToGetException()) { + if (e instanceof InterruptedException || configuration.isWantToGetException()) { throw toRuntimeException(e); } logger.info("failed to clear. error: {}, prefix: {}", e.getMessage(), arcusPrefix); diff --git a/src/main/java/com/navercorp/arcus/spring/cache/ArcusCacheConfiguration.java b/src/main/java/com/navercorp/arcus/spring/cache/ArcusCacheConfiguration.java index 2f5c7e4..f048db2 100644 --- a/src/main/java/com/navercorp/arcus/spring/cache/ArcusCacheConfiguration.java +++ b/src/main/java/com/navercorp/arcus/spring/cache/ArcusCacheConfiguration.java @@ -29,7 +29,6 @@ public class ArcusCacheConfiguration { static final long DEFAULT_TIMEOUT_MILLISECONDS = 700L; - @Deprecated static final boolean DEFAULT_WANT_TO_GET_EXCEPTION = false; static final boolean DEFAULT_ALLOW_NULL_VALUES = true; @@ -44,7 +43,6 @@ public class ArcusCacheConfiguration { private ArcusFrontCache arcusFrontCache; private int frontExpireSeconds = 5; private boolean forceFrontCaching; - @Deprecated private boolean wantToGetException = DEFAULT_WANT_TO_GET_EXCEPTION; private boolean allowNullValues = DEFAULT_ALLOW_NULL_VALUES; @@ -103,13 +101,20 @@ public ArcusCacheConfiguration disableForcingFrontCache() { return this; } - @Deprecated + /** + * Throw exception when Arcus request failed by error, cancellation, timeout. + * If {@link java.lang.InterruptedException} occurred, it will be thrown. + * Exception should be handled by customarily. + */ public ArcusCacheConfiguration enableGettingException() { this.wantToGetException = true; return this; } - @Deprecated + /** + * Do not throw exception when Arcus request failed by error, cancellation, timeout. + * Instead, log the details of exception at INFO level. + */ public ArcusCacheConfiguration disableGettingException() { this.wantToGetException = false; return this; @@ -192,7 +197,6 @@ public void setArcusFrontCache(@Nullable ArcusFrontCache arcusFrontCache) { this.arcusFrontCache = arcusFrontCache; } - @Deprecated public boolean isWantToGetException() { return wantToGetException; } diff --git a/src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheTest.java b/src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheTest.java index f3f312f..c580353 100644 --- a/src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheTest.java +++ b/src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheTest.java @@ -21,6 +21,7 @@ import com.navercorp.arcus.spring.concurrent.KeyLockProvider; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; @@ -163,6 +164,28 @@ public void testGet_FutureException() { assertNull(value); } + @Test + public void testGet_InterruptedException() { + // given + GetFuture future = new GetFuture(null, 0) { + @Override + public Object get(long timeout, TimeUnit unit) throws InterruptedException { + throw new InterruptedException(); + } + }; + + // when + when(arcusClientPool.asyncGet(arcusKey)) + .thenReturn(future); + try { + arcusCache.get(ARCUS_STRING_KEY); + } catch (Exception e) { + // then + assertEquals(RuntimeException.class, e.getClass()); + assertEquals(InterruptedException.class, e.getCause().getClass()); + } + } + @Test public void testGet_FrontCache_CacheHit() { // given