use of cn.taketoday.cache.Cache in project today-framework 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();
}
use of cn.taketoday.cache.Cache in project today-framework by TAKETODAY.
the class CacheTestUtils method assertCacheHit.
/**
* Assert the following key has a matching value within the specified cache(s).
*/
public static void assertCacheHit(Object key, Object value, Cache... caches) {
for (Cache cache : caches) {
Cache.ValueWrapper wrapper = cache.get(key);
assertThat(wrapper).as("An entry in " + cache + " should have been found with key " + key).isNotNull();
assertThat(wrapper.get()).as("Wrong value in " + cache + " for entry with key " + key).isEqualTo(value);
}
}
use of cn.taketoday.cache.Cache in project today-framework by TAKETODAY.
the class AbstractCacheAnnotationTests method testMultiEvict.
protected void testMultiEvict(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = o1.toString() + "A";
Object r1 = service.multiCache(o1);
Object r2 = service.multiCache(o1);
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
primary.put(o2, o2);
assertThat(r2).isSameAs(r1);
assertThat(primary.get(o1).get()).isSameAs(r1);
assertThat(secondary.get(o1).get()).isSameAs(r1);
service.multiEvict(o1);
assertThat(primary.get(o1)).isNull();
assertThat(secondary.get(o1)).isNull();
assertThat(primary.get(o2)).isNull();
Object r3 = service.multiCache(o1);
Object r4 = service.multiCache(o1);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
assertThat(primary.get(o1).get()).isSameAs(r3);
assertThat(secondary.get(o1).get()).isSameAs(r4);
}
use of cn.taketoday.cache.Cache in project today-framework by TAKETODAY.
the class AbstractCacheAnnotationTests method testMultiPut.
protected void testMultiPut(CacheableService<?> service) {
Object o = 1;
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
assertThat(primary.get(o)).isNull();
assertThat(secondary.get(o)).isNull();
Object r1 = service.multiUpdate(o);
assertThat(primary.get(o).get()).isSameAs(r1);
assertThat(secondary.get(o).get()).isSameAs(r1);
o = 2;
assertThat(primary.get(o)).isNull();
assertThat(secondary.get(o)).isNull();
Object r2 = service.multiUpdate(o);
assertThat(primary.get(o).get()).isSameAs(r2);
assertThat(secondary.get(o).get()).isSameAs(r2);
}
use of cn.taketoday.cache.Cache in project today-framework by TAKETODAY.
the class AbstractCacheAnnotationTests method testMultiCacheAndEvict.
protected void testMultiCacheAndEvict(CacheableService<?> service) {
String methodName = "multiCacheAndEvict";
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
assertThat(secondary.get(methodName)).isNull();
assertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiCacheAndEvict(key);
assertThat(service.multiCacheAndEvict(key)).isSameAs(r1);
// assert the method name is used
assertThat(primary.get(methodName).get()).isSameAs(r1);
assertThat(secondary.get(methodName)).isNull();
assertThat(secondary.get(key)).isNull();
}
Aggregations