use of org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction in project OpenSearch by opensearch-project.
the class CoordinationMetadataTests method testVotingTombstoneSerializationEqualsHashCode.
public void testVotingTombstoneSerializationEqualsHashCode() {
VotingConfigExclusion tombstone = new VotingConfigExclusion(randomAlphaOfLength(10), randomAlphaOfLength(10));
// Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
EqualsHashCodeTestUtils.checkEqualsAndHashCode(tombstone, (CopyFunction<VotingConfigExclusion>) orig -> OpenSearchTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfigExclusion::new), orig -> randomlyChangeVotingTombstone(orig));
}
use of org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction in project OpenSearch by opensearch-project.
the class CoordinationMetadataTests method testCoordinationMetadataSerializationEqualsHashCode.
public void testCoordinationMetadataSerializationEqualsHashCode() {
CoordinationMetadata initialMetadata = new CoordinationMetadata(randomNonNegativeLong(), randomVotingConfig(), randomVotingConfig(), randomVotingTombstones());
// Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
EqualsHashCodeTestUtils.checkEqualsAndHashCode(initialMetadata, (CopyFunction<CoordinationMetadata>) orig -> OpenSearchTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), CoordinationMetadata::new), meta -> {
CoordinationMetadata.Builder builder = CoordinationMetadata.builder(meta);
switch(randomInt(3)) {
case 0:
builder.term(randomValueOtherThan(meta.term(), OpenSearchTestCase::randomNonNegativeLong));
break;
case 1:
builder.lastCommittedConfiguration(randomlyChangeVotingConfiguration(meta.getLastCommittedConfiguration()));
break;
case 2:
builder.lastAcceptedConfiguration(randomlyChangeVotingConfiguration(meta.getLastAcceptedConfiguration()));
break;
case 3:
if (meta.getVotingConfigExclusions().isEmpty() == false && randomBoolean()) {
builder.clearVotingConfigExclusions();
} else {
randomVotingTombstones().forEach(dn -> builder.addVotingConfigExclusion(dn));
}
break;
}
return builder.build();
});
}
use of org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction in project OpenSearch by opensearch-project.
the class PeerFinderMessagesTests method testPeersResponseEqualsHashCodeSerialization.
public void testPeersResponseEqualsHashCodeSerialization() {
final long initialTerm = randomNonNegativeLong();
final PeersResponse initialPeersResponse;
if (randomBoolean()) {
initialPeersResponse = new PeersResponse(Optional.of(createNode(randomAlphaOfLength(10))), emptyList(), initialTerm);
} else {
initialPeersResponse = new PeersResponse(Optional.empty(), Arrays.stream(generateRandomStringArray(10, 10, false, false)).map(this::createNode).collect(Collectors.toList()), initialTerm);
}
// Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
EqualsHashCodeTestUtils.checkEqualsAndHashCode(initialPeersResponse, (CopyFunction<PeersResponse>) publishResponse -> copyWriteable(publishResponse, writableRegistry(), PeersResponse::new), in -> {
final long term = in.getTerm();
if (randomBoolean()) {
return new PeersResponse(in.getMasterNode(), in.getKnownPeers(), randomValueOtherThan(term, OpenSearchTestCase::randomNonNegativeLong));
} else {
if (in.getMasterNode().isPresent()) {
if (randomBoolean()) {
return new PeersResponse(Optional.of(createNode(randomAlphaOfLength(10))), in.getKnownPeers(), term);
} else {
return new PeersResponse(Optional.empty(), singletonList(createNode(randomAlphaOfLength(10))), term);
}
} else {
if (randomBoolean()) {
return new PeersResponse(Optional.of(createNode(randomAlphaOfLength(10))), emptyList(), term);
} else {
return new PeersResponse(in.getMasterNode(), modifyDiscoveryNodesList(in.getKnownPeers(), false), term);
}
}
}
});
}
use of org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction in project OpenSearch by opensearch-project.
the class LeaderCheckerTests method testLeaderCheckRequestEqualsHashcodeSerialization.
public void testLeaderCheckRequestEqualsHashcodeSerialization() {
LeaderCheckRequest request = new LeaderCheckRequest(new DiscoveryNode(randomAlphaOfLength(10), buildNewFakeTransportAddress(), Version.CURRENT));
// noinspection RedundantCast since it is needed for some IDEs (specifically Eclipse 4.8.0) to infer the right type
EqualsHashCodeTestUtils.checkEqualsAndHashCode(request, (CopyFunction<LeaderCheckRequest>) rq -> copyWriteable(rq, writableRegistry(), LeaderCheckRequest::new), rq -> new LeaderCheckRequest(new DiscoveryNode(randomAlphaOfLength(10), buildNewFakeTransportAddress(), Version.CURRENT)));
}
use of org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction in project OpenSearch by opensearch-project.
the class CoordinationMetadataTests method testVotingConfigurationSerializationEqualsHashCode.
public void testVotingConfigurationSerializationEqualsHashCode() {
VotingConfiguration initialConfig = randomVotingConfig();
// Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
EqualsHashCodeTestUtils.checkEqualsAndHashCode(initialConfig, (CopyFunction<VotingConfiguration>) orig -> OpenSearchTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfiguration::new), cfg -> randomlyChangeVotingConfiguration(cfg));
}
Aggregations