use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractJCacheAnnotationTests method cacheWithCustomCacheResolver.
@Test
public void cacheWithCustomCacheResolver() {
Cache cache = getCache(DEFAULT_CACHE);
Object key = createKey(this.keyItem);
service.cacheWithCustomCacheResolver(this.keyItem);
// Cache in mock cache
assertThat(cache.get(key)).isNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testEvictAll.
protected void testEvictAll(CacheableService<?> service, boolean successExpected) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
Object o2 = new Object();
cache.putIfAbsent(o1, -1L);
cache.putIfAbsent(o2, -2L);
Object r1 = service.cache(o1);
Object r2 = service.cache(o2);
assertThat(r2).isNotSameAs(r1);
service.evictAll(new Object());
if (successExpected) {
assertThat(cache.get(o1)).isNull();
assertThat(cache.get(o2)).isNull();
} else {
assertThat(cache.get(o1)).isNotNull();
assertThat(cache.get(o2)).isNotNull();
}
Object r3 = service.cache(o1);
Object r4 = service.cache(o2);
if (successExpected) {
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isNotSameAs(r2);
} else {
assertThat(r3).isSameAs(r1);
assertThat(r4).isSameAs(r2);
}
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testCacheUpdate.
protected void testCacheUpdate(CacheableService<?> service) {
Object o = new Object();
Cache cache = this.cm.getCache("testCache");
assertThat(cache.get(o)).isNull();
Object r1 = service.update(o);
assertThat(cache.get(o).get()).isSameAs(r1);
o = new Object();
assertThat(cache.get(o)).isNull();
Object r2 = service.update(o);
assertThat(cache.get(o).get()).isSameAs(r2);
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testEvict.
protected void testEvict(CacheableService<?> service, boolean successExpected) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
cache.putIfAbsent(o1, -1L);
Object r1 = service.cache(o1);
service.evict(o1, null);
if (successExpected) {
assertThat(cache.get(o1)).isNull();
} else {
assertThat(cache.get(o1)).isNotNull();
}
Object r2 = service.cache(o1);
if (successExpected) {
assertThat(r2).isNotSameAs(r1);
} else {
assertThat(r2).isSameAs(r1);
}
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testMultiConditionalCacheAndEvict.
protected void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
assertThat(primary.get(key)).isNull();
assertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
assertThat(!r1.equals(r3)).isTrue();
assertThat(primary.get(key)).isNull();
Object key2 = 3;
Object r2 = service.multiConditionalCacheAndEvict(key2);
assertThat(service.multiConditionalCacheAndEvict(key2)).isSameAs(r2);
// assert the method name is used
assertThat(primary.get(key2).get()).isSameAs(r2);
assertThat(secondary.get(key2)).isNull();
}
Aggregations