DATAREDIS-469 - Throw DataRetrievalFailureException for atomic numbers when key is removed.

We now throw DataRetrievalFailureException in case of get() when the underlying key storing the value of an AtomicInteger, AtomicLong or AtomicDouble is removed from Redis.

Original pull request: #182.
This commit is contained in:
Christoph Strobl
2016-03-24 12:40:09 +01:00
committed by Mark Paluch
parent d097a64bc6
commit 20cfd3e76c
6 changed files with 110 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.ConnectionUtils;
@@ -44,6 +45,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
@@ -210,4 +212,28 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
assertThat(ral.get(), is(32.23));
}
/**
* @see DATAREDIS-469
*/
@Test
public void getThrowsExceptionWhenKeyHasBeenRemoved() {
expectedException.expect(DataRetrievalFailureException.class);
expectedException.expectMessage("'test' seems to no longer exist");
// setup long
RedisAtomicDouble test = new RedisAtomicDouble("test", factory, 1);
assertThat(test.get(), equalTo(1D)); // this passes
RedisTemplate<String, Long> template = new RedisTemplate<String, Long>();
template.setConnectionFactory(factory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
template.afterPropertiesSet();
template.delete("test");
test.get();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
@@ -44,6 +45,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
@@ -180,4 +182,28 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
assertThat(ral.get(), is(32));
}
/**
* @see DATAREDIS-469
*/
@Test
public void getThrowsExceptionWhenKeyHasBeenRemoved() {
expectedException.expect(DataRetrievalFailureException.class);
expectedException.expectMessage("'test' seems to no longer exist");
// setup long
RedisAtomicInteger test = new RedisAtomicInteger("test", factory, 1);
assertThat(test.get(), equalTo(1)); // this passes
RedisTemplate<String, Long> template = new RedisTemplate<String, Long>();
template.setConnectionFactory(factory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
template.afterPropertiesSet();
template.delete("test");
test.get();
}
}

View File

@@ -27,6 +27,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.connection.RedisConnection;
@@ -41,6 +42,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
@@ -151,4 +153,28 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
assertThat(ral.get(), is(32L));
}
/**
* @see DATAREDIS-469
*/
@Test
public void getThrowsExceptionWhenKeyHasBeenRemoved() {
expectedException.expect(DataRetrievalFailureException.class);
expectedException.expectMessage("'test' seems to no longer exist");
// setup long
RedisAtomicLong test = new RedisAtomicLong("test", factory, 1);
assertThat(test.get(), equalTo(1L)); // this passes
RedisTemplate<String, Long> template = new RedisTemplate<String, Long>();
template.setConnectionFactory(factory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
template.afterPropertiesSet();
template.delete("test");
test.get();
}
}