From 392dc95d467eca55630083cedbf3bae3c1590689 Mon Sep 17 00:00:00 2001 From: markharwood Date: Fri, 14 Sep 2018 11:07:24 +0100 Subject: [PATCH] Test fix - Graph vertices could appear in different orders based on map insertion sequence Closes #33686 --- .../xpack/graph/GraphExploreResponseTests.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/graph/GraphExploreResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/graph/GraphExploreResponseTests.java index 9c4a76fdcecf1..fb3b483d23a7e 100644 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/graph/GraphExploreResponseTests.java +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/graph/GraphExploreResponseTests.java @@ -26,6 +26,8 @@ import org.elasticsearch.test.AbstractXContentTestCase; import java.io.IOException; +import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.function.Predicate; @@ -105,8 +107,17 @@ protected void assertEqualInstances( GraphExploreResponse expectedInstance, Gra Connection[] expectedConns = expectedInstance.getConnections().toArray(new Connection[0]); assertArrayEquals(expectedConns, newConns); - Vertex[] newVertices = newInstance.getVertices().toArray(new Vertex[0]); + //Sort the vertices lists before equality test (map insertion sequences can cause order differences) + Comparator comparator = new Comparator() { + @Override + public int compare(Vertex o1, Vertex o2) { + return o1.getId().toString().compareTo(o2.getId().toString()); + } + }; + Vertex[] newVertices = newInstance.getVertices().toArray(new Vertex[0]); Vertex[] expectedVertices = expectedInstance.getVertices().toArray(new Vertex[0]); + Arrays.sort(newVertices, comparator); + Arrays.sort(expectedVertices, comparator); assertArrayEquals(expectedVertices, newVertices); ShardOperationFailedException[] newFailures = newInstance.getShardFailures();