Test fix - Graph connections could appear in different orders
Graph connections could appear in different orders based on insertion sequence Closes #33686
This commit is contained in:
parent
546e7361ed
commit
c118581617
|
@ -13,6 +13,8 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -88,12 +90,29 @@ public class GraphExploreResponseTests extends AbstractXContentTestCase< GraphEx
|
||||||
assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook()));
|
assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook()));
|
||||||
assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut()));
|
assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut()));
|
||||||
|
|
||||||
|
Comparator<Connection> connComparator = new Comparator<Connection>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Connection o1, Connection o2) {
|
||||||
|
return o1.getId().toString().compareTo(o2.getId().toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
Connection[] newConns = newInstance.getConnections().toArray(new Connection[0]);
|
Connection[] newConns = newInstance.getConnections().toArray(new Connection[0]);
|
||||||
Connection[] expectedConns = expectedInstance.getConnections().toArray(new Connection[0]);
|
Connection[] expectedConns = expectedInstance.getConnections().toArray(new Connection[0]);
|
||||||
|
Arrays.sort(newConns, connComparator);
|
||||||
|
Arrays.sort(expectedConns, connComparator);
|
||||||
assertArrayEquals(expectedConns, newConns);
|
assertArrayEquals(expectedConns, newConns);
|
||||||
|
|
||||||
|
//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[] newVertices = newInstance.getVertices().toArray(new Vertex[0]);
|
||||||
Vertex[] expectedVertices = expectedInstance.getVertices().toArray(new Vertex[0]);
|
Vertex[] expectedVertices = expectedInstance.getVertices().toArray(new Vertex[0]);
|
||||||
|
Arrays.sort(newVertices, comparator);
|
||||||
|
Arrays.sort(expectedVertices, comparator);
|
||||||
assertArrayEquals(expectedVertices, newVertices);
|
assertArrayEquals(expectedVertices, newVertices);
|
||||||
|
|
||||||
ShardOperationFailedException[] newFailures = newInstance.getShardFailures();
|
ShardOperationFailedException[] newFailures = newInstance.getShardFailures();
|
||||||
|
|
|
@ -103,8 +103,16 @@ public class GraphExploreResponseTests extends AbstractXContentTestCase< GraphEx
|
||||||
assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook()));
|
assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook()));
|
||||||
assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut()));
|
assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut()));
|
||||||
|
|
||||||
|
Comparator<Connection> connComparator = new Comparator<Connection>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Connection o1, Connection o2) {
|
||||||
|
return o1.getId().toString().compareTo(o2.getId().toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
Connection[] newConns = newInstance.getConnections().toArray(new Connection[0]);
|
Connection[] newConns = newInstance.getConnections().toArray(new Connection[0]);
|
||||||
Connection[] expectedConns = expectedInstance.getConnections().toArray(new Connection[0]);
|
Connection[] expectedConns = expectedInstance.getConnections().toArray(new Connection[0]);
|
||||||
|
Arrays.sort(newConns, connComparator);
|
||||||
|
Arrays.sort(expectedConns, connComparator);
|
||||||
assertArrayEquals(expectedConns, newConns);
|
assertArrayEquals(expectedConns, newConns);
|
||||||
|
|
||||||
//Sort the vertices lists before equality test (map insertion sequences can cause order differences)
|
//Sort the vertices lists before equality test (map insertion sequences can cause order differences)
|
||||||
|
|
Loading…
Reference in New Issue