Skip to content

Commit

Permalink
Test fix - Graph vertices could appear in different orders based on m…
Browse files Browse the repository at this point in the history
…ap insertion sequence (#33709)

Solved by sorting the vertices arrays before comparison
Closes #33686
  • Loading branch information
markharwood committed Sep 14, 2018
1 parent 925d087 commit efad80d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Vertex> comparator = new Comparator<Vertex>() {
@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();
Expand Down

0 comments on commit efad80d

Please sign in to comment.