Skip to content

Commit fb61b18

Browse files
committed
Fix NPE in HealthApiFeatureSetUsageTests testEqualsAndHashcode
1 parent 3ee3331 commit fb61b18

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,6 @@ tests:
579579
- class: org.elasticsearch.xpack.remotecluster.CrossClusterEsqlRCS2UnavailableRemotesIT
580580
method: testEsqlRcs2UnavailableRemoteScenarios
581581
issue: https://github.com/elastic/elasticsearch/issues/136493
582-
- class: org.elasticsearch.xpack.core.HealthApiFeatureSetUsageTests
583-
method: testEqualsAndHashcode
584-
issue: https://github.com/elastic/elasticsearch/issues/136648
585582
- class: org.elasticsearch.xpack.downsample.ILMDownsampleDisruptionIT
586583
method: testILMDownsampleRollingRestart
587584
issue: https://github.com/elastic/elasticsearch/issues/136585

test/framework/src/main/java/org/elasticsearch/test/AbstractWireTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public abstract class AbstractWireTestCase<T> extends ESTestCase {
5454
* Tests that the equals and hashcode methods are consistent and copied
5555
* versions of the instance are equal.
5656
*/
57-
public final void testEqualsAndHashcode() {
57+
public void testEqualsAndHashcode() {
5858
for (int runs = 0; runs < NUMBER_OF_TEST_RUNS; runs++) {
5959
T testInstance = createTestInstance();
6060
try {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/HealthApiFeatureSetUsageTests.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import static org.hamcrest.Matchers.equalTo;
2828
import static org.hamcrest.Matchers.notNullValue;
2929

30+
31+
3032
public class HealthApiFeatureSetUsageTests extends AbstractWireSerializingTestCase<HealthApiFeatureSetUsage> {
3133

3234
@Override
@@ -37,9 +39,9 @@ protected HealthApiFeatureSetUsage createTestInstance() {
3739
@Override
3840
protected HealthApiFeatureSetUsage mutateInstance(HealthApiFeatureSetUsage instance) {
3941
Map<String, Object> originalStats = instance.stats();
40-
Counters newStats = randomCounters();
42+
Counters newStats = randomCounters(false);
4143
while (originalStats.equals(newStats.toMutableNestedMap())) {
42-
newStats = randomCounters();
44+
newStats = randomCounters(false);
4345
}
4446
return new HealthApiFeatureSetUsage(true, true, newStats);
4547
}
@@ -50,7 +52,11 @@ protected Writeable.Reader<HealthApiFeatureSetUsage> instanceReader() {
5052
}
5153

5254
private Counters randomCounters() {
53-
if (rarely()) {
55+
return randomCounters(true);
56+
}
57+
58+
private Counters randomCounters(boolean allowNull) {
59+
if (allowNull && rarely()) {
5460
return null;
5561
}
5662
Counters counters = new Counters();

0 commit comments

Comments
 (0)