DATAREDIS-890 - Polishing.

Add author tags. Use try-with-resources to close Jedis.

Original pull request: #373.
This commit is contained in:
Mark Paluch
2018-11-23 10:14:37 +01:00
parent 4a4a2d6f36
commit b10cdf400c
2 changed files with 10 additions and 12 deletions

View File

@@ -67,6 +67,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Ninad Divadkar
* @author Tao Chen
* @author Chen Guanqun
* @since 1.7
*/
public class JedisClusterConnection implements DefaultedRedisClusterConnection {
@@ -987,12 +988,10 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
List<Entry<String, JedisPool>> list = new ArrayList<>(cluster.getClusterNodes().entrySet());
Collections.shuffle(list);
for (Entry<String, JedisPool> entry : list) {
Jedis jedis = null;
try {
jedis = entry.getValue().getResource();
try (Jedis jedis = entry.getValue().getResource()) {
time = System.currentTimeMillis();
Set<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(jedis.clusterNodes());
@@ -1003,17 +1002,15 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
return cached;
} catch (Exception ex) {
errors.put(entry.getKey(), ex);
} finally {
if (jedis != null) {
jedis.close();
}
}
}
StringBuilder sb = new StringBuilder();
for (Entry<String, Exception> entry : errors.entrySet()) {
sb.append(String.format("\r\n\t- %s failed: %s", entry.getKey(), entry.getValue().getMessage()));
}
throw new ClusterStateFailureException(
"Could not retrieve cluster information. CLUSTER NODES returned with error." + sb.toString());
}

View File

@@ -57,6 +57,7 @@ import org.springframework.data.redis.connection.jedis.JedisClusterConnection.Je
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Chen Guanqun
*/
@RunWith(MockitoJUnitRunner.Silent.class)
public class JedisClusterConnectionUnitTests {
@@ -136,7 +137,7 @@ public class JedisClusterConnectionUnitTests {
connection.clusterMeet(null);
}
@Test // DATAREDIS-315
@Test // DATAREDIS-315, DATAREDIS-890
public void clusterForgetShouldSendCommandsToRemainingNodesCorrectly() {
connection.clusterForget(CLUSTER_NODE_2);
@@ -145,7 +146,7 @@ public class JedisClusterConnectionUnitTests {
verify(con3Mock, times(1)).clusterForget(CLUSTER_NODE_2.getId());
}
@Test // DATAREDIS-315
@Test // DATAREDIS-315, DATAREDIS-890
public void clusterReplicateShouldSendCommandsCorrectly() {
connection.clusterReplicate(CLUSTER_NODE_1, CLUSTER_NODE_2);
@@ -305,7 +306,7 @@ public class JedisClusterConnectionUnitTests {
assertThat(result, is(42L));
}
@Test // DATAREDIS-315
@Test // DATAREDIS-315, DATAREDIS-890
public void timeShouldBeExecutedOnSingleNode() {
when(con2Mock.time()).thenReturn(Arrays.asList("1449655759", "92217"));
@@ -329,7 +330,7 @@ public class JedisClusterConnectionUnitTests {
verify(con3Mock, times(1)).configResetStat();
}
@Test // DATAREDIS-315
@Test // DATAREDIS-315, DATAREDIS-890
public void resetConfigStatsShouldBeExecutedOnSingleNodeCorrectly() {
connection.resetConfigStats(CLUSTER_NODE_2);