34
34
import java .util .concurrent .CountDownLatch ;
35
35
import java .util .concurrent .TimeUnit ;
36
36
37
+ import static org .opensearch .cluster .service .ClusterManagerTaskThrottler .THRESHOLD_SETTINGS ;
37
38
import static org .opensearch .test .ClusterServiceUtils .setState ;
38
39
39
40
/**
@@ -75,8 +76,9 @@ public void testDefaults() {
75
76
}, new ClusterManagerThrottlingStats ());
76
77
throttler .registerClusterManagerTask ("put-mapping" , true );
77
78
throttler .registerClusterManagerTask ("create-index" , true );
79
+
78
80
for (String key : throttler .THROTTLING_TASK_KEYS .keySet ()) {
79
- assertNull ( throttler .getThrottlingLimit (key ));
81
+ assertEquals ( 50 , throttler .getThrottlingLimit (key ). intValue ( ));
80
82
}
81
83
}
82
84
@@ -94,11 +96,11 @@ public void testValidateSettingsForDifferentVersion() {
94
96
}, new ClusterManagerThrottlingStats ());
95
97
throttler .registerClusterManagerTask ("put-mapping" , true );
96
98
97
- // set some limit for update snapshot tasks
99
+ // set some limit for put-mapping tasks
98
100
int newLimit = randomIntBetween (1 , 10 );
99
101
100
102
Settings newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.put-mapping.value" , newLimit ).build ();
101
- assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (newSettings ));
103
+ assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (THRESHOLD_SETTINGS . get ( newSettings ) ));
102
104
103
105
// validate for empty setting, it shouldn't throw exception
104
106
Settings emptySettings = Settings .builder ().build ();
@@ -124,11 +126,11 @@ public void testValidateSettingsForTaskWithoutRetryOnDataNode() {
124
126
}, new ClusterManagerThrottlingStats ());
125
127
throttler .registerClusterManagerTask ("put-mapping" , false );
126
128
127
- // set some limit for update snapshot tasks
129
+ // set some limit for put-mapping tasks
128
130
int newLimit = randomIntBetween (1 , 10 );
129
131
130
132
Settings newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.put-mapping.value" , newLimit ).build ();
131
- assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (newSettings ));
133
+ assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (THRESHOLD_SETTINGS . get ( newSettings ) ));
132
134
}
133
135
134
136
public void testUpdateSettingsForNullValue () {
@@ -154,7 +156,7 @@ public void testUpdateSettingsForNullValue() {
154
156
// set limit to null
155
157
Settings nullSettings = Settings .builder ().build ();
156
158
clusterSettings .applySettings (nullSettings );
157
- assertNull ( throttler .getThrottlingLimit ("put-mapping" ));
159
+ assertEquals ( 50 , throttler .getThrottlingLimit ("put-mapping" ). intValue ( ));
158
160
}
159
161
160
162
public void testSettingsOnBootstrap () {
@@ -222,10 +224,10 @@ public void testValidateSettingsForUnknownTask() {
222
224
return clusterService .getClusterManagerService ().getMinNodeVersion ();
223
225
}, new ClusterManagerThrottlingStats ());
224
226
225
- // set some limit for update snapshot tasks
227
+ // set some limit for random tasks
226
228
int newLimit = randomIntBetween (1 , 10 );
227
229
Settings newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.random-task.value" , newLimit ).build ();
228
- assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (newSettings ));
230
+ assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (THRESHOLD_SETTINGS . get ( newSettings ) ));
229
231
}
230
232
231
233
public void testUpdateThrottlingLimitForBasicSanity () {
@@ -242,17 +244,17 @@ public void testUpdateThrottlingLimitForBasicSanity() {
242
244
}, new ClusterManagerThrottlingStats ());
243
245
throttler .registerClusterManagerTask ("put-mapping" , true );
244
246
245
- // set some limit for update snapshot tasks
247
+ // set some limit for put-mapping tasks
246
248
long newLimit = randomLongBetween (1 , 10 );
247
249
248
250
Settings newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.put-mapping.value" , newLimit ).build ();
249
251
clusterSettings .applySettings (newSettings );
250
252
assertEquals (newLimit , throttler .getThrottlingLimit ("put-mapping" ).intValue ());
251
253
252
- // set update snapshot task limit to default
253
- newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.put-mapping.value" , - 1 ).build ();
254
+ // set put-mapping task limit to 20
255
+ newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.put-mapping.value" , 20 ).build ();
254
256
clusterSettings .applySettings (newSettings );
255
- assertNull ( throttler .getThrottlingLimit ("put-mapping" ));
257
+ assertEquals ( 20 , throttler .getThrottlingLimit ("put-mapping" ). intValue ( ));
256
258
}
257
259
258
260
public void testValidateSettingForLimit () {
@@ -269,8 +271,8 @@ public void testValidateSettingForLimit() {
269
271
}, new ClusterManagerThrottlingStats ());
270
272
throttler .registerClusterManagerTask ("put-mapping" , true );
271
273
272
- Settings newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.put-mapping.values " , -5 ).build ();
273
- assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (newSettings ));
274
+ Settings newSettings = Settings .builder ().put ("cluster_manager.throttling.thresholds.put-mapping.value " , -5 ).build ();
275
+ assertThrows (IllegalArgumentException .class , () -> throttler .validateSetting (THRESHOLD_SETTINGS . get ( newSettings ) ));
274
276
}
275
277
276
278
public void testUpdateLimit () {
@@ -348,7 +350,7 @@ public void testThrottlingForInitialStaticSettingAndVersionCheck() {
348
350
}, throttlingStats );
349
351
ClusterManagerTaskThrottler .ThrottlingKey throttlingKey = throttler .registerClusterManagerTask ("put-mapping" , true );
350
352
351
- // verifying adding more tasks then threshold passes
353
+ // verifying adding more tasks than threshold passes
352
354
throttler .onBeginSubmit (getMockUpdateTaskList ("put-mapping" , throttlingKey , put_mapping_threshold_value + 5 ));
353
355
assertEquals (0L , throttlingStats .getThrottlingCount ("put-mapping" ));
354
356
0 commit comments