Skip to content

Commit

Permalink
Guard NodeTopologyView against absent INFO #2243
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Nov 22, 2022
1 parent 490756f commit b913b4a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ private long getReplicationOffset(String info) {

private static <T> T getMatchOrDefault(String haystack, Pattern pattern, Function<String, T> converter, T defaultValue) {

if (haystack == null) {
return defaultValue;
}

Matcher matcher = pattern.matcher(haystack);

if (matcher.find() && LettuceStrings.isNotEmpty(matcher.group(1))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ void shouldReuseKnownUris() {
assertThat(clusterNodes).contains(localhost, otherhost, host3);
}

@Test
void shouldNotFailOnNullInfo() {

RedisURI localhost = RedisURI.create("127.0.0.1", 6479);
RedisURI otherhost = RedisURI.create("127.0.0.2", 7000);

RedisURI host3 = RedisURI.create("127.0.0.3", 7000);

String viewByLocalhost = "1 127.0.0.1:6479 master,myself - 0 1401258245007 2 connected 8000-11999\n"
+ "2 127.0.0.2:7000 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n"
+ "3 127.0.0.3:7000 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";

String viewByOtherhost = "1 127.0.0.2:6479 master - 0 1401258245007 2 connected 8000-11999\n"
+ "2 127.0.0.2:7000 master,myself - 111 1401258245007 222 connected 7000 12000 12002-16383\n"
+ "3 127.0.0.3:7000 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n";

NodeTopologyView localhostView = new NodeTopologyView(localhost, viewByLocalhost, null, 0);
NodeTopologyView otherhostView = new NodeTopologyView(otherhost, viewByOtherhost, null, 0);

NodeTopologyViews nodeTopologyViews = new NodeTopologyViews(Arrays.asList(localhostView, otherhostView));

Set<RedisURI> clusterNodes = nodeTopologyViews.getClusterNodes();
assertThat(clusterNodes).contains(localhost, otherhost, host3);
}

@Test
void shouldFailWithoutOwnPartition() {

Expand Down

0 comments on commit b913b4a

Please sign in to comment.