DATAREDIS-684 - Release Jedis cluster node connections with close().
We now release Jedis cluster node connections with Jedis.close() to the pool instead of Pool.returnResource(…). The close() method itself checks whether the connection was broken and if so, the connection gets destroyed. Destroying broken connections prevents the pool from supplying broken connections on borrow when testOnBorrow is disabled. The only case where we return broken resources ourselves to the Pool is when we discover a broken connection ourselves: If we run into a NullPointerException or RedisConnectionFailureException, then we consider a connection is broken. Original Pull Request: #271
This commit is contained in:
committed by
Christoph Strobl
parent
f5ffa33f7e
commit
b1aef2717e
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2017 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.
|
||||
@@ -17,6 +17,11 @@ package org.springframework.data.redis.connection;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
@@ -26,13 +31,9 @@ import org.junit.Test;
|
||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class ClusterSlotHashUtilsTests {
|
||||
|
||||
@@ -58,7 +59,7 @@ public class ClusterSlotHashUtilsTests {
|
||||
serverSlot.intValue(), slot);
|
||||
|
||||
}
|
||||
pool.returnResource(jedis);
|
||||
jedis.close();
|
||||
} finally {
|
||||
if (cluster != null) {
|
||||
cluster.close();
|
||||
@@ -100,7 +101,7 @@ public class ClusterSlotHashUtilsTests {
|
||||
serverSlot1.intValue(), slot1);
|
||||
|
||||
}
|
||||
pool.returnResource(jedis);
|
||||
jedis.close();
|
||||
} finally {
|
||||
if (cluster != null) {
|
||||
cluster.close();
|
||||
@@ -110,7 +111,7 @@ public class ClusterSlotHashUtilsTests {
|
||||
|
||||
/**
|
||||
* Generate random string using ascii chars {@code ' ' (space)} to {@code 'z'}. Explicitly skipping { and }.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String randomString() {
|
||||
|
||||
@@ -154,6 +154,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
|
||||
verify(con2Mock, times(1)).clusterReplicate(CLUSTER_NODE_1.getId());
|
||||
verify(con1Mock, times(1)).clusterNodes();
|
||||
verify(con1Mock, times(1)).close();
|
||||
verifyZeroInteractions(con1Mock);
|
||||
}
|
||||
|
||||
@@ -314,7 +315,9 @@ public class JedisClusterConnectionUnitTests {
|
||||
connection.time(CLUSTER_NODE_2);
|
||||
|
||||
verify(con2Mock, times(1)).time();
|
||||
verify(con2Mock, times(1)).close();
|
||||
verify(con1Mock, times(1)).clusterNodes();
|
||||
verify(con1Mock, times(1)).close();
|
||||
verifyZeroInteractions(con1Mock, con3Mock);
|
||||
}
|
||||
|
||||
@@ -334,6 +337,7 @@ public class JedisClusterConnectionUnitTests {
|
||||
connection.resetConfigStats(CLUSTER_NODE_2);
|
||||
|
||||
verify(con2Mock, times(1)).configResetStat();
|
||||
verify(con2Mock, times(1)).close();
|
||||
verify(con1Mock, never()).configResetStat();
|
||||
verify(con3Mock, never()).configResetStat();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user