Skip to content

Commit 8bc49e2

Browse files
committed
Test fixes
1 parent b520a39 commit 8bc49e2

File tree

19 files changed

+91
-23
lines changed

19 files changed

+91
-23
lines changed

server/src/test/java/org/elasticsearch/action/admin/indices/shards/TransportIndicesShardStoresActionTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
import org.elasticsearch.cluster.node.DiscoveryNodes;
2525
import org.elasticsearch.cluster.routing.IndexRoutingTable;
2626
import org.elasticsearch.cluster.routing.RoutingTable;
27+
import org.elasticsearch.cluster.service.ClusterApplierService;
2728
import org.elasticsearch.cluster.service.ClusterService;
2829
import org.elasticsearch.common.settings.ClusterSettings;
2930
import org.elasticsearch.common.settings.Settings;
3031
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
32+
import org.elasticsearch.core.TimeValue;
3133
import org.elasticsearch.gateway.TransportNodesListGatewayStartedShards;
3234
import org.elasticsearch.index.IndexVersion;
3335
import org.elasticsearch.index.shard.ShardId;
@@ -192,7 +194,11 @@ private abstract static class TestHarness implements Closeable {
192194

193195
final var threadPool = deterministicTaskQueue.getThreadPool();
194196

195-
final var settings = Settings.EMPTY;
197+
final var settings = Settings.builder()
198+
// disable thread watchdog to avoid infinitely repeating task
199+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO)
200+
.build();
201+
196202
final var clusterSettings = ClusterSettings.createBuiltInClusterSettings(settings);
197203

