|
34 | 34 | import java.util.List; |
35 | 35 | import java.util.Map; |
36 | 36 | import java.util.Set; |
| 37 | +import java.util.concurrent.TimeUnit; |
37 | 38 | import java.util.stream.Collectors; |
38 | 39 | import java.util.stream.Stream; |
39 | 40 |
|
@@ -688,38 +689,52 @@ public void testClusterHealthResponseWithEnsureNodeWeighedInParam() throws Excep |
688 | 689 | logger.info("--> network disruption is started"); |
689 | 690 | networkDisruption.startDisrupting(); |
690 | 691 |
|
691 | | - // wait for leader checker to fail |
692 | | - Thread.sleep(13000); |
693 | | - |
694 | | - // Check cluster health for weighed in node when cluster manager is not discovered, health check should |
695 | | - // return a response with 503 status code |
696 | | - assertThrows( |
697 | | - ClusterManagerNotDiscoveredException.class, |
698 | | - () -> client(nodes_in_zone_a.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get() |
699 | | - ); |
700 | | - |
701 | | - // Check cluster health for weighed away node when cluster manager is not discovered, health check should |
702 | | - // return a response with 503 status code |
703 | | - assertThrows( |
704 | | - ClusterManagerNotDiscoveredException.class, |
705 | | - () -> client(nodes_in_zone_c.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get() |
706 | | - ); |
| 692 | + assertBusy(() -> { |
| 693 | + // Check cluster health for weighed in node when cluster manager is not discovered, health check should |
| 694 | + // return a response with 503 status code |
| 695 | + assertThrows( |
| 696 | + ClusterManagerNotDiscoveredException.class, |
| 697 | + () -> client(nodes_in_zone_a.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get() |
| 698 | + ); |
| 699 | + |
| 700 | + // Check cluster health for weighed away node when cluster manager is not discovered, health check should |
| 701 | + // return a response with 503 status code |
| 702 | + assertThrows( |
| 703 | + ClusterManagerNotDiscoveredException.class, |
| 704 | + () -> client(nodes_in_zone_c.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get() |
| 705 | + ); |
| 706 | + }, 1, TimeUnit.MINUTES); |
| 707 | + |
| 708 | + logger.info("--> stop network disruption"); |
707 | 709 | networkDisruption.stopDisrupting(); |
708 | | - Thread.sleep(1000); |
709 | 710 |
|
710 | | - // delete weights |
711 | | - ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin().cluster().prepareDeleteWeightedRouting().setVersion(0).get(); |
712 | | - assertTrue(deleteResponse.isAcknowledged()); |
| 711 | + assertBusy(() -> { |
| 712 | + // delete weights |
| 713 | + ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin() |
| 714 | + .cluster() |
| 715 | + .prepareDeleteWeightedRouting() |
| 716 | + .setVersion(0) |
| 717 | + .get(); |
| 718 | + assertTrue(deleteResponse.isAcknowledged()); |
713 | 719 |
|
714 | | - // Check local cluster health |
715 | | - nodeLocalHealth = client(nodes_in_zone_c.get(0)).admin() |
716 | | - .cluster() |
717 | | - .prepareHealth() |
718 | | - .setLocal(true) |
719 | | - .setEnsureNodeWeighedIn(true) |
720 | | - .get(); |
721 | | - assertFalse(nodeLocalHealth.isTimedOut()); |
722 | | - assertTrue(nodeLocalHealth.hasDiscoveredClusterManager()); |
| 720 | + ClusterHealthResponse clusterHealthResponse = client().admin() |
| 721 | + .cluster() |
| 722 | + .prepareHealth() |
| 723 | + .setWaitForNodes("4") |
| 724 | + .execute() |
| 725 | + .actionGet(); |
| 726 | + assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); |
| 727 | + |
| 728 | + // Check local cluster health |
| 729 | + clusterHealthResponse = client(nodes_in_zone_c.get(0)).admin() |
| 730 | + .cluster() |
| 731 | + .prepareHealth() |
| 732 | + .setLocal(true) |
| 733 | + .setEnsureNodeWeighedIn(true) |
| 734 | + .get(); |
| 735 | + assertFalse(clusterHealthResponse.isTimedOut()); |
| 736 | + assertTrue(clusterHealthResponse.hasDiscoveredClusterManager()); |
| 737 | + }, 1, TimeUnit.MINUTES); |
723 | 738 | } |
724 | 739 |
|
725 | 740 | public void testReadWriteWeightedRoutingMetadataOnNodeRestart() throws Exception { |
|
0 commit comments