Skip to content

Commit 0a3aae1

Browse files
DATAREDIS-481 - Apply existing tests to new implementation
1 parent 51f1e1c commit 0a3aae1

File tree

3 files changed

+467
-3
lines changed

3 files changed

+467
-3
lines changed

src/main/java/org/springframework/data/redis/cache/NRedisCache.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public RedisCacheWriter getNativeCache() {
100100
}
101101

102102
@Override
103-
public <T> T get(Object key, Callable<T> valueLoader) {
103+
public synchronized <T> T get(Object key, Callable<T> valueLoader) {
104104

105105
ValueWrapper result = get(key);
106106

@@ -119,7 +119,10 @@ public void put(Object key, Object value) {
119119
Object cacheValue = preProcessCacheValue(value);
120120

121121
if (!isAllowNullValues() && cacheValue == null) {
122-
return;
122+
123+
throw new IllegalArgumentException(String.format(
124+
"Cache '%s' does not allow 'null' values. Avoid storing null via '@Cacheable(unless=\"#result == null\")' or configure RedisCache to allow 'null' via RedisCacheConfiguration.",
125+
name));
123126
}
124127

125128
cacheWriter.put(name, createAndConvertCacheKey(key), serializeCacheValue(cacheValue), cacheConfig.getTimeout());

src/test/java/org/springframework/data/redis/cache/AbstractNativeCacheTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import static org.junit.Assert.*;
2020
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
2121

22+
import org.hamcrest.core.IsInstanceOf;
2223
import org.junit.Before;
2324
import org.junit.Test;
2425
import org.springframework.cache.Cache;
2526
import org.springframework.cache.Cache.ValueWrapper;
27+
import org.springframework.data.redis.core.RedisTemplate;
2628

2729
/**
2830
* Test for native cache implementations.
@@ -66,7 +68,7 @@ public void testCacheName() throws Exception {
6668

6769
@Test
6870
public void testNativeCache() throws Exception {
69-
assertSame(nativeCache, cache.getNativeCache());
71+
assertThat(cache.getNativeCache(), IsInstanceOf.instanceOf(RedisTemplate.class));
7072
}
7173

7274
@Test

0 commit comments

Comments
 (0)