|
47 | 47 | import org.opensearch.cluster.routing.RoutingNode;
|
48 | 48 | import org.opensearch.cluster.routing.RoutingTable;
|
49 | 49 | import org.opensearch.cluster.routing.ShardRoutingState;
|
| 50 | +import org.opensearch.cluster.service.ClusterApplierService; |
| 51 | +import org.opensearch.cluster.service.ClusterManagerService; |
| 52 | +import org.opensearch.cluster.service.ClusterService; |
50 | 53 | import org.opensearch.common.Priority;
|
51 | 54 | import org.opensearch.common.settings.ClusterSettings;
|
52 | 55 | import org.opensearch.common.settings.Settings;
|
|
72 | 75 | import static org.opensearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_CREATE_INDEX_BLOCK_AUTO_RELEASE;
|
73 | 76 | import static org.hamcrest.Matchers.contains;
|
74 | 77 | import static org.hamcrest.Matchers.equalTo;
|
| 78 | +import static org.mockito.Mockito.mock; |
| 79 | +import static org.mockito.Mockito.when; |
75 | 80 |
|
76 | 81 | public class DiskThresholdMonitorTests extends OpenSearchAllocationTestCase {
|
77 | 82 |
|
@@ -116,9 +121,7 @@ public void testMarkFloodStageIndicesReadOnly() {
|
116 | 121 | AtomicReference<Set<String>> indices = new AtomicReference<>();
|
117 | 122 | AtomicLong currentTime = new AtomicLong();
|
118 | 123 | DiskThresholdMonitor monitor = new DiskThresholdMonitor(
|
119 |
| - Settings.EMPTY, |
120 |
| - () -> clusterState, |
121 |
| - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 124 | + createClusterService(Settings.EMPTY, clusterState), |
122 | 125 | null,
|
123 | 126 | currentTime::get,
|
124 | 127 | (reason, priority, listener) -> {
|
@@ -178,9 +181,7 @@ protected void setIndexCreateBlock(ActionListener<Void> listener, boolean indexC
|
178 | 181 | assertTrue(anotherFinalClusterState.blocks().indexBlocked(ClusterBlockLevel.WRITE, "test_2"));
|
179 | 182 |
|
180 | 183 | monitor = new DiskThresholdMonitor(
|
181 |
| - Settings.EMPTY, |
182 |
| - () -> anotherFinalClusterState, |
183 |
| - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 184 | + createClusterService(Settings.EMPTY, anotherFinalClusterState), |
184 | 185 | null,
|
185 | 186 | currentTime::get,
|
186 | 187 | (reason, priority, listener) -> {
|
@@ -219,9 +220,7 @@ public void testDoesNotSubmitRerouteTaskTooFrequently() {
|
219 | 220 | AtomicLong currentTime = new AtomicLong();
|
220 | 221 | AtomicReference<ActionListener<ClusterState>> listenerReference = new AtomicReference<>();
|
221 | 222 | DiskThresholdMonitor monitor = new DiskThresholdMonitor(
|
222 |
| - Settings.EMPTY, |
223 |
| - () -> clusterState, |
224 |
| - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 223 | + createClusterService(Settings.EMPTY, clusterState), |
225 | 224 | null,
|
226 | 225 | currentTime::get,
|
227 | 226 | (reason, priority, listener) -> {
|
@@ -360,9 +359,7 @@ public void testAutoReleaseIndices() {
|
360 | 359 | );
|
361 | 360 |
|
362 | 361 | DiskThresholdMonitor monitor = new DiskThresholdMonitor(
|
363 |
| - Settings.EMPTY, |
364 |
| - () -> clusterState, |
365 |
| - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 362 | + createClusterService(Settings.EMPTY, clusterState), |
366 | 363 | null,
|
367 | 364 | () -> 0L,
|
368 | 365 | (reason, priority, listener) -> {
|
@@ -422,9 +419,7 @@ protected void setIndexCreateBlock(ActionListener<Void> listener, boolean indexC
|
422 | 419 |
|
423 | 420 | assertTrue(clusterStateWithBlocks.blocks().indexBlocked(ClusterBlockLevel.WRITE, "test_2"));
|
424 | 421 | monitor = new DiskThresholdMonitor(
|
425 |
| - Settings.EMPTY, |
426 |
| - () -> clusterStateWithBlocks, |
427 |
| - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 422 | + createClusterService(Settings.EMPTY, clusterStateWithBlocks), |
428 | 423 | null,
|
429 | 424 | () -> 0L,
|
430 | 425 | (reason, priority, listener) -> {
|
@@ -539,9 +534,7 @@ public long getAsLong() {
|
539 | 534 | final AtomicLong relocatingShardSizeRef = new AtomicLong();
|
540 | 535 |
|
541 | 536 | DiskThresholdMonitor monitor = new DiskThresholdMonitor(
|
542 |
| - Settings.EMPTY, |
543 |
| - clusterStateRef::get, |
544 |
| - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 537 | + createClusterService(Settings.EMPTY, clusterState), |
545 | 538 | null,
|
546 | 539 | timeSupplier,
|
547 | 540 | (reason, priority, listener) -> listener.onResponse(clusterStateRef.get())
|
@@ -687,9 +680,7 @@ public void testIndexCreateBlockWhenNoDataNodeHealthy() {
|
687 | 680 | AtomicLong currentTime = new AtomicLong();
|
688 | 681 | Settings settings = Settings.builder().build();
|
689 | 682 | DiskThresholdMonitor monitor = new DiskThresholdMonitor(
|
690 |
| - settings, |
691 |
| - () -> clusterState, |
692 |
| - new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 683 | + createClusterService(settings, clusterState), |
693 | 684 | null,
|
694 | 685 | currentTime::get,
|
695 | 686 | (reason, priority, listener) -> {
|
@@ -766,9 +757,7 @@ public void testIndexCreateBlockRemovedOnlyWhenAnyNodeAboveHighWatermark() {
|
766 | 757 | AtomicLong currentTime = new AtomicLong();
|
767 | 758 | Settings settings = Settings.builder().put(CLUSTER_CREATE_INDEX_BLOCK_AUTO_RELEASE.getKey(), true).build();
|
768 | 759 | DiskThresholdMonitor monitor = new DiskThresholdMonitor(
|
769 |
| - settings, |
770 |
| - () -> clusterState, |
771 |
| - new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), |
| 760 | + createClusterService(settings, clusterState), |
772 | 761 | null,
|
773 | 762 | currentTime::get,
|
774 | 763 | (reason, priority, listener) -> {
|
@@ -905,4 +894,10 @@ private static ClusterInfo clusterInfo(
|
905 | 894 | return new ClusterInfo(diskUsages, null, null, null, reservedSpace, Map.of());
|
906 | 895 | }
|
907 | 896 |
|
| 897 | + private static ClusterService createClusterService(Settings settings, ClusterState clusterState) { |
| 898 | + ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); |
| 899 | + final ClusterApplierService clusterApplierService = mock(ClusterApplierService.class); |
| 900 | + when(clusterApplierService.state()).thenReturn(clusterState); |
| 901 | + return new ClusterService(settings, clusterSettings, mock(ClusterManagerService.class), clusterApplierService); |
| 902 | + } |
908 | 903 | }
|
0 commit comments