Skip to content

Commit 7f8b59b

Browse files
Fix NullPointerExceptions in TransportClusterStateActionDisruptionIT
Replaces the use of InternalTestCluster.getMasterName() with a ClusterServiceUtils.addTemporaryStateListener() call that waits for a new master node other than the previous master node. InternalTestCluster.getMasterName() is not safe to use in unstable clusters, per PR 127213. Closes: #127466 #127443 #127424 #127423 #127422
1 parent 83300ea commit 7f8b59b

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

muted-tests.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,9 @@ tests:
432432
- class: org.elasticsearch.xpack.esql.heap_attack.HeapAttackIT
433433
method: testLookupExplosionNoFetch
434434
issue: https://github.com/elastic/elasticsearch/issues/127365
435-
- class: org.elasticsearch.action.admin.cluster.state.TransportClusterStateActionDisruptionIT
436-
method: testNonLocalRequestAlwaysFindsMasterAndWaitsForMetadata
437-
issue: https://github.com/elastic/elasticsearch/issues/127422
438435
- class: org.elasticsearch.xpack.esql.qa.single_node.PushQueriesIT
439436
method: testPushCaseInsensitiveEqualityOnDefaults
440437
issue: https://github.com/elastic/elasticsearch/issues/127431
441-
- class: org.elasticsearch.action.admin.cluster.state.TransportClusterStateActionDisruptionIT
442-
method: testLocalRequestAlwaysSucceeds
443-
issue: https://github.com/elastic/elasticsearch/issues/127423
444-
- class: org.elasticsearch.action.admin.cluster.state.TransportClusterStateActionDisruptionIT
445-
method: testLocalRequestWaitsForMetadata
446-
issue: https://github.com/elastic/elasticsearch/issues/127466
447438

448439
# Examples:
449440
#

server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateActionDisruptionIT.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@
2121
import org.elasticsearch.discovery.MasterNotDiscoveredException;
2222
import org.elasticsearch.gateway.GatewayService;
2323
import org.elasticsearch.plugins.Plugin;
24+
import org.elasticsearch.test.ClusterServiceUtils;
2425
import org.elasticsearch.test.ESIntegTestCase;
2526
import org.elasticsearch.test.transport.MockTransportService;
2627
import org.elasticsearch.transport.TransportService;
2728

2829
import java.util.Collection;
2930
import java.util.Collections;
3031
import java.util.List;
32+
import java.util.Optional;
3133
import java.util.concurrent.atomic.AtomicBoolean;
3234
import java.util.stream.Collectors;
3335
import java.util.stream.StreamSupport;
3436

3537
import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING;
3638
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
37-
import static org.hamcrest.Matchers.equalTo;
3839
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3940
import static org.hamcrest.Matchers.hasSize;
4041
import static org.hamcrest.Matchers.instanceOf;
41-
import static org.hamcrest.Matchers.not;
4242

4343
@ESIntegTestCase.ClusterScope(numDataNodes = 0, scope = ESIntegTestCase.Scope.TEST)
4444
public class TransportClusterStateActionDisruptionIT extends ESIntegTestCase {
@@ -212,11 +212,13 @@ public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception
212212
}
213213
}
214214

215-
assertBusy(() -> {
216-
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
217-
final String claimedMasterName = internalCluster().getMasterName(nonMasterNode);
218-
assertThat(claimedMasterName, not(equalTo(masterName)));
219-
});
215+
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
216+
var newMasterNodeListener = ClusterServiceUtils.addTemporaryStateListener(
217+
internalCluster().clusterService(nonMasterNode),
218+
state -> Optional.ofNullable(state.nodes().getMasterNode()).map(m -> m.getName().equals(masterName) == false).orElse(false),
219+
TEST_REQUEST_TIMEOUT
220+
);
221+
safeAwait(newMasterNodeListener, TEST_REQUEST_TIMEOUT);
220222

221223
shutdown.set(true);
222224
assertingThread.join();

0 commit comments

Comments
 (0)