-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTERNAL: add builder and transaction for ArcusCacheManager
- Loading branch information
Showing
3 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheManagerBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.navercorp.arcus.spring.cache; | ||
|
||
import java.util.Collections; | ||
|
||
import net.spy.memcached.ArcusClient; | ||
import net.spy.memcached.ArcusClientPool; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.cache.Cache; | ||
import org.springframework.cache.transaction.TransactionAwareCacheDecorator; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class ArcusCacheManagerBuilderTest { | ||
|
||
private final ArcusClientPool arcusClientPool = ArcusClient.createArcusClientPool("localhost:2181", "test", 4); | ||
|
||
@Test | ||
void testMissingCacheMadeByDefaultCacheConfig() { | ||
ArcusCacheConfiguration configuration = new ArcusCacheConfiguration(); | ||
configuration.setServiceId("TEST-"); | ||
ArcusCacheManager cm = ArcusCacheManager.builder(arcusClientPool).cacheDefaults(configuration).build(); | ||
cm.afterPropertiesSet(); | ||
|
||
ArcusCache missingCache = (ArcusCache) cm.getMissingCache("new-cache"); | ||
assertNotNull(missingCache); | ||
assertEquals(configuration.getServiceId(), missingCache.getServiceId()); | ||
assertEquals(configuration.getPrefix(), missingCache.getPrefix()); | ||
assertEquals(configuration.getExpireSeconds(), missingCache.getExpireSeconds()); | ||
} | ||
|
||
@Test | ||
void testSettingDifferentDefaultCacheConfiguration() { | ||
ArcusCacheConfiguration withPrefix = new ArcusCacheConfiguration(); | ||
withPrefix.setPrefix("prefix"); | ||
ArcusCacheConfiguration withoutPrefix = new ArcusCacheConfiguration(); | ||
|
||
ArcusCacheManager cm = ArcusCacheManager.builder(arcusClientPool) | ||
.cacheDefaults(withPrefix) | ||
.initialCacheNames(Collections.singleton("first-cache")) | ||
.cacheDefaults(withoutPrefix) | ||
.initialCacheNames(Collections.singleton("second-cache")) | ||
.build(); | ||
|
||
cm.afterPropertiesSet(); | ||
|
||
ArcusCache firstCache = (ArcusCache) cm.getCache("first-cache"); | ||
assertNotNull(firstCache); | ||
assertEquals(withPrefix.getPrefix(), firstCache.getPrefix()); | ||
ArcusCache secondCache = (ArcusCache) cm.getCache("second-cache"); | ||
assertNotNull(secondCache); | ||
assertNull(withoutPrefix.getPrefix()); | ||
assertEquals(withoutPrefix.getPrefix(), secondCache.getPrefix()); | ||
} | ||
|
||
@Test | ||
void testTransactionAwareCacheManager() { | ||
Cache cache = ArcusCacheManager.builder(arcusClientPool) | ||
.transactionAware() | ||
.build() | ||
.getCache("decorated-cache"); | ||
|
||
assertInstanceOf(TransactionAwareCacheDecorator.class, cache); | ||
} | ||
|
||
@Test | ||
void testArcusClientNull() { | ||
assertThrows(IllegalStateException.class, () -> ArcusCacheManager.builder(null).build()); | ||
} | ||
} |