diff --git a/pom.xml b/pom.xml
index e6d868411f..7e777e9a15 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-redis
- 1.8.0.BUILD-SNAPSHOT
+ 1.8.0.DATAREDIS-507-SNAPSHOT
Spring Data Redis
diff --git a/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java b/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java
index 18a2504e60..eb32fd1aea 100644
--- a/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java
+++ b/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java
@@ -84,6 +84,7 @@
* Please use {@link RedisTemplate} for this purpose.
*
* @author Christoph Strobl
+ * @author Mark Paluch
* @since 1.7
*/
public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
@@ -447,13 +448,6 @@ public byte[] toBytes(Object source) {
*/
public void destroy() throws Exception {
- if (redisOps instanceof RedisTemplate) {
- RedisConnectionFactory connectionFactory = ((RedisTemplate, ?>) redisOps).getConnectionFactory();
- if (connectionFactory instanceof DisposableBean) {
- ((DisposableBean) connectionFactory).destroy();
- }
- }
-
this.expirationListener.destroy();
this.messageListenerContainer.destroy();
}
diff --git a/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java
index 4e39be81af..a42a465912 100644
--- a/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java
+++ b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java
@@ -29,6 +29,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.beans.factory.DisposableBean;
import org.springframework.dao.DataAccessException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Reference;
@@ -86,6 +87,14 @@ public void tearDown() {
} catch (Exception e) {
// ignore
}
+
+ try {
+ if (connectionFactory instanceof DisposableBean) {
+ ((DisposableBean) connectionFactory).destroy();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
}
/**
diff --git a/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterUnitTests.java b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterUnitTests.java
new file mode 100644
index 0000000000..1b5337e105
--- /dev/null
+++ b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterUnitTests.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.redis.core;
+
+import static org.mockito.Mockito.*;
+
+import java.util.Arrays;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.springframework.data.redis.connection.RedisConnection;
+import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
+
+/**
+ * Unit tests for {@link RedisKeyValueAdapter}.
+ *
+ * @author Mark Paluch
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class RedisKeyValueAdapterUnitTests {
+
+ RedisTemplate, ?> redisTemplate;
+ RedisKeyValueAdapter redisKeyValueAdapter;
+
+ @Mock JedisConnectionFactory jedisConnectionFactoryMock;
+ @Mock RedisConnection redisConnectionMock;
+
+ @Before
+ public void setUp() throws Exception {
+
+ redisTemplate = new RedisTemplate