+ improve connection cleanup in some tests
This commit is contained in:
@@ -19,19 +19,17 @@ package org.springframework.data.keyvalue.redis.connection;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.data.keyvalue.redis.Address;
|
import org.springframework.data.keyvalue.redis.Address;
|
||||||
|
import org.springframework.data.keyvalue.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.keyvalue.redis.Person;
|
import org.springframework.data.keyvalue.redis.Person;
|
||||||
import org.springframework.data.keyvalue.redis.core.StringRedisTemplate;
|
import org.springframework.data.keyvalue.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer;
|
import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer;
|
||||||
@@ -49,26 +47,17 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
|
|
||||||
protected abstract RedisConnectionFactory getConnectionFactory();
|
protected abstract RedisConnectionFactory getConnectionFactory();
|
||||||
|
|
||||||
private static Set<RedisConnectionFactory> connFactories = new LinkedHashSet<RedisConnectionFactory>();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
connection = new DefaultStringRedisConnection(getConnectionFactory().getConnection());
|
connection = new DefaultStringRedisConnection(getConnectionFactory().getConnection());
|
||||||
connFactories.add(getConnectionFactory());
|
ConnectionFactoryTracker.add(getConnectionFactory());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void cleanUp() {
|
public static void cleanUp() {
|
||||||
if (connFactories != null) {
|
ConnectionFactoryTracker.cleanUp();
|
||||||
for (RedisConnectionFactory connectionFactory : connFactories) {
|
|
||||||
try {
|
|
||||||
((DisposableBean) connectionFactory).destroy();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.err.println("Cannot clean factory " + connectionFactory + ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class RedisAtomicTests {
|
|||||||
intCounter = new RedisAtomicInteger(getClass().getSimpleName() + ":int", factory);
|
intCounter = new RedisAtomicInteger(getClass().getSimpleName() + ":int", factory);
|
||||||
longCounter = new RedisAtomicLong(getClass().getSimpleName() + ":long", factory);
|
longCounter = new RedisAtomicLong(getClass().getSimpleName() + ":long", factory);
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
|
ConnectionFactoryTracker.add(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|||||||
Reference in New Issue
Block a user