Skip to content

Commit ea022ff

Browse files
surround all write load enable settings with clearing afterwards in a finally block
1 parent 9948453 commit ea022ff

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

server/src/internalClusterTest/java/org/elasticsearch/index/shard/IndexShardIT.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import org.elasticsearch.test.InternalSettingsPlugin;
8181
import org.elasticsearch.threadpool.ThreadPool;
8282
import org.elasticsearch.xcontent.XContentType;
83+
import org.junit.After;
8384
import org.junit.Assert;
8485

8586
import java.io.IOException;
@@ -305,25 +306,26 @@ public void testHeapUsageEstimateIsPresent() {
305306
}
306307

307308
public void testNodeWriteLoadsArePresent() {
308-
// Disable write load decider to begin with
309-
setWriteLoadDeciderEnablement(WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED);
310-
311-
InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
312-
ClusterInfoServiceUtils.refresh(clusterInfoService);
313-
Map<String, NodeUsageStatsForThreadPools> nodeThreadPoolStats = clusterInfoService.getClusterInfo()
314-
.getNodeUsageStatsForThreadPools();
315-
assertNotNull(nodeThreadPoolStats);
316-
/** Not collecting stats yet because allocation write load stats collection is disabled by default.
317-
* see {@link WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING} */
318-
assertTrue(nodeThreadPoolStats.isEmpty());
319-
320-
// Enable collection for node write loads.
321-
setWriteLoadDeciderEnablement(
322-
randomBoolean()
323-
? WriteLoadConstraintSettings.WriteLoadDeciderStatus.ENABLED
324-
: WriteLoadConstraintSettings.WriteLoadDeciderStatus.LOW_THRESHOLD_ONLY
325-
);
326309
try {
310+
// Disable write load decider to begin with
311+
setWriteLoadDeciderEnablement(WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED);
312+
313+
InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
314+
ClusterInfoServiceUtils.refresh(clusterInfoService);
315+
Map<String, NodeUsageStatsForThreadPools> nodeThreadPoolStats = clusterInfoService.getClusterInfo()
316+
.getNodeUsageStatsForThreadPools();
317+
assertNotNull(nodeThreadPoolStats);
318+
/** Not collecting stats yet because allocation write load stats collection is disabled by default.
319+
* see {@link WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING} */
320+
assertTrue(nodeThreadPoolStats.isEmpty());
321+
322+
// Enable collection for node write loads.
323+
setWriteLoadDeciderEnablement(
324+
randomBoolean()
325+
? WriteLoadConstraintSettings.WriteLoadDeciderStatus.ENABLED
326+
: WriteLoadConstraintSettings.WriteLoadDeciderStatus.LOW_THRESHOLD_ONLY
327+
);
328+
327329
// Force a ClusterInfo refresh to run collection of the node thread pool usage stats.
328330
ClusterInfoServiceUtils.refresh(clusterInfoService);
329331
nodeThreadPoolStats = clusterInfoService.getClusterInfo().getNodeUsageStatsForThreadPools();
@@ -361,10 +363,10 @@ public void testShardWriteLoadsArePresent() {
361363

362364
final InternalClusterInfoService clusterInfoService = (InternalClusterInfoService) getInstanceFromNode(ClusterInfoService.class);
363365

364-
// Explicitly disable write load decider
365-
setWriteLoadDeciderEnablement(WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED);
366-
367366
try {
367+
// Explicitly disable write load decider
368+
setWriteLoadDeciderEnablement(WriteLoadConstraintSettings.WriteLoadDeciderStatus.DISABLED);
369+
368370
// Stats should not be collected when the decider is disabled
369371
{
370372
ClusterInfoServiceUtils.refresh(clusterInfoService);

0 commit comments

Comments
 (0)