use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testMethodName.
protected void testMethodName(CacheableService<?> service, String keyName) {
Object key = new Object();
Object r1 = service.name(key);
assertThat(service.name(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
assertThat(cache.get(keyName)).isNotNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testCustomCacheManager.
@Test
public void testCustomCacheManager() {
CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.class);
Object key = new Object();
Object r1 = this.cs.customCacheManager(key);
assertThat(this.cs.customCacheManager(key)).isSameAs(r1);
Cache cache = customCm.getCache("testCache");
assertThat(cache.get(key)).isNotNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractJCacheAnnotationTests method put.
@Test
public void put() {
Cache cache = getCache(DEFAULT_CACHE);
Object key = createKey(this.keyItem);
Object value = new Object();
assertThat(cache.get(key)).isNull();
service.put(this.keyItem, value);
Cache.ValueWrapper result = cache.get(key);
assertThat(result).isNotNull();
assertThat(result.get()).isEqualTo(value);
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractJCacheAnnotationTests method earlyRemoveWithException.
@Test
public void earlyRemoveWithException() {
Cache cache = getCache(DEFAULT_CACHE);
Object key = createKey(this.keyItem);
Object value = new Object();
cache.put(key, value);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> service.earlyRemoveWithException(this.keyItem, true));
assertThat(cache.get(key)).isNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractJCacheAnnotationTests method earlyRemoveAllWithExceptionVetoRemove.
@Test
public void earlyRemoveAllWithExceptionVetoRemove() {
Cache cache = getCache(DEFAULT_CACHE);
Object key = createKey(this.keyItem);
cache.put(key, new Object());
assertThatNullPointerException().isThrownBy(() -> service.earlyRemoveAllWithException(false));
// This will be remove anyway as the earlyRemove has removed the cache before
assertThat(isEmpty(cache)).isTrue();
}
Aggregations