DATAREDIS-416 - RedisCache.putIfAbsent(…) now returns null for first addition.

We now return null for RedisCache.putIfAbesent(…) when value is set to meet the contract defined by org.springframework.cache.Cache.putIfAbsent(…).

Original pull request: #150.
This commit is contained in:
Christoph Strobl
2015-07-23 15:11:16 +02:00
committed by Oliver Gierke
parent b2bae8f8fb
commit 7073502e42
2 changed files with 7 additions and 7 deletions

View File

@@ -250,6 +250,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
/**
* @see DATAREDIS-344
* @see DATAREDIS-416
*/
@Test
public void putIfAbsentShouldSetValueOnlyIfNotPresent() {
@@ -262,16 +263,15 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
template.delete(key);
Object value = getValue();
assertThat(redisCache.putIfAbsent(key, value), nullValue());
ValueWrapper wrapper = redisCache.putIfAbsent(key, value);
assertThat(wrapper.get(), sameInstance(value));
ValueWrapper wrapper2 = redisCache.putIfAbsent(key, value);
if (!(value instanceof Number)) {
assertThat(wrapper2.get(), not(sameInstance(value)));
assertThat(wrapper.get(), not(sameInstance(value)));
}
assertThat(wrapper2.get(), equalTo(value));
assertThat(wrapper.get(), equalTo(value));
}
}