Skip to content

Commit

Permalink
CLEANUP: tidy codes
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviarla committed Sep 20, 2024
1 parent 6573414 commit 905e0f8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 68 deletions.
11 changes: 8 additions & 3 deletions src/main/java/com/navercorp/arcus/spring/cache/ArcusCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@
* 이렇게 설정했을때, 캐시의 키 값으로 생성되는 값은 <span>beta-member:메서드 매개변수로 만든 문자열</span>이 됩니다.
* </p>
*/
@SuppressWarnings({"DeprecatedIsStillUsed", "deprecation"})
@SuppressWarnings({"DeprecatedIsStillUsed"})
public class ArcusCache extends AbstractValueAdaptingCache {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

// TODO: make name, arcusClient final
private String name;
private ArcusClientPool arcusClient;
private final ArcusCacheConfiguration configuration;
Expand All @@ -102,8 +103,12 @@ public ArcusCache(String name, ArcusClientPool clientPool) {

public ArcusCache(String name, ArcusClientPool clientPool, ArcusCacheConfiguration configuration) {
super(requireNonNull(configuration).isAllowNullValues());
this.setName(name);
this.setArcusClient(clientPool);

Assert.notNull(name, "ArcusCache's 'name' property must have a value.");
Assert.notNull(clientPool, "ArcusCache's 'arcusClient' property must not be null.");

this.name = name;
this.arcusClient = clientPool;
this.configuration = configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
*/
public class ArcusCacheManager extends AbstractTransactionSupportingCacheManager implements DisposableBean {
private final ArcusClientPool client;
protected ArcusCacheConfiguration defaultConfiguration;
protected Map<String, ArcusCacheConfiguration> initialCacheConfigs;
private final ArcusCacheConfiguration defaultConfiguration;
private final Map<String, ArcusCacheConfiguration> initialCacheConfigs;
private boolean internalClient;

/**
Expand All @@ -53,11 +53,8 @@ public class ArcusCacheManager extends AbstractTransactionSupportingCacheManager
* @param defaultConfiguration 정의되지 않은 캐시의 기본 설정
* @param initialCacheConfigs 생성할 캐시들의 이름과 설정들의 집합
*/
public ArcusCacheManager(
ArcusClientPool client,
ArcusCacheConfiguration defaultConfiguration,
Map<String, ArcusCacheConfiguration> initialCacheConfigs
) {
public ArcusCacheManager(ArcusClientPool client, ArcusCacheConfiguration defaultConfiguration,
Map<String, ArcusCacheConfiguration> initialCacheConfigs) {
this.client = client;
this.defaultConfiguration = defaultConfiguration;
this.initialCacheConfigs = initialCacheConfigs;
Expand All @@ -67,26 +64,19 @@ public ArcusCacheManager(
/**
* 캐시 매니저 내부에서 Arcus 클라이언트를 생성 및 소멸을 관리하기 위한 생성자.
*
* @param adminAddress Arcus 클라이언트를 생성하기 위해 필요한 캐시의 주소
* @param adminAddress Arcus 클라이언트를 생성하기 위해 필요한 ZooKeeper 주소
* @param serviceCode Arcus 클라이언트를 생성하기 위해 필요한 서비스 코드
* @param connectionFactoryBuilder Arcus 클라이언트를 생성하기 위해 필요한 ConnectionFactory 빌더
* @param poolSize Arcus 클라이언트를 생성하기 위해 필요한 클라이언트 풀 사이즈
* @param defaultConfiguration 정의되지 않은 캐시의 기본 설정
* @param initialCacheConfigs 생성할 캐시들의 이름과 설정들의 집합
*/
public ArcusCacheManager(
String adminAddress,
String serviceCode,
ConnectionFactoryBuilder connectionFactoryBuilder,
int poolSize,
ArcusCacheConfiguration defaultConfiguration,
Map<String, ArcusCacheConfiguration> initialCacheConfigs
) {
this(
ArcusClient.createArcusClientPool(adminAddress, serviceCode, connectionFactoryBuilder, poolSize),
defaultConfiguration,
initialCacheConfigs
);
public ArcusCacheManager(String adminAddress, String serviceCode, ConnectionFactoryBuilder connectionFactoryBuilder,
int poolSize, ArcusCacheConfiguration defaultConfiguration,
Map<String, ArcusCacheConfiguration> initialCacheConfigs) {
this.client = ArcusClient.createArcusClientPool(adminAddress, serviceCode, connectionFactoryBuilder, poolSize);
this.defaultConfiguration = defaultConfiguration;
this.initialCacheConfigs = initialCacheConfigs;
this.internalClient = true;
}

Expand All @@ -103,7 +93,7 @@ public static ArcusCacheManagerBuilder builder(String adminAddress,

@Override
protected Collection<? extends Cache> loadCaches() {
List<Cache> caches = new ArrayList<Cache>(initialCacheConfigs.size());
List<Cache> caches = new ArrayList<>(initialCacheConfigs.size());
for (Map.Entry<String, ArcusCacheConfiguration> entry : initialCacheConfigs.entrySet()) {
caches.add(createCache(entry.getKey(), entry.getValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ void throwExceptionIfGetWithDifferentClassType() {
assertNull(arcusCache.get(TEST_KEY));

arcusCache.put(TEST_KEY, TEST_VALUE);
assertThrows(IllegalStateException.class, () -> {
arcusCache.get(TEST_KEY, Integer.class);
});
assertThrows(IllegalStateException.class, () -> arcusCache.get(TEST_KEY, Integer.class));
}

@Test
Expand All @@ -109,9 +107,7 @@ void throwExceptionIfGetWithValueLoaderFailed() {
};

assertNull(arcusCache.get(TEST_KEY));
assertThrows(RuntimeException.class, () -> {
assertEquals(TEST_VALUE, arcusCache.get(TEST_KEY, valueLoader));
});
assertThrows(RuntimeException.class, () -> assertEquals(TEST_VALUE, arcusCache.get(TEST_KEY, valueLoader)));
}

@Test
Expand Down Expand Up @@ -163,9 +159,7 @@ void putTheNullValueIfAllowNullValuesIsTrue() {

@Test
void putTheNullValueIfAllowNullValuesIsFalse() {
assertThrows(IllegalArgumentException.class, () -> {
arcusCacheWithoutAllowingNullValue.put(TEST_KEY, null);
});
assertThrows(IllegalArgumentException.class, () -> arcusCacheWithoutAllowingNullValue.put(TEST_KEY, null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ void shutdownClientIfArcusClientPoolManagedInCacheManager() throws Exception {
ArcusClientPool client2 = (ArcusClientPool) ReflectionUtils.getField(clientField, this.arcusCacheManagerFromAddress);
assertNotNull(client2);

assertThrows(IllegalStateException.class, () -> {
client2.get(key);
});
assertThrows(IllegalStateException.class, () -> client2.get(key));
}
}
24 changes: 6 additions & 18 deletions src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ void throwExceptionIfPutWithWantToGetException() {
.thenThrow(new TestException());

// when
assertThrows(TestException.class, () -> {
arcusCache.put(ARCUS_STRING_KEY, VALUE);
});
assertThrows(TestException.class, () -> arcusCache.put(ARCUS_STRING_KEY, VALUE));
}

@Test
Expand Down Expand Up @@ -493,9 +491,7 @@ void throwExceptionIfEvictWithWantToGetException() {
.thenThrow(new TestException());

// when
assertThrows(TestException.class, () -> {
arcusCache.evict(ARCUS_STRING_KEY);
});
assertThrows(TestException.class, () -> arcusCache.evict(ARCUS_STRING_KEY));
}

@Test
Expand Down Expand Up @@ -647,9 +643,7 @@ void clearWithWantToGetException() {
.thenReturn(createOperationFutureException());

// when
assertThrows(TestException.class, () -> {
arcusCache.clear();
});
assertThrows(TestException.class, () -> arcusCache.clear());
}

@Test
Expand Down Expand Up @@ -806,9 +800,7 @@ void getWithDifferentClassType() {
.thenReturn(createGetFuture(VALUE));

// when
assertThrows(IllegalStateException.class, () -> {
arcusCache.get(ARCUS_STRING_KEY, Integer.class);
});
assertThrows(IllegalStateException.class, () -> arcusCache.get(ARCUS_STRING_KEY, Integer.class));
}

@Test
Expand All @@ -819,9 +811,7 @@ void throwExceptionIfGetWithClassTypeWithWantToGetException() {
.thenThrow(new TestException());

// when
assertThrows(TestException.class, () -> {
arcusCache.get(ARCUS_STRING_KEY, String.class);
});
assertThrows(TestException.class, () -> arcusCache.get(ARCUS_STRING_KEY, String.class));
}

@Test
Expand All @@ -832,9 +822,7 @@ void throwExceptionIfGetWithClassTypeHasFutureExceptionWithWantToGetException()
.thenReturn(createGetFutureException());

// when
assertThrows(TestException.class, () -> {
arcusCache.get(ARCUS_STRING_KEY, String.class);
});
assertThrows(TestException.class, () -> arcusCache.get(ARCUS_STRING_KEY, String.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ void after() {
@Test
void frontCacheNameConflict() {
new DefaultArcusFrontCache("test", 3L, false, false);
assertThrows(ObjectExistsException.class, () -> {
new DefaultArcusFrontCache("test", 3L, false, false);
});
assertThrows(ObjectExistsException.class, () -> new DefaultArcusFrontCache("test", 3L, false, false));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DefaultKeyLockProviderTest {

@Test
void doNotThrowArrayIndexOufOfBoundsException() {
Set<Integer> hashCodeSet = new HashSet<Integer>();
Set<Integer> hashCodeSet = new HashSet<>();

int exponentOfLocks = DefaultKeyLockProvider.DEFAULT_EXPONENT_OF_LOCKS + 1;
int numberOfLocks = (int) Math.pow(2, exponentOfLocks);
Expand All @@ -51,14 +51,11 @@ void doNotAllowConcurrentAccessIfUsingKeyLockProvider() throws InterruptedExcept
final DefaultKeyLockProvider provider = new DefaultKeyLockProvider();
final TestObject key = new TestObject(0);
final int maxCount = 10000;
final Runnable runnable = new Runnable() {
@Override
public void run() {
for (int i = 0; i < maxCount; i++) {
provider.getLockForKey(key).writeLock().lock();
count++;
provider.getLockForKey(key).writeLock().unlock();
}
final Runnable runnable = () -> {
for (int i = 0; i < maxCount; i++) {
provider.getLockForKey(key).writeLock().lock();
count++;
provider.getLockForKey(key).writeLock().unlock();
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ log4j.appender.console.type=Console
log4j.appender.console.layout.type=PatternLayout
log4j.appender.console.layout.pattern=%-5p: %c - %m%n

log4j.rootLogger.level=INFO,console
log4j.rootLogger.level=INFO,console

log4j.loggers=arcus,spring

Expand Down

0 comments on commit 905e0f8

Please sign in to comment.