diff --git a/java/integTest/src/test/java/glide/TestUtilities.java b/java/integTest/src/test/java/glide/TestUtilities.java index 8c18e8b98f..51af70e326 100644 --- a/java/integTest/src/test/java/glide/TestUtilities.java +++ b/java/integTest/src/test/java/glide/TestUtilities.java @@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.fail; import glide.api.models.ClusterValue; +import java.util.Arrays; +import java.util.stream.Collectors; import lombok.experimental.UtilityClass; @UtilityClass @@ -23,4 +25,24 @@ public static int getValueFromInfo(String data, String value) { public static T getFirstEntryFromMultiValue(ClusterValue data) { return data.getMultiValue().get(data.getMultiValue().keySet().toArray(String[]::new)[0]); } + + /** + * Replaces 'ping-sent' and 'pong-recv' timestamps in Redis Cluster Nodes output with + * placeholders. + */ + public static String removeTimeStampsFromClusterNodesOutput(String rawOutput) { + return Arrays.stream(rawOutput.split("\n")) + .map( + line -> { + String[] parts = line.split(" "); + // Format for CLUSTER NODES COMMAND: + // ... + if (parts.length > 6) { + parts[4] = "ping-sent"; + parts[5] = "pong-recv"; + } + return String.join(" ", parts); + }) + .collect(Collectors.joining("\n")); + } } diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index 3d1f890028..ce54e474ef 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -5,6 +5,7 @@ import static glide.TestConfiguration.REDIS_VERSION; import static glide.TestUtilities.getFirstEntryFromMultiValue; import static glide.TestUtilities.getValueFromInfo; +import static glide.TestUtilities.removeTimeStampsFromClusterNodesOutput; import static glide.api.BaseClient.OK; import static glide.api.models.commands.InfoOptions.Section.CLIENTS; import static glide.api.models.commands.InfoOptions.Section.CLUSTER; @@ -373,12 +374,14 @@ public void config_rewrite_non_existent_config_file() { @Test @SneakyThrows public void cluster_route_by_address_reaches_correct_node() { + // Masks timestamps in the cluster nodes output to avoid flakiness due to dynamic values. String initialNode = - (String) - clusterClient - .customCommand(new String[] {"cluster", "nodes"}, RANDOM) - .get() - .getSingleValue(); + removeTimeStampsFromClusterNodesOutput( + (String) + clusterClient + .customCommand(new String[] {"cluster", "nodes"}, RANDOM) + .get() + .getSingleValue()); String host = Arrays.stream(initialNode.split("\n")) @@ -389,22 +392,24 @@ public void cluster_route_by_address_reaches_correct_node() { assertNotNull(host); String specifiedClusterNode1 = - (String) - clusterClient - .customCommand(new String[] {"cluster", "nodes"}, new ByAddressRoute(host)) - .get() - .getSingleValue(); + removeTimeStampsFromClusterNodesOutput( + (String) + clusterClient + .customCommand(new String[] {"cluster", "nodes"}, new ByAddressRoute(host)) + .get() + .getSingleValue()); assertEquals(initialNode, specifiedClusterNode1); String[] splitHost = host.split(":"); String specifiedClusterNode2 = - (String) - clusterClient - .customCommand( - new String[] {"cluster", "nodes"}, - new ByAddressRoute(splitHost[0], Integer.parseInt(splitHost[1]))) - .get() - .getSingleValue(); + removeTimeStampsFromClusterNodesOutput( + (String) + clusterClient + .customCommand( + new String[] {"cluster", "nodes"}, + new ByAddressRoute(splitHost[0], Integer.parseInt(splitHost[1]))) + .get() + .getSingleValue()); assertEquals(initialNode, specifiedClusterNode2); }