Skip to content

DATAREDIS-507 - Do not destroy RedisConnectionFactory in RedisKeyValueAdapter.destroy. #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.0.BUILD-SNAPSHOT</version>
<version>1.8.0.DATAREDIS-507-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,6 +87,14 @@ public void tearDown() {
} catch (Exception e) {
// ignore
}

try {
if (connectionFactory instanceof DisposableBean) {
((DisposableBean) connectionFactory).destroy();
}
} catch (Exception e) {
// ignore
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Object, Object>();
redisTemplate.setConnectionFactory(jedisConnectionFactoryMock);
redisTemplate.afterPropertiesSet();

when(jedisConnectionFactoryMock.getConnection()).thenReturn(redisConnectionMock);
when(redisConnectionMock.getConfig("notify-keyspace-events"))
.thenReturn(Arrays.asList("notify-keyspace-events", "KEA"));

redisKeyValueAdapter = new RedisKeyValueAdapter(redisTemplate);
}

@Test
public void destroyShouldNotDestroyConnectionFactory() throws Exception {

redisKeyValueAdapter.destroy();

verify(jedisConnectionFactoryMock, never()).destroy();
}
}