Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLEANUP: tidy codes #106

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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