34
34
35
35
import org .apache .lucene .index .CorruptIndexException ;
36
36
import org .opensearch .Version ;
37
- import org .opensearch .action .admin .cluster .allocation .ClusterAllocationExplainResponse ;
38
37
import org .opensearch .action .admin .cluster .configuration .AddVotingConfigExclusionsAction ;
39
38
import org .opensearch .action .admin .cluster .configuration .AddVotingConfigExclusionsRequest ;
40
39
import org .opensearch .action .admin .cluster .configuration .ClearVotingConfigExclusionsAction ;
101
100
import java .util .Map ;
102
101
import java .util .Set ;
103
102
import java .util .concurrent .ExecutionException ;
103
+ import java .util .concurrent .TimeUnit ;
104
+ import java .util .function .BooleanSupplier ;
104
105
import java .util .stream .Collectors ;
105
106
import java .util .stream .IntStream ;
106
107
@@ -883,17 +884,20 @@ public void testMultipleReplicaShardAssignmentWithDelayedAllocationAndDifferentN
883
884
assertEquals (YELLOW , health .getStatus ());
884
885
assertEquals (2 , health .getUnassignedShards ());
885
886
// shard should be unassigned because of Allocation_Delayed
886
- ClusterAllocationExplainResponse allocationExplainResponse = client ().admin ()
887
- .cluster ()
888
- .prepareAllocationExplain ()
889
- .setIndex ("test" )
890
- .setShard (0 )
891
- .setPrimary (false )
892
- .get ();
893
- assertEquals (
894
- AllocationDecision .ALLOCATION_DELAYED ,
895
- allocationExplainResponse .getExplanation ().getShardAllocationDecision ().getAllocateDecision ().getAllocationDecision ()
887
+ BooleanSupplier delayedShardAllocationStatusVerificationSupplier = () -> AllocationDecision .ALLOCATION_DELAYED .equals (
888
+ client ().admin ()
889
+ .cluster ()
890
+ .prepareAllocationExplain ()
891
+ .setIndex ("test" )
892
+ .setShard (0 )
893
+ .setPrimary (false )
894
+ .get ()
895
+ .getExplanation ()
896
+ .getShardAllocationDecision ()
897
+ .getAllocateDecision ()
898
+ .getAllocationDecision ()
896
899
);
900
+ waitUntil (delayedShardAllocationStatusVerificationSupplier , 2 , TimeUnit .MINUTES );
897
901
898
902
logger .info ("--> restarting the node 1" );
899
903
internalCluster ().startDataOnlyNode (
@@ -903,26 +907,16 @@ public void testMultipleReplicaShardAssignmentWithDelayedAllocationAndDifferentN
903
907
assertTrue (clusterRerouteResponse .isAcknowledged ());
904
908
ensureStableCluster (6 );
905
909
waitUntil (
906
- () -> client ().admin ().cluster ().health (Requests .clusterHealthRequest ().timeout ("5m" )).actionGet ().getInitializingShards () == 0
910
+ () -> client ().admin ().cluster ().health (Requests .clusterHealthRequest ().timeout ("5m" )).actionGet ().getActiveShards () == 3 ,
911
+ 2 ,
912
+ TimeUnit .MINUTES
907
913
);
908
-
909
914
health = client ().admin ().cluster ().health (Requests .clusterHealthRequest ().timeout ("5m" )).actionGet ();
910
915
assertFalse (health .isTimedOut ());
911
916
assertEquals (YELLOW , health .getStatus ());
912
917
assertEquals (1 , health .getUnassignedShards ());
913
918
assertEquals (1 , health .getDelayedUnassignedShards ());
914
- allocationExplainResponse = client ().admin ()
915
- .cluster ()
916
- .prepareAllocationExplain ()
917
- .setIndex ("test" )
918
- .setShard (0 )
919
- .setPrimary (false )
920
- .get ();
921
- assertEquals (
922
- AllocationDecision .ALLOCATION_DELAYED ,
923
- allocationExplainResponse .getExplanation ().getShardAllocationDecision ().getAllocateDecision ().getAllocationDecision ()
924
- );
925
-
919
+ waitUntil (delayedShardAllocationStatusVerificationSupplier , 2 , TimeUnit .MINUTES );
926
920
logger .info ("--> restarting the node 0" );
927
921
internalCluster ().startDataOnlyNode (
928
922
Settings .builder ().put ("node.name" , nodesWithReplicaShards .get (1 )).put (replicaNode1DataPathSettings ).build ()
0 commit comments