Search in sources :

Example 1 with CopyFunction

use of org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction in project crate by crate.

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 -> ESTestCase.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(), ESTestCase::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();
    });
}
Also used : EqualsHashCodeTestUtils(org.elasticsearch.test.EqualsHashCodeTestUtils) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Set(java.util.Set) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) BytesReference(org.elasticsearch.common.bytes.BytesReference) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) XContentParser(org.elasticsearch.common.xcontent.XContentParser) CopyFunction(org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction) HashSet(java.util.HashSet) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) Collections(java.util.Collections) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry)

Example 2 with CopyFunction

use of org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction in project crate by crate.

the class LeaderCheckerTests method testLeaderCheckRequestEqualsHashcodeSerialization.

public void testLeaderCheckRequestEqualsHashcodeSerialization() {
    LeaderCheckRequest request = new LeaderCheckRequest(new DiscoveryNode(randomAlphaOfLength(10), buildNewFakeTransportAddress(), Version.CURRENT));
    // Note: the explicit cast of the CopyFunction is needed for some IDE (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)));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) LEADER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING) Empty(org.elasticsearch.transport.TransportResponse.Empty) HANDSHAKE_ACTION_NAME(org.elasticsearch.transport.TransportService.HANDSHAKE_ACTION_NAME) TransportRequest(org.elasticsearch.transport.TransportRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Names(org.elasticsearch.threadpool.ThreadPool.Names) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) CopyFunction(org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction) Matchers.matchesRegex(org.hamcrest.Matchers.matchesRegex) LEADER_CHECK_ACTION_NAME(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_ACTION_NAME) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) Settings(org.elasticsearch.common.settings.Settings) AbstractSimpleTransportTestCase(org.elasticsearch.transport.AbstractSimpleTransportTestCase) Matchers.nullValue(org.hamcrest.Matchers.nullValue) LeaderCheckRequest(org.elasticsearch.cluster.coordination.LeaderChecker.LeaderCheckRequest) TransportResponse(org.elasticsearch.transport.TransportResponse) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) EqualsHashCodeTestUtils(org.elasticsearch.test.EqualsHashCodeTestUtils) LEADER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_INTERVAL_SETTING) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) MockTransport(org.elasticsearch.test.transport.MockTransport) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) AtomicLong(java.util.concurrent.atomic.AtomicLong) Version(org.elasticsearch.Version) NODE_NAME_SETTING(org.elasticsearch.node.Node.NODE_NAME_SETTING) LEADER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_RETRY_COUNT_SETTING) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) Matchers.anyOf(org.hamcrest.Matchers.anyOf) TransportException(org.elasticsearch.transport.TransportException) Matchers.endsWith(org.hamcrest.Matchers.endsWith) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) LeaderCheckRequest(org.elasticsearch.cluster.coordination.LeaderChecker.LeaderCheckRequest)

Example 3 with CopyFunction

use of org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction in project crate by crate.

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 -> ESTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfigExclusion::new), orig -> randomlyChangeVotingTombstone(orig));
}
Also used : VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) EqualsHashCodeTestUtils(org.elasticsearch.test.EqualsHashCodeTestUtils) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Set(java.util.Set) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) BytesReference(org.elasticsearch.common.bytes.BytesReference) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) XContentParser(org.elasticsearch.common.xcontent.XContentParser) CopyFunction(org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction) HashSet(java.util.HashSet) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) Collections(java.util.Collections) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry)

Example 4 with CopyFunction

use of org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction in project crate by crate.

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 -> ESTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfiguration::new), cfg -> randomlyChangeVotingConfiguration(cfg));
}
Also used : EqualsHashCodeTestUtils(org.elasticsearch.test.EqualsHashCodeTestUtils) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Set(java.util.Set) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) BytesReference(org.elasticsearch.common.bytes.BytesReference) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) XContentParser(org.elasticsearch.common.xcontent.XContentParser) CopyFunction(org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction) HashSet(java.util.HashSet) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) Collections(java.util.Collections) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)

Aggregations

ESTestCase (org.elasticsearch.test.ESTestCase)4 EqualsHashCodeTestUtils (org.elasticsearch.test.EqualsHashCodeTestUtils)4 CopyFunction (org.elasticsearch.test.EqualsHashCodeTestUtils.CopyFunction)4 Matchers.equalTo (org.hamcrest.Matchers.equalTo)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 VotingConfigExclusion (org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion)3 VotingConfiguration (org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)3 ToXContent (org.elasticsearch.common.xcontent.ToXContent)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 XContentParser (org.elasticsearch.common.xcontent.XContentParser)3 JsonXContent (org.elasticsearch.common.xcontent.json.JsonXContent)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 Version (org.elasticsearch.Version)1