198204
final var transportService = new TransportService(

server/src/test/java/org/elasticsearch/cluster/InternalClusterInfoServiceSchedulingTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.common.settings.Settings;
3434
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
3535
import org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor;
36+
import org.elasticsearch.core.TimeValue;
3637
import org.elasticsearch.node.Node;
3738
import org.elasticsearch.test.ClusterServiceUtils;
3839
import org.elasticsearch.test.ESTestCase;
@@ -63,6 +64,7 @@ public void testScheduling() {
6364
final Settings.Builder settingsBuilder = Settings.builder()
6465
.put(Node.NODE_NAME_SETTING.getKey(), discoveryNode.getName())
6566
.put(InternalClusterInfoService.CLUSTER_ROUTING_ALLOCATION_ESTIMATED_HEAP_THRESHOLD_DECIDER_ENABLED.getKey(), true)
67+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO)
6668
.put(
6769
WriteLoadConstraintSettings.WRITE_LOAD_DECIDER_ENABLED_SETTING.getKey(),
6870
randomBoolean()

server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ public void testBalanceQuality() throws IOException {
216216
final var deterministicTaskQueue = new DeterministicTaskQueue();
217217
final var threadPool = deterministicTaskQueue.getThreadPool();
218218

219-
final var settings = Settings.EMPTY;
219+
final var settings = Settings.builder()
220+
// disable thread watchdog to avoid infinitely repeating task
221+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO)
222+
.build();
220223
final var clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
221224

222225
final var masterService = new MasterService(

server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ public void testAllocate(AllocateUnassignedHandler allocateUnassigned, Consumer<
138138
.blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK)
139139
.build();
140140

141-
var settings = Settings.EMPTY;
141+
final var settings = Settings.builder()
142+
// disable thread watchdog to avoid infinitely repeating task
143+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO)
144+
.build();
145+
142146
var clusterSettings = createBuiltInClusterSettings(settings);
143147
var clusterService = new ClusterService(
144148
settings,

server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ public void testRecoverStateUpdateTask() throws Exception {
153153
public void testRecoveryWillAbortIfExpectedTermDoesNotMatch() throws Exception {
154154
final long expectedTerm = randomLongBetween(1, 42);
155155
final ClusterState stateWithBlock = buildClusterState(1, randomLongBetween(43, 99));
156-
final GatewayService service = createGatewayService(Settings.builder(), stateWithBlock);
156+
final GatewayService service = createGatewayService(
157+
Settings.builder()
158+
// disable thread watchdog to avoid infinitely repeating task
159+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO),
160+
stateWithBlock
161+
);
157162
final ClusterStateUpdateTask clusterStateUpdateTask = service.new RecoverStateUpdateTask(expectedTerm);
158163

159164
final ClusterState recoveredState = clusterStateUpdateTask.execute(stateWithBlock);
@@ -178,7 +183,12 @@ public void testNoActionWhenNodeIsNotMaster() {
178183
final ClusterChangedEvent clusterChangedEvent = mock(ClusterChangedEvent.class);
179184
when(clusterChangedEvent.state()).thenReturn(initialState);
180185

181-
final GatewayService gatewayService = createGatewayService(Settings.builder(), initialState);
186+
final GatewayService gatewayService = createGatewayService(
187+
Settings.builder()
188+
// disable thread watchdog to avoid infinitely repeating task
189+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO),
190+
initialState
191+
);
182192
gatewayService.clusterChanged(clusterChangedEvent);
183193
assertThat(deterministicTaskQueue.hasAnyTasks(), is(false));
184194
assertThat(gatewayService.currentPendingStateRecovery, nullValue());
@@ -189,7 +199,9 @@ public void testNoActionWhenStateIsAlreadyRecovered() {
189199
Settings.builder()
190200
.put(GatewayService.RECOVER_AFTER_DATA_NODES_SETTING.getKey(), 2)
191201
.put(GatewayService.EXPECTED_DATA_NODES_SETTING.getKey(), 4)
192-
.put(GatewayService.RECOVER_AFTER_TIME_SETTING.getKey(), TimeValue.timeValueMinutes(10)),
202+
.put(GatewayService.RECOVER_AFTER_TIME_SETTING.getKey(), TimeValue.timeValueMinutes(10))
203+
// disable thread watchdog to avoid infinitely repeating task
204+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO),
193205
ClusterState.builder(buildClusterState(2, randomIntBetween(1, 42))).blocks(ClusterBlocks.builder()).build()
194206
);
195207
final GatewayService gatewayService = createGatewayService(clusterService);
@@ -208,7 +220,10 @@ public void testNoActionWhenStateIsAlreadyRecovered() {
208220
}
209221

210222
public void testImmediateRecovery() {
211-
final Settings.Builder settingsBuilder = Settings.builder();
223+
final Settings.Builder settingsBuilder = Settings.builder()
224+
// disable thread watchdog to avoid infinitely repeating task
225+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO);
226+
212227
final int expectedNumberOfDataNodes = randomIntBetween(1, 3);
213228
// The cluster recover immediately because it either has the required expectedDataNodes
214229
// or both expectedDataNodes and recoverAfterTime are not configured
@@ -326,8 +341,10 @@ private Tuple<ClusterService, GatewayService> createServicesTupleForScheduledRec
326341
int expectedNumberOfDataNodes,
327342
boolean hasRecoverAfterTime
328343
) {
329-
final Settings.Builder settingsBuilder = Settings.builder();
330-
settingsBuilder.put(EXPECTED_DATA_NODES_SETTING.getKey(), expectedNumberOfDataNodes);
344+
final Settings.Builder settingsBuilder = Settings.builder()
345+
.put(EXPECTED_DATA_NODES_SETTING.getKey(), expectedNumberOfDataNodes)
346+
// disable thread watchdog to avoid infinitely repeating task
347+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO);
331348
if (hasRecoverAfterTime) {
332349
settingsBuilder.put(RECOVER_AFTER_TIME_SETTING.getKey(), TimeValue.timeValueMinutes(10));
333350
}
@@ -350,7 +367,9 @@ private Tuple<ClusterService, GatewayService> createServicesTupleForScheduledRec
350367
}
351368

352369
public void testScheduledRecoveryWithRecoverAfterNodes() {
353-
final Settings.Builder settingsBuilder = Settings.builder();
370+
final Settings.Builder settingsBuilder = Settings.builder()
371+
// disable thread watchdog to avoid infinitely repeating task
372+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO);
354373
final int expectedNumberOfDataNodes = randomIntBetween(4, 6);
355374
final boolean hasRecoverAfterTime = randomBoolean();
356375
if (hasRecoverAfterTime) {

test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
4343
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
4444
import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider;
45+
import org.elasticsearch.cluster.service.ClusterApplierService;
4546
import org.elasticsearch.common.settings.ClusterSettings;
4647
import org.elasticsearch.common.settings.Settings;
4748
import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue;
4849
import org.elasticsearch.core.Nullable;
4950
import org.elasticsearch.core.Strings;
5051
import org.elasticsearch.core.SuppressForbidden;
52+
import org.elasticsearch.core.TimeValue;
5153
import org.elasticsearch.gateway.GatewayAllocator;
5254
import org.elasticsearch.index.IndexVersion;
5355
import org.elasticsearch.index.IndexVersions;
@@ -172,7 +174,13 @@ private static String pickShardsAllocator(Settings settings) {
172174

173175
private static DesiredBalanceShardsAllocator createDesiredBalanceShardsAllocator(Settings settings) {
174176
var queue = new DeterministicTaskQueue();
175-
var clusterSettings = createBuiltInClusterSettings(settings);
177+
var clusterSettings = createBuiltInClusterSettings(
178+
Settings.builder()
179+
// disable thread watchdog (submits infinitely repeating task to threadpool) by default
180+
.put(ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL.getKey(), TimeValue.ZERO)
181+
.put(settings)
182+
.build()
183+
);
176184
var clusterService = ClusterServiceUtils.createClusterService(queue.getThreadPool(), clusterSettings);
177185
return new DesiredBalanceShardsAllocator(
178186
clusterSettings,

x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/AnomalyJobCRUDIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public void createComponents() throws Exception {
6969
ResultsPersisterService.PERSIST_RESULTS_MAX_RETRIES,
7070
ClusterService.USER_DEFINED_METADATA,
7171
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
72-
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING
72+
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING,
73+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL,
74+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_QUIET_TIME
7375
)
7476
)
7577
);

x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ public void createComponents() throws Exception {
170170
ClusterService.USER_DEFINED_METADATA,
171171
ResultsPersisterService.PERSIST_RESULTS_MAX_RETRIES,
172172
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
173-
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING
173+
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING,
174+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL,
175+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_QUIET_TIME
174176
)
175177
)
176178
);

x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/EstablishedMemUsageIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public void createComponents() {
5959
OperationRouting.USE_ADAPTIVE_REPLICA_SELECTION_SETTING,
6060
ClusterService.USER_DEFINED_METADATA,
6161
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
62-
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING
62+
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING,
63+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL,
64+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_QUIET_TIME
6365
)
6466
)
6567
);

x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobModelSnapshotCRUDIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public void createComponents() throws Exception {
6969
ResultsPersisterService.PERSIST_RESULTS_MAX_RETRIES,
7070
ClusterService.USER_DEFINED_METADATA,
7171
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
72-
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING
72+
ClusterApplierService.CLUSTER_SERVICE_SLOW_TASK_THREAD_DUMP_TIMEOUT_SETTING,
73+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_INTERVAL,
74+
ClusterApplierService.CLUSTER_APPLIER_THREAD_WATCHDOG_QUIET_TIME
7375
)
7476
)
7577
);

0 commit comments

Comments
 (0)