Skip to content

Commit 30711ae

Browse files
committed
[Test] Make unable master node error more explicit
Instead of NPE, this PR throws an AssertionError with more explicit error message. Relates: elastic#127213
1 parent 72d2c92 commit 30711ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,11 @@ public String getMasterName(@Nullable String viaNode) {
20402040
try {
20412041
ClusterServiceUtils.awaitClusterState(logger, state -> state.nodes().getMasterNode() != null, clusterService(viaNode));
20422042
final ClusterState state = client(viaNode).admin().cluster().prepareState(TEST_REQUEST_TIMEOUT).setLocal(true).get().getState();
2043-
return state.nodes().getMasterNode().getName();
2043+
final DiscoveryNode masterNode = state.nodes().getMasterNode();
2044+
if (masterNode == null) {
2045+
throw new AssertionError("Master is not stable but the method expects a stable master node");
2046+
}
2047+
return masterNode.getName();
20442048
} catch (Exception e) {
20452049
logger.warn("Can't fetch cluster state", e);
20462050
throw new RuntimeException("Can't get master node " + e.getMessage(), e);

0 commit comments

Comments
 (0)