Skip to content

Commit 5aadc93

Browse files
Fix test infra NPE in doEnsureClusterStateConsistency
1 parent 1e87f67 commit 5aadc93

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,15 @@ private void setMultiProjectParams(Map<String, String> xContentParams) {
13811381
}
13821382
}
13831383

1384+
/**
1385+
* Verifies that all nodes in the cluster see the same master node and cluster UUID and use the same JSON serialization.
1386+
* <ul>
1387+
* <li> Fetches the cluster state from every node in the cluster </li>
1388+
* <li> Fetches the master node's view of the cluster state </li>
1389+
* <li> Compares each node's view with the master node's </li>
1390+
* </ul>
1391+
* @param namedWriteableRegistry
1392+
*/
13841393
protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry namedWriteableRegistry) {
13851394
// This check has very little value in external test clusters and there is no guaranteed method of obtaining the master cluster
13861395
// state in those clusters.
@@ -1408,6 +1417,10 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name
14081417
);
14091418
Map<String, Object> masterStateMap = convertToMap(masterClusterState, xContentParams());
14101419
String masterId = masterClusterState.nodes().getMasterNodeId();
1420+
if (masterId == null) {
1421+
logger.warn("Failed to find an elected master in the cluster state: " + masterClusterState);
1422+
throw new AssertionError("Unable to find master in cluster state. Expecting a stable master node");
1423+
}
14111424
for (SubscribableListener<ClusterStateResponse> localStateListener : localStates) {
14121425
localStateListener.andThenAccept(localClusterStateResponse -> {
14131426
byte[] localClusterStateBytes = ClusterState.Builder.toBytes(localClusterStateResponse.getState());

0 commit comments

Comments
 (0)