Skip to content

Commit

Permalink
Fix NodeMetadataTests#testEqualsHashcodeSerialization (elastic#83170)
Browse files Browse the repository at this point in the history
The mutation function would rarely fail to mutate the input object. This
commit fixes that.

Relates elastic#82689
  • Loading branch information
DaveCTurner authored Jan 27, 2022
1 parent 514bec1 commit 847dd43
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,22 @@ public void testEqualsHashcodeSerialization() {
assertThat(nodeMetadataLongTuple.v2(), equalTo(generation));
return nodeMetadataLongTuple.v1();
},
nodeMetadata -> {
switch (randomInt(3)) {
case 0:
return new NodeMetadata(
randomAlphaOfLength(21 - nodeMetadata.nodeId().length()),
nodeMetadata.nodeVersion(),
Version.CURRENT
);
case 1:
return new NodeMetadata(
nodeMetadata.nodeId(),
randomValueOtherThan(nodeMetadata.nodeVersion(), this::randomVersion),
Version.CURRENT
);
default:
return new NodeMetadata(
nodeMetadata.nodeId(),
nodeMetadata.nodeVersion(),
randomValueOtherThan(Version.CURRENT, this::randomVersion)
);
}
nodeMetadata -> switch (randomInt(3)) {
case 0 -> new NodeMetadata(
randomAlphaOfLength(21 - nodeMetadata.nodeId().length()),
nodeMetadata.nodeVersion(),
nodeMetadata.oldestIndexVersion()
);
case 1 -> new NodeMetadata(
nodeMetadata.nodeId(),
randomValueOtherThan(nodeMetadata.nodeVersion(), this::randomVersion),
nodeMetadata.oldestIndexVersion()
);
default -> new NodeMetadata(
nodeMetadata.nodeId(),
nodeMetadata.nodeVersion(),
randomValueOtherThan(nodeMetadata.oldestIndexVersion(), this::randomVersion)
);
}
);
}
Expand Down

0 comments on commit 847dd43

Please sign in to comment.