3535import java .nio .file .Files ;
3636import java .nio .file .Path ;
3737import java .nio .file .StandardCopyOption ;
38- import java .util .List ;
3938import java .util .concurrent .CountDownLatch ;
4039import java .util .concurrent .ExecutionException ;
4140import java .util .concurrent .TimeUnit ;
4241import java .util .concurrent .atomic .AtomicLong ;
42+ import java .util .stream .Stream ;
4343
4444import static org .elasticsearch .health .HealthStatus .YELLOW ;
4545import static org .elasticsearch .indices .recovery .RecoverySettings .INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING ;
4646import static org .elasticsearch .node .Node .INITIAL_STATE_TIMEOUT_SETTING ;
47+ import static org .elasticsearch .test .NodeRoles .dataNode ;
4748import static org .elasticsearch .test .NodeRoles .dataOnlyNode ;
4849import static org .elasticsearch .test .NodeRoles .masterNode ;
4950import static org .hamcrest .Matchers .allOf ;
@@ -502,7 +503,19 @@ public void testSettingsAppliedOnMasterReElection() throws Exception {
502503 assertClusterStateSaveOK (savedClusterState .v1 (), savedClusterState .v2 (), "43mb" );
503504 }
504505
505- public void testHealthIndicator () throws Exception {
506+ public void testHealthIndicatorWithSingleNode () throws Exception {
507+ internalCluster ().setBootstrapMasterNodeIndex (0 );
508+ logger .info ("--> start the node" );
509+ String nodeName = internalCluster ().startNode ((dataNode ()));
510+ FileSettingsService masterFileSettingsService = internalCluster ().getInstance (FileSettingsService .class , nodeName );
511+ assertBusy (() -> assertTrue (masterFileSettingsService .watching ()));
512+
513+ ensureStableCluster (1 );
514+
515+ testHealthIndicatorOnError (nodeName , nodeName );
516+ }
517+
518+ public void testHealthIndicatorWithSeparateHealthNode () throws Exception {
506519 internalCluster ().setBootstrapMasterNodeIndex (0 );
507520 logger .info ("--> start a data node to act as the health node" );
508521 String healthNode = internalCluster ().startNode (
@@ -518,7 +531,14 @@ public void testHealthIndicator() throws Exception {
518531
519532 ensureStableCluster (2 );
520533
521- // Initially, all is well
534+ testHealthIndicatorOnError (masterNode , healthNode );
535+ }
536+
537+ /**
538+ * {@code masterNode} and {@code healthNode} can be the same node.
539+ */
540+ private void testHealthIndicatorOnError (String masterNode , String healthNode ) throws Exception {
541+ logger .info ("--> ensure all is well before the error" );
522542 assertBusy (() -> {
523543 FetchHealthInfoCacheAction .Response healthNodeResponse = client ().execute (
524544 FetchHealthInfoCacheAction .INSTANCE ,
@@ -545,7 +565,7 @@ public void testHealthIndicator() throws Exception {
545565 healthNodeResponse .getHealthInfo ().fileSettingsHealthInfo ().failureStreak ()
546566 );
547567
548- for (var node : List .of (masterNode , healthNode )) {
568+ for (var node : Stream .of (masterNode , healthNode ). distinct (). toList ( )) {
549569 GetHealthAction .Response getHealthResponse = client (node ).execute (
550570 GetHealthAction .INSTANCE ,
551571 new GetHealthAction .Request (false , 123 )
0 commit comments