Skip to content

Commit

Permalink
INTERNAL: remove deprecation of wantToGetException
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviarla authored and jhpark816 committed Sep 12, 2024
1 parent 5770901 commit 4d8f4c2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/02-arcus-spring-concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ ArcusCacheConfiguration 객체를 생성하고 아래 메소드를 통해 속성
- 인자로 null을 입력할 수 없다.
- `enableGettingException()` / `disableGettingException()`
- ARCUS Client의 연산에서 발생하는 예외를 받을지 여부를 설정한다.
- 기본적으로 disable 상태이며 예외가 발생하면 원본 메서드를 수행하도록 한다.
- enable시킬 경우 예외가 발생하면 그대로 반환하므로 직접 상황에 맞게 예외를 처리해주어야 한다.
- 기본적으로 disable 상태이며 예외가 발생하면 반환하지 않고 로깅만 하여, 원본 메서드가 수행되도록 한다. 단, InterruptedException의 경우 그대로 반환된다.
- enable시킬 경우 예외가 발생하면 그대로 반환하므로, 직접 상황에 맞게 예외를 처리해주어야 한다.
- `enableCachingNullValues()` / `disableCachingNullValues()`
- 캐시 아이템의 값으로 null을 허용할지 여부를 설정한다.
- 기본적으로 enable 상태이며 null 값을 NullValue 객체로 변환하여 캐시에 저장한다.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/navercorp/arcus/spring/cache/ArcusCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -192,7 +197,6 @@ public void setArcusFrontCache(@Nullable ArcusFrontCache arcusFrontCache) {
this.arcusFrontCache = arcusFrontCache;
}

@Deprecated
public boolean isWantToGetException() {
return wantToGetException;
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -163,6 +164,28 @@ public void testGet_FutureException() {
assertNull(value);
}

@Test
public void testGet_InterruptedException() {
// given
GetFuture<Object> future = new GetFuture<Object>(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
Expand Down

0 comments on commit 4d8f4c2

Please sign in to comment.