|
|
|
@ -79,7 +79,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testCacheable(CacheableService<?> service) throws Exception { |
|
|
|
public void testCacheable(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
@ -90,9 +90,9 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r3).isSameAs(r1); |
|
|
|
assertThat(r3).isSameAs(r1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCacheableNull(CacheableService<?> service) throws Exception { |
|
|
|
public void testCacheableNull(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
assertThat((Object) this.cm.getCache("testCache").get(o1)).isNull(); |
|
|
|
assertThat(this.cm.getCache("testCache").get(o1)).isNull(); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cacheNull(o1); |
|
|
|
Object r1 = service.cacheNull(o1); |
|
|
|
Object r2 = service.cacheNull(o1); |
|
|
|
Object r2 = service.cacheNull(o1); |
|
|
|
@ -105,7 +105,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r3).as("Cached value should be null").isNull(); |
|
|
|
assertThat(r3).as("Cached value should be null").isNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCacheableSync(CacheableService<?> service) throws Exception { |
|
|
|
public void testCacheableSync(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cacheSync(o1); |
|
|
|
Object r1 = service.cacheSync(o1); |
|
|
|
@ -116,9 +116,9 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r3).isSameAs(r1); |
|
|
|
assertThat(r3).isSameAs(r1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCacheableSyncNull(CacheableService<?> service) throws Exception { |
|
|
|
public void testCacheableSyncNull(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
assertThat((Object) this.cm.getCache("testCache").get(o1)).isNull(); |
|
|
|
assertThat(this.cm.getCache("testCache").get(o1)).isNull(); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cacheSyncNull(o1); |
|
|
|
Object r1 = service.cacheSyncNull(o1); |
|
|
|
Object r2 = service.cacheSyncNull(o1); |
|
|
|
Object r2 = service.cacheSyncNull(o1); |
|
|
|
@ -131,47 +131,53 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r3).as("Cached value should be null").isNull(); |
|
|
|
assertThat(r3).as("Cached value should be null").isNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEvict(CacheableService<?> service) throws Exception { |
|
|
|
public void testEvict(CacheableService<?> service, boolean successExpected) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
cache.putIfAbsent(o1, -1L); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
service.evict(o1, null); |
|
|
|
service.invalidate(o1); |
|
|
|
if (successExpected) { |
|
|
|
Object r3 = service.cache(o1); |
|
|
|
assertThat(cache.get(o1)).isNull(); |
|
|
|
Object r4 = service.cache(o1); |
|
|
|
} |
|
|
|
assertThat(r3).isNotSameAs(r1); |
|
|
|
else { |
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
assertThat(cache.get(o1)).isNotNull(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object r2 = service.cache(o1); |
|
|
|
|
|
|
|
if (successExpected) { |
|
|
|
|
|
|
|
assertThat(r2).isNotSameAs(r1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEvictEarly(CacheableService<?> service) throws Exception { |
|
|
|
public void testEvictEarly(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
cache.putIfAbsent(o1, -1L); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
service.evictEarly(o1); |
|
|
|
service.evictEarly(o1); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (RuntimeException ex) { |
|
|
|
catch (RuntimeException ex) { |
|
|
|
// expected
|
|
|
|
// expected
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
assertThat(cache.get(o1)).isNull(); |
|
|
|
|
|
|
|
|
|
|
|
Object r3 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
Object r4 = service.cache(o1); |
|
|
|
assertThat(r2).isNotSameAs(r1); |
|
|
|
assertThat(r3).isNotSameAs(r1); |
|
|
|
|
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEvictException(CacheableService<?> service) throws Exception { |
|
|
|
public void testEvictException(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
service.evictWithException(o1); |
|
|
|
service.evictWithException(o1); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -179,67 +185,95 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
// expected
|
|
|
|
// expected
|
|
|
|
} |
|
|
|
} |
|
|
|
// exception occurred, eviction skipped, data should still be in the cache
|
|
|
|
// exception occurred, eviction skipped, data should still be in the cache
|
|
|
|
Object r3 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
assertThat(r3).isSameAs(r1); |
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEvictWKey(CacheableService<?> service) throws Exception { |
|
|
|
public void testEvictWithKey(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
|
|
|
|
service.evict(o1, null); |
|
|
|
service.evict(o1, null); |
|
|
|
Object r3 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
Object r4 = service.cache(o1); |
|
|
|
assertThat(r2).isNotSameAs(r1); |
|
|
|
assertThat(r3).isNotSameAs(r1); |
|
|
|
|
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEvictWKeyEarly(CacheableService<?> service) throws Exception { |
|
|
|
public void testEvictWithKeyEarly(CacheableService<?> service) { |
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
service.invalidateEarly(o1, null); |
|
|
|
service.evictEarly(o1); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
// expected
|
|
|
|
// expected
|
|
|
|
} |
|
|
|
} |
|
|
|
Object r3 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
Object r4 = service.cache(o1); |
|
|
|
assertThat(r2).isNotSameAs(r1); |
|
|
|
assertThat(r3).isNotSameAs(r1); |
|
|
|
|
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEvictAll(CacheableService<?> service) throws Exception { |
|
|
|
public void testEvictAll(CacheableService<?> service, boolean successExpected) { |
|
|
|
|
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
|
|
|
|
|
|
|
|
Object o1 = new Object(); |
|
|
|
Object o1 = new Object(); |
|
|
|
|
|
|
|
Object o2 = new Object(); |
|
|
|
|
|
|
|
cache.putIfAbsent(o1, -1L); |
|
|
|
|
|
|
|
cache.putIfAbsent(o2, -2L); |
|
|
|
|
|
|
|
|
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r1 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o1); |
|
|
|
Object r2 = service.cache(o2); |
|
|
|
|
|
|
|
assertThat(r2).isNotSameAs(r1); |
|
|
|
Object o2 = new Object(); |
|
|
|
|
|
|
|
Object r10 = service.cache(o2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
|
|
|
|
assertThat(r10).isNotSameAs(r1); |
|
|
|
|
|
|
|
service.evictAll(new Object()); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testEvictAllEarly(CacheableService<?> service) { |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
assertThat((Object) cache.get(o1)).isNull(); |
|
|
|
|
|
|
|
assertThat((Object) cache.get(o2)).isNull(); |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
service.evictAllEarly(new Object()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) { |
|
|
|
|
|
|
|
// expected
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
assertThat(cache.get(o1)).isNull(); |
|
|
|
|
|
|
|
assertThat(cache.get(o2)).isNull(); |
|
|
|
|
|
|
|
|
|
|
|
Object r3 = service.cache(o1); |
|
|
|
Object r3 = service.cache(o1); |
|
|
|
Object r4 = service.cache(o1); |
|
|
|
Object r4 = service.cache(o2); |
|
|
|
assertThat(r3).isNotSameAs(r1); |
|
|
|
assertThat(r3).isNotSameAs(r1); |
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
assertThat(r4).isNotSameAs(r2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testConditionalExpression(CacheableService<?> service) throws Exception { |
|
|
|
public void testConditionalExpression(CacheableService<?> service) { |
|
|
|
Object r1 = service.conditional(4); |
|
|
|
Object r1 = service.conditional(4); |
|
|
|
Object r2 = service.conditional(4); |
|
|
|
Object r2 = service.conditional(4); |
|
|
|
|
|
|
|
|
|
|
|
@ -251,7 +285,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testConditionalExpressionSync(CacheableService<?> service) throws Exception { |
|
|
|
public void testConditionalExpressionSync(CacheableService<?> service) { |
|
|
|
Object r1 = service.conditionalSync(4); |
|
|
|
Object r1 = service.conditionalSync(4); |
|
|
|
Object r2 = service.conditionalSync(4); |
|
|
|
Object r2 = service.conditionalSync(4); |
|
|
|
|
|
|
|
|
|
|
|
@ -263,7 +297,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
assertThat(r4).isSameAs(r3); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testUnlessExpression(CacheableService<?> service) throws Exception { |
|
|
|
public void testUnlessExpression(CacheableService<?> service) { |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
cache.clear(); |
|
|
|
cache.clear(); |
|
|
|
service.unless(10); |
|
|
|
service.unless(10); |
|
|
|
@ -272,7 +306,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(cache.get(11)).isNull(); |
|
|
|
assertThat(cache.get(11)).isNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testKeyExpression(CacheableService<?> service) throws Exception { |
|
|
|
public void testKeyExpression(CacheableService<?> service) { |
|
|
|
Object r1 = service.key(5, 1); |
|
|
|
Object r1 = service.key(5, 1); |
|
|
|
Object r2 = service.key(5, 2); |
|
|
|
Object r2 = service.key(5, 2); |
|
|
|
|
|
|
|
|
|
|
|
@ -284,7 +318,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r4).isNotSameAs(r3); |
|
|
|
assertThat(r4).isNotSameAs(r3); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testVarArgsKey(CacheableService<?> service) throws Exception { |
|
|
|
public void testVarArgsKey(CacheableService<?> service) { |
|
|
|
Object r1 = service.varArgsKey(1, 2, 3); |
|
|
|
Object r1 = service.varArgsKey(1, 2, 3); |
|
|
|
Object r2 = service.varArgsKey(1, 2, 3); |
|
|
|
Object r2 = service.varArgsKey(1, 2, 3); |
|
|
|
|
|
|
|
|
|
|
|
@ -297,7 +331,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testNullValue(CacheableService<?> service) throws Exception { |
|
|
|
public void testNullValue(CacheableService<?> service) { |
|
|
|
Object key = new Object(); |
|
|
|
Object key = new Object(); |
|
|
|
assertThat(service.nullValue(key)).isNull(); |
|
|
|
assertThat(service.nullValue(key)).isNull(); |
|
|
|
int nr = service.nullInvocations().intValue(); |
|
|
|
int nr = service.nullInvocations().intValue(); |
|
|
|
@ -307,7 +341,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(service.nullInvocations().intValue()).isEqualTo(nr + 1); |
|
|
|
assertThat(service.nullInvocations().intValue()).isEqualTo(nr + 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testMethodName(CacheableService<?> service, String keyName) throws Exception { |
|
|
|
public void testMethodName(CacheableService<?> service, String keyName) { |
|
|
|
Object key = new Object(); |
|
|
|
Object key = new Object(); |
|
|
|
Object r1 = service.name(key); |
|
|
|
Object r1 = service.name(key); |
|
|
|
assertThat(service.name(key)).isSameAs(r1); |
|
|
|
assertThat(service.name(key)).isSameAs(r1); |
|
|
|
@ -326,27 +360,27 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(cache.get(expectedKey)).isNotNull(); |
|
|
|
assertThat(cache.get(expectedKey)).isNotNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCheckedThrowable(CacheableService<?> service) throws Exception { |
|
|
|
public void testCheckedThrowable(CacheableService<?> service) { |
|
|
|
String arg = UUID.randomUUID().toString(); |
|
|
|
String arg = UUID.randomUUID().toString(); |
|
|
|
assertThatIOException().isThrownBy(() -> |
|
|
|
assertThatIOException().isThrownBy(() -> |
|
|
|
service.throwChecked(arg)) |
|
|
|
service.throwChecked(arg)) |
|
|
|
.withMessage(arg); |
|
|
|
.withMessage(arg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testUncheckedThrowable(CacheableService<?> service) throws Exception { |
|
|
|
public void testUncheckedThrowable(CacheableService<?> service) { |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> |
|
|
|
service.throwUnchecked(1L)) |
|
|
|
service.throwUnchecked(1L)) |
|
|
|
.withMessage("1"); |
|
|
|
.withMessage("1"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCheckedThrowableSync(CacheableService<?> service) throws Exception { |
|
|
|
public void testCheckedThrowableSync(CacheableService<?> service) { |
|
|
|
String arg = UUID.randomUUID().toString(); |
|
|
|
String arg = UUID.randomUUID().toString(); |
|
|
|
assertThatIOException().isThrownBy(() -> |
|
|
|
assertThatIOException().isThrownBy(() -> |
|
|
|
service.throwCheckedSync(arg)) |
|
|
|
service.throwCheckedSync(arg)) |
|
|
|
.withMessage(arg); |
|
|
|
.withMessage(arg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testUncheckedThrowableSync(CacheableService<?> service) throws Exception { |
|
|
|
public void testUncheckedThrowableSync(CacheableService<?> service) { |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> |
|
|
|
service.throwUncheckedSync(1L)) |
|
|
|
service.throwUncheckedSync(1L)) |
|
|
|
.withMessage("1"); |
|
|
|
.withMessage("1"); |
|
|
|
@ -360,12 +394,12 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
public void testCacheUpdate(CacheableService<?> service) { |
|
|
|
public void testCacheUpdate(CacheableService<?> service) { |
|
|
|
Object o = new Object(); |
|
|
|
Object o = new Object(); |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
Cache cache = this.cm.getCache("testCache"); |
|
|
|
assertThat((Object) cache.get(o)).isNull(); |
|
|
|
assertThat(cache.get(o)).isNull(); |
|
|
|
Object r1 = service.update(o); |
|
|
|
Object r1 = service.update(o); |
|
|
|
assertThat(cache.get(o).get()).isSameAs(r1); |
|
|
|
assertThat(cache.get(o).get()).isSameAs(r1); |
|
|
|
|
|
|
|
|
|
|
|
o = new Object(); |
|
|
|
o = new Object(); |
|
|
|
assertThat((Object) cache.get(o)).isNull(); |
|
|
|
assertThat(cache.get(o)).isNull(); |
|
|
|
Object r2 = service.update(o); |
|
|
|
Object r2 = service.update(o); |
|
|
|
assertThat(cache.get(o).get()).isSameAs(r2); |
|
|
|
assertThat(cache.get(o).get()).isSameAs(r2); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -389,8 +423,8 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
Cache primary = this.cm.getCache("primary"); |
|
|
|
Cache primary = this.cm.getCache("primary"); |
|
|
|
Cache secondary = this.cm.getCache("secondary"); |
|
|
|
Cache secondary = this.cm.getCache("secondary"); |
|
|
|
|
|
|
|
|
|
|
|
assertThat((Object) primary.get(o1)).isNull(); |
|
|
|
assertThat(primary.get(o1)).isNull(); |
|
|
|
assertThat((Object) secondary.get(o1)).isNull(); |
|
|
|
assertThat(secondary.get(o1)).isNull(); |
|
|
|
Object r1 = service.multiCache(o1); |
|
|
|
Object r1 = service.multiCache(o1); |
|
|
|
assertThat(primary.get(o1).get()).isSameAs(r1); |
|
|
|
assertThat(primary.get(o1).get()).isSameAs(r1); |
|
|
|
assertThat(secondary.get(o1).get()).isSameAs(r1); |
|
|
|
assertThat(secondary.get(o1).get()).isSameAs(r1); |
|
|
|
@ -401,8 +435,8 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
assertThat(r2).isSameAs(r1); |
|
|
|
assertThat(r3).isSameAs(r1); |
|
|
|
assertThat(r3).isSameAs(r1); |
|
|
|
|
|
|
|
|
|
|
|
assertThat((Object) primary.get(o2)).isNull(); |
|
|
|
assertThat(primary.get(o2)).isNull(); |
|
|
|
assertThat((Object) secondary.get(o2)).isNull(); |
|
|
|
assertThat(secondary.get(o2)).isNull(); |
|
|
|
Object r4 = service.multiCache(o2); |
|
|
|
Object r4 = service.multiCache(o2); |
|
|
|
assertThat(primary.get(o2).get()).isSameAs(r4); |
|
|
|
assertThat(primary.get(o2).get()).isSameAs(r4); |
|
|
|
assertThat(secondary.get(o2).get()).isSameAs(r4); |
|
|
|
assertThat(secondary.get(o2).get()).isSameAs(r4); |
|
|
|
@ -425,9 +459,9 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
assertThat(secondary.get(o1).get()).isSameAs(r1); |
|
|
|
assertThat(secondary.get(o1).get()).isSameAs(r1); |
|
|
|
|
|
|
|
|
|
|
|
service.multiEvict(o1); |
|
|
|
service.multiEvict(o1); |
|
|
|
assertThat((Object) primary.get(o1)).isNull(); |
|
|
|
assertThat(primary.get(o1)).isNull(); |
|
|
|
assertThat((Object) secondary.get(o1)).isNull(); |
|
|
|
assertThat(secondary.get(o1)).isNull(); |
|
|
|
assertThat((Object) primary.get(o2)).isNull(); |
|
|
|
assertThat(primary.get(o2)).isNull(); |
|
|
|
|
|
|
|
|
|
|
|
Object r3 = service.multiCache(o1); |
|
|
|
Object r3 = service.multiCache(o1); |
|
|
|
Object r4 = service.multiCache(o1); |
|
|
|
Object r4 = service.multiCache(o1); |
|
|
|
@ -444,26 +478,26 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
Cache primary = this.cm.getCache("primary"); |
|
|
|
Cache primary = this.cm.getCache("primary"); |
|
|
|
Cache secondary = this.cm.getCache("secondary"); |
|
|
|
Cache secondary = this.cm.getCache("secondary"); |
|
|
|
|
|
|
|
|
|
|
|
assertThat((Object) primary.get(o)).isNull(); |
|
|
|
assertThat(primary.get(o)).isNull(); |
|
|
|
assertThat((Object) secondary.get(o)).isNull(); |
|
|
|
assertThat(secondary.get(o)).isNull(); |
|
|
|
Object r1 = service.multiUpdate(o); |
|
|
|
Object r1 = service.multiUpdate(o); |
|
|
|
assertThat(primary.get(o).get()).isSameAs(r1); |
|
|
|
assertThat(primary.get(o).get()).isSameAs(r1); |
|
|
|
assertThat(secondary.get(o).get()).isSameAs(r1); |
|
|
|
assertThat(secondary.get(o).get()).isSameAs(r1); |
|
|
|
|
|
|
|
|
|
|
|
o = 2; |
|
|
|
o = 2; |
|
|
|
assertThat((Object) primary.get(o)).isNull(); |
|
|
|
assertThat(primary.get(o)).isNull(); |
|
|
|
assertThat((Object) secondary.get(o)).isNull(); |
|
|
|
assertThat(secondary.get(o)).isNull(); |
|
|
|
Object r2 = service.multiUpdate(o); |
|
|
|
Object r2 = service.multiUpdate(o); |
|
|
|
assertThat(primary.get(o).get()).isSameAs(r2); |
|
|
|
assertThat(primary.get(o).get()).isSameAs(r2); |
|
|
|
assertThat(secondary.get(o).get()).isSameAs(r2); |
|
|
|
assertThat(secondary.get(o).get()).isSameAs(r2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testPutRefersToResult(CacheableService<?> service) throws Exception { |
|
|
|
public void testPutRefersToResult(CacheableService<?> service) { |
|
|
|
Long id = Long.MIN_VALUE; |
|
|
|
Long id = Long.MIN_VALUE; |
|
|
|
TestEntity entity = new TestEntity(); |
|
|
|
TestEntity entity = new TestEntity(); |
|
|
|
Cache primary = this.cm.getCache("primary"); |
|
|
|
Cache primary = this.cm.getCache("primary"); |
|
|
|
assertThat((Object) primary.get(id)).isNull(); |
|
|
|
assertThat(primary.get(id)).isNull(); |
|
|
|
assertThat((Object) entity.getId()).isNull(); |
|
|
|
assertThat(entity.getId()).isNull(); |
|
|
|
service.putRefersToResult(entity); |
|
|
|
service.putRefersToResult(entity); |
|
|
|
assertThat(primary.get(id).get()).isSameAs(entity); |
|
|
|
assertThat(primary.get(id).get()).isSameAs(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -503,7 +537,7 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
Object r3 = service.multiConditionalCacheAndEvict(key); |
|
|
|
Object r3 = service.multiConditionalCacheAndEvict(key); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(!r1.equals(r3)).isTrue(); |
|
|
|
assertThat(!r1.equals(r3)).isTrue(); |
|
|
|
assertThat((Object) primary.get(key)).isNull(); |
|
|
|
assertThat(primary.get(key)).isNull(); |
|
|
|
|
|
|
|
|
|
|
|
Object key2 = 3; |
|
|
|
Object key2 = 3; |
|
|
|
Object r2 = service.multiConditionalCacheAndEvict(key2); |
|
|
|
Object r2 = service.multiConditionalCacheAndEvict(key2); |
|
|
|
@ -515,127 +549,132 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCacheable() throws Exception { |
|
|
|
public void testCacheable() { |
|
|
|
testCacheable(this.cs); |
|
|
|
testCacheable(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCacheableNull() throws Exception { |
|
|
|
public void testCacheableNull() { |
|
|
|
testCacheableNull(this.cs); |
|
|
|
testCacheableNull(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCacheableSync() throws Exception { |
|
|
|
public void testCacheableSync() { |
|
|
|
testCacheableSync(this.cs); |
|
|
|
testCacheableSync(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCacheableSyncNull() throws Exception { |
|
|
|
public void testCacheableSyncNull() { |
|
|
|
testCacheableSyncNull(this.cs); |
|
|
|
testCacheableSyncNull(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInvalidate() throws Exception { |
|
|
|
public void testEvict() { |
|
|
|
testEvict(this.cs); |
|
|
|
testEvict(this.cs, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testEarlyInvalidate() throws Exception { |
|
|
|
public void testEvictEarly() { |
|
|
|
testEvictEarly(this.cs); |
|
|
|
testEvictEarly(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testEvictWithException() throws Exception { |
|
|
|
public void testEvictWithException() { |
|
|
|
testEvictException(this.cs); |
|
|
|
testEvictException(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testEvictAll() throws Exception { |
|
|
|
public void testEvictAll() { |
|
|
|
testEvictAll(this.cs); |
|
|
|
testEvictAll(this.cs, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testEvictAllEarly() { |
|
|
|
|
|
|
|
testEvictAllEarly(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInvalidateWithKey() throws Exception { |
|
|
|
public void testEvictWithKey() { |
|
|
|
testEvictWKey(this.cs); |
|
|
|
testEvictWithKey(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testEarlyInvalidateWithKey() throws Exception { |
|
|
|
public void testEvictWithKeyEarly() { |
|
|
|
testEvictWKeyEarly(this.cs); |
|
|
|
testEvictWithKeyEarly(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testConditionalExpression() throws Exception { |
|
|
|
public void testConditionalExpression() { |
|
|
|
testConditionalExpression(this.cs); |
|
|
|
testConditionalExpression(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testConditionalExpressionSync() throws Exception { |
|
|
|
public void testConditionalExpressionSync() { |
|
|
|
testConditionalExpressionSync(this.cs); |
|
|
|
testConditionalExpressionSync(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUnlessExpression() throws Exception { |
|
|
|
public void testUnlessExpression() { |
|
|
|
testUnlessExpression(this.cs); |
|
|
|
testUnlessExpression(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassCacheUnlessExpression() throws Exception { |
|
|
|
public void testClassCacheUnlessExpression() { |
|
|
|
testUnlessExpression(this.cs); |
|
|
|
testUnlessExpression(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testKeyExpression() throws Exception { |
|
|
|
public void testKeyExpression() { |
|
|
|
testKeyExpression(this.cs); |
|
|
|
testKeyExpression(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testVarArgsKey() throws Exception { |
|
|
|
public void testVarArgsKey() { |
|
|
|
testVarArgsKey(this.cs); |
|
|
|
testVarArgsKey(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassCacheCacheable() throws Exception { |
|
|
|
public void testClassCacheCacheable() { |
|
|
|
testCacheable(this.ccs); |
|
|
|
testCacheable(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassCacheInvalidate() throws Exception { |
|
|
|
public void testClassCacheEvict() { |
|
|
|
testEvict(this.ccs); |
|
|
|
testEvict(this.ccs, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassEarlyInvalidate() throws Exception { |
|
|
|
public void testClassEvictEarly() { |
|
|
|
testEvictEarly(this.ccs); |
|
|
|
testEvictEarly(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassEvictAll() throws Exception { |
|
|
|
public void testClassEvictAll() { |
|
|
|
testEvictAll(this.ccs); |
|
|
|
testEvictAll(this.ccs, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassEvictWithException() throws Exception { |
|
|
|
public void testClassEvictWithException() { |
|
|
|
testEvictException(this.ccs); |
|
|
|
testEvictException(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassCacheInvalidateWKey() throws Exception { |
|
|
|
public void testClassCacheEvictWithWKey() { |
|
|
|
testEvictWKey(this.ccs); |
|
|
|
testEvictWithKey(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassEarlyInvalidateWithKey() throws Exception { |
|
|
|
public void testClassEvictWithKeyEarly() { |
|
|
|
testEvictWKeyEarly(this.ccs); |
|
|
|
testEvictWithKeyEarly(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNullValue() throws Exception { |
|
|
|
public void testNullValue() { |
|
|
|
testNullValue(this.cs); |
|
|
|
testNullValue(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassNullValue() throws Exception { |
|
|
|
public void testClassNullValue() { |
|
|
|
Object key = new Object(); |
|
|
|
Object key = new Object(); |
|
|
|
assertThat(this.ccs.nullValue(key)).isNull(); |
|
|
|
assertThat(this.ccs.nullValue(key)).isNull(); |
|
|
|
int nr = this.ccs.nullInvocations().intValue(); |
|
|
|
int nr = this.ccs.nullInvocations().intValue(); |
|
|
|
@ -648,22 +687,22 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMethodName() throws Exception { |
|
|
|
public void testMethodName() { |
|
|
|
testMethodName(this.cs, "name"); |
|
|
|
testMethodName(this.cs, "name"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassMethodName() throws Exception { |
|
|
|
public void testClassMethodName() { |
|
|
|
testMethodName(this.ccs, "nametestCache"); |
|
|
|
testMethodName(this.ccs, "nametestCache"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRootVars() throws Exception { |
|
|
|
public void testRootVars() { |
|
|
|
testRootVars(this.cs); |
|
|
|
testRootVars(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassRootVars() throws Exception { |
|
|
|
public void testClassRootVars() { |
|
|
|
testRootVars(this.ccs); |
|
|
|
testRootVars(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -704,52 +743,52 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNullArg() throws Exception { |
|
|
|
public void testNullArg() { |
|
|
|
testNullArg(this.cs); |
|
|
|
testNullArg(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassNullArg() throws Exception { |
|
|
|
public void testClassNullArg() { |
|
|
|
testNullArg(this.ccs); |
|
|
|
testNullArg(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCheckedException() throws Exception { |
|
|
|
public void testCheckedException() { |
|
|
|
testCheckedThrowable(this.cs); |
|
|
|
testCheckedThrowable(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassCheckedException() throws Exception { |
|
|
|
public void testClassCheckedException() { |
|
|
|
testCheckedThrowable(this.ccs); |
|
|
|
testCheckedThrowable(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCheckedExceptionSync() throws Exception { |
|
|
|
public void testCheckedExceptionSync() { |
|
|
|
testCheckedThrowableSync(this.cs); |
|
|
|
testCheckedThrowableSync(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassCheckedExceptionSync() throws Exception { |
|
|
|
public void testClassCheckedExceptionSync() { |
|
|
|
testCheckedThrowableSync(this.ccs); |
|
|
|
testCheckedThrowableSync(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUncheckedException() throws Exception { |
|
|
|
public void testUncheckedException() { |
|
|
|
testUncheckedThrowable(this.cs); |
|
|
|
testUncheckedThrowable(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassUncheckedException() throws Exception { |
|
|
|
public void testClassUncheckedException() { |
|
|
|
testUncheckedThrowable(this.ccs); |
|
|
|
testUncheckedThrowable(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUncheckedExceptionSync() throws Exception { |
|
|
|
public void testUncheckedExceptionSync() { |
|
|
|
testUncheckedThrowableSync(this.cs); |
|
|
|
testUncheckedThrowableSync(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassUncheckedExceptionSync() throws Exception { |
|
|
|
public void testClassUncheckedExceptionSync() { |
|
|
|
testUncheckedThrowableSync(this.ccs); |
|
|
|
testUncheckedThrowableSync(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -804,12 +843,12 @@ public abstract class AbstractCacheAnnotationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPutRefersToResult() throws Exception { |
|
|
|
public void testPutRefersToResult() { |
|
|
|
testPutRefersToResult(this.cs); |
|
|
|
testPutRefersToResult(this.cs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testClassPutRefersToResult() throws Exception { |
|
|
|
public void testClassPutRefersToResult() { |
|
|
|
testPutRefersToResult(this.ccs); |
|
|
|
testPutRefersToResult(this.ccs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|