DATAREDIS-606 - Follow along cache contract not allowing misuse of put null value as cache evict strategy.

Adapted test to reflect intended behavior change.
This commit is contained in:
Christoph Strobl
2017-03-03 10:31:48 +01:00
parent 102b437c3f
commit 202bee64a2
2 changed files with 14 additions and 19 deletions

View File

@@ -44,6 +44,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.cache.Cache;
import org.springframework.cache.Cache.ValueRetrievalException;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
@@ -302,21 +303,18 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
assertThat(wrapper.get(), equalTo(value));
}
@Test // DATAREDIS-510
@Test(expected = IllegalArgumentException.class) // DATAREDIS-510, DATAREDIS-606
public void cachePutWithNullShouldNotAddStuffToRedis() {
assumeThat(getAllowCacheNullValues(), is(false));
Object key = getKey();
Object value = getValue();
cache.put(key, null);
assertThat(cache.get(key), is(nullValue()));
}
@Test // DATAREDIS-510
public void cachePutWithNullShouldRemoveKeyIfExists() {
@Test // DATAREDIS-510, DATAREDIS-606
public void cachePutWithNullShouldErrorAndLeaveExistingKeyUntouched() {
assumeThat(getAllowCacheNullValues(), is(false));
@@ -327,9 +325,13 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
assertThat(cache.get(key).get(), is(equalTo(value)));
cache.put(key, null);
try {
cache.put(key, null);
} catch (IllegalArgumentException e) {
// forget this one.
}
assertThat(cache.get(key), is(nullValue()));
assertThat(cache.get(key).get(), is(equalTo(value)));
}
@Test // DATAREDIS-443, DATAREDIS-452
@@ -372,7 +374,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
assertThat(cache.get(key).get(), is(nullValue()));
}
@Test // DATAREDIS-553
@Test(expected = ValueRetrievalException.class) // DATAREDIS-553, DATAREDIS-606
public void testCacheGetSynchronizedNullNotAllowingNull() {
assumeThat(getAllowCacheNullValues(), is(false));
@@ -386,9 +388,6 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
return null;
}
});
assertThat(value, is(nullValue()));
assertThat(cache.get(key), is(nullValue()));
}
@Test // DATAREDIS-553

View File

@@ -34,6 +34,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.cache.Cache;
import org.springframework.cache.Cache.ValueRetrievalException;
import org.springframework.cache.support.NullValue;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.RedisClusterConnection;
@@ -209,9 +210,9 @@ public class RedisCacheUnitTests {
});
}
@Test // DATAREDIS-553
@Test(expected = ValueRetrievalException.class) // DATAREDIS-553, DATAREDIS-606
@SuppressWarnings("unchecked")
public void getWithCallableShouldStoreNullNotAllowingNull() throws ClassNotFoundException {
public void getWithCallableShouldThrowExceptionSotringNullWhenNotAllowingNull() throws ClassNotFoundException {
cache = new RedisCache(CACHE_NAME, NO_PREFIX_BYTES, templateSpy, 0L, false);
@@ -221,11 +222,6 @@ public class RedisCacheUnitTests {
return null;
}
});
verify(connectionMock).get(eq(KEY_BYTES));
verify(connectionMock).multi();
verify(connectionMock).del(eq(KEY_BYTES));
verify(connectionMock).exec();
}
@Test // DATAREDIS-553