Search in sources :

Example 26 with Cache

use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.

the class AbstractJCacheAnnotationTests method earlyRemove.

@Test
public void earlyRemove() {
    Cache cache = getCache(DEFAULT_CACHE);
    Object key = createKey(this.keyItem);
    Object value = new Object();
    cache.put(key, value);
    service.earlyRemove(this.keyItem);
    assertThat(cache.get(key)).isNull();
}
Also used : Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 27 with Cache

use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.

the class AbstractJCacheAnnotationTests method cacheExceptionVetoed.

@Test
public void cacheExceptionVetoed() {
    Cache cache = getCache(EXCEPTION_CACHE);
    Object key = createKey(this.keyItem);
    assertThat(cache.get(key)).isNull();
    assertThatNullPointerException().isThrownBy(() -> service.cacheWithException(this.keyItem, false));
    assertThat(cache.get(key)).isNull();
}
Also used : Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 28 with Cache

use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.

the class AbstractJCacheAnnotationTests method cacheCheckedException.

@Test
public void cacheCheckedException() {
    Cache cache = getCache(EXCEPTION_CACHE);
    Object key = createKey(this.keyItem);
    assertThat(cache.get(key)).isNull();
    assertThatIOException().isThrownBy(() -> service.cacheWithCheckedException(this.keyItem, true));
    Cache.ValueWrapper result = cache.get(key);
    assertThat(result).isNotNull();
    assertThat(result.get().getClass()).isEqualTo(IOException.class);
}
Also used : Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 29 with Cache

use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.

the class AbstractJCacheAnnotationTests method earlyPutWithExceptionVetoPut.

@Test
public void earlyPutWithExceptionVetoPut() {
    Cache cache = getCache(DEFAULT_CACHE);
    Object key = createKey(this.keyItem);
    Object value = new Object();
    assertThat(cache.get(key)).isNull();
    assertThatNullPointerException().isThrownBy(() -> service.earlyPutWithException(this.keyItem, value, false));
    // This will be cached anyway as the earlyPut has updated the cache before
    Cache.ValueWrapper result = cache.get(key);
    assertThat(result).isNotNull();
    assertThat(result.get()).isEqualTo(value);
}
Also used : Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 30 with Cache

use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.

the class AbstractJCacheAnnotationTests method removeAll.

@Test
public void removeAll() {
    Cache cache = getCache(DEFAULT_CACHE);
    Object key = createKey(this.keyItem);
    cache.put(key, new Object());
    service.removeAll();
    assertThat(isEmpty(cache)).isTrue();
}
Also used : Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Aggregations

Cache (cn.taketoday.cache.Cache)316 Test (org.junit.jupiter.api.Test)180 ConcurrentMapCache (cn.taketoday.cache.concurrent.ConcurrentMapCache)38 CaffeineCache (cn.taketoday.cache.support.CaffeineCache)20 CaffeineCacheManager (cn.taketoday.cache.support.CaffeineCacheManager)17 CacheManager (cn.taketoday.cache.CacheManager)12 Nullable (cn.taketoday.lang.Nullable)8 ArrayList (java.util.ArrayList)8 NoSuchBeanDefinitionException (cn.taketoday.beans.factory.NoSuchBeanDefinitionException)6 SimpleCacheManager (cn.taketoday.cache.support.SimpleCacheManager)6 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)6 Assertions.assertThatIOException (org.assertj.core.api.Assertions.assertThatIOException)6 CacheConfiguration (cn.taketoday.cache.annotation.CacheConfiguration)5 Method (java.lang.reflect.Method)5 LinkedHashSet (java.util.LinkedHashSet)4 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)3 Date (java.util.Date)3 User (test.demo.config.User)3 ValueWrapper (cn.taketoday.cache.Cache.ValueWrapper)2 NoSuchCacheException (cn.taketoday.cache.NoSuchCacheException)2