Search in sources :

Example 21 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testAckListenerReceivesAcksFromAllNodes.

public void testAckListenerReceivesAcksFromAllNodes() {
    try (Cluster cluster = new Cluster(randomIntBetween(3, 5))) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader = cluster.getAnyLeader();
        AckCollector ackCollector = leader.submitValue(randomLong());
        cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
        for (final ClusterNode clusterNode : cluster.clusterNodes) {
            assertTrue("expected ack from " + clusterNode, ackCollector.hasAckedSuccessfully(clusterNode));
        }
        assertThat("leader should be last to ack", ackCollector.getSuccessfulAckIndex(leader), equalTo(cluster.clusterNodes.size() - 1));
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)

Example 22 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testLeaderDisconnectionWithoutDisconnectEventDetectedQuickly.

public void testLeaderDisconnectionWithoutDisconnectEventDetectedQuickly() {
    try (Cluster cluster = new Cluster(randomIntBetween(3, 5))) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode originalLeader = cluster.getAnyLeader();
        logger.info("--> disconnecting leader {}", originalLeader);
        originalLeader.disconnect();
        cluster.stabilise(Math.max(// Each follower may have just sent a leader check, which receives no response
        defaultMillis(LEADER_CHECK_TIMEOUT_SETTING) + // then wait for the follower to check the leader
        defaultMillis(LEADER_CHECK_INTERVAL_SETTING) + // then wait for the exception response
        DEFAULT_DELAY_VARIABILITY + // then wait for a new election
        DEFAULT_ELECTION_DELAY, // ALSO the leader may have just sent a follower check, which receives no response
        defaultMillis(FOLLOWER_CHECK_TIMEOUT_SETTING) + // wait for the leader to check its followers
        defaultMillis(FOLLOWER_CHECK_INTERVAL_SETTING) + // then wait for the exception response
        DEFAULT_DELAY_VARIABILITY) + // wait for the removal to be committed
        DEFAULT_CLUSTER_STATE_UPDATE_DELAY + // then wait for the followup reconfiguration
        DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
        assertThat(cluster.getAnyLeader().getId(), not(equalTo(originalLeader.getId())));
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)

Example 23 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testClusterRecoversAfterExceptionDuringSerialization.

public void testClusterRecoversAfterExceptionDuringSerialization() {
    try (Cluster cluster = new Cluster(randomIntBetween(1, 5))) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader1 = cluster.getAnyLeader();
        logger.info("--> submitting broken task to [{}]", leader1);
        final AtomicBoolean failed = new AtomicBoolean();
        leader1.submitUpdateTask("broken-task", cs -> ClusterState.builder(cs).putCustom("broken", new BrokenCustom()).build(), (source, e) -> {
            assertThat(e.getCause(), instanceOf(ElasticsearchException.class));
            assertThat(e.getCause().getMessage(), equalTo(BrokenCustom.EXCEPTION_MESSAGE));
            failed.set(true);
        });
        cluster.runFor(DEFAULT_DELAY_VARIABILITY + 1, "processing broken task");
        assertTrue(failed.get());
        cluster.stabilise();
        final ClusterNode leader2 = cluster.getAnyLeader();
        long finalValue = randomLong();
        logger.info("--> submitting value [{}] to [{}]", finalValue, leader2);
        leader2.submitValue(finalValue);
        cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
        for (final ClusterNode clusterNode : cluster.clusterNodes) {
            final String nodeId = clusterNode.getId();
            final ClusterState appliedState = clusterNode.getLastAppliedClusterState();
            assertThat(nodeId + " has the applied value", value(appliedState), is(finalValue));
        }
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterState(org.elasticsearch.cluster.ClusterState) ElasticsearchException(org.elasticsearch.ElasticsearchException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 24 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testSingleNodeDiscoveryWithoutQuorum.

public void testSingleNodeDiscoveryWithoutQuorum() {
    try (Cluster cluster = new Cluster(3)) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode clusterNode = cluster.getAnyNode();
        logger.debug("rebooting [{}]", clusterNode.getId());
        clusterNode.close();
        cluster.clusterNodes.forEach(cn -> cluster.deterministicTaskQueue.scheduleNow(cn.onNode(new Runnable() {

            @Override
            public void run() {
                cn.transportService.disconnectFromNode(clusterNode.getLocalNode());
            }

            @Override
            public String toString() {
                return "disconnect from " + clusterNode.getLocalNode() + " after shutdown";
            }
        })));
        IllegalStateException ise = expectThrows(IllegalStateException.class, () -> cluster.clusterNodes.replaceAll(cn -> cn == clusterNode ? cn.restartedNode(Function.identity(), Function.identity(), Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE).build()) : cn));
        assertThat(ise.getMessage(), allOf(containsString("cannot start with [discovery.type] set to [single-node] when local node"), containsString("does not have quorum in voting configuration")));
        // to avoid closing it twice
        cluster.clusterNodes.remove(clusterNode);
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) ElasticsearchException(org.elasticsearch.ElasticsearchException) LEADER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING) Arrays(java.util.Arrays) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) Matchers.not(org.hamcrest.Matchers.not) Level(org.apache.logging.log4j.Level) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) LogEvent(org.apache.logging.log4j.core.LogEvent) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) CANDIDATE(org.elasticsearch.cluster.coordination.Coordinator.Mode.CANDIDATE) DISCOVERY_FIND_PEERS_INTERVAL_SETTING(org.elasticsearch.discovery.PeerFinder.DISCOVERY_FIND_PEERS_INTERVAL_SETTING) Map(java.util.Map) Mode(org.elasticsearch.cluster.coordination.Coordinator.Mode) MockLogAppender(org.elasticsearch.test.MockLogAppender) FOLLOWER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING) LEADER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_INTERVAL_SETTING) Set(java.util.Set) Collectors(java.util.stream.Collectors) Matchers.startsWith(org.hamcrest.Matchers.startsWith) AbstractDiffable(org.elasticsearch.cluster.AbstractDiffable) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) LEADER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_RETRY_COUNT_SETTING) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) NO_MASTER_BLOCK_ALL(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ALL) ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) PUBLISH_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.Coordinator.PUBLISH_TIMEOUT_SETTING) Matchers.containsString(org.hamcrest.Matchers.containsString) NO_MASTER_BLOCK_WRITES(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_WRITES) DEFAULT_DELAY_VARIABILITY(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.DEFAULT_DELAY_VARIABILITY) AwaitsFix(org.apache.lucene.util.LuceneTestCase.AwaitsFix) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) HashSet(java.util.HashSet) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) FOLLOWER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING) DiscoveryModule(org.elasticsearch.discovery.DiscoveryModule) Node(org.elasticsearch.node.Node) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Regex(org.elasticsearch.common.regex.Regex) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Loggers(org.elasticsearch.common.logging.Loggers) CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION(org.elasticsearch.cluster.coordination.Reconfigurator.CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION) IOException(java.io.IOException) ELECTION_INITIAL_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.ElectionSchedulerFactory.ELECTION_INITIAL_TIMEOUT_SETTING) FOLLOWER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING) Matchers.hasItem(org.hamcrest.Matchers.hasItem) GatewayService(org.elasticsearch.gateway.GatewayService) NO_MASTER_BLOCK_SETTING(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_SETTING) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Builder(org.elasticsearch.common.settings.Settings.Builder) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 25 with ClusterNode

use of org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode in project crate by crate.

the class CoordinatorTests method testDiffBasedPublishing.

public void testDiffBasedPublishing() {
    try (Cluster cluster = new Cluster(randomIntBetween(1, 5))) {
        cluster.runRandomly();
        cluster.stabilise();
        final ClusterNode leader = cluster.getAnyLeader();
        final long finalValue = randomLong();
        final Map<ClusterNode, PublishClusterStateStats> prePublishStats = cluster.clusterNodes.stream().collect(Collectors.toMap(Function.identity(), cn -> cn.coordinator.stats().getPublishStats()));
        logger.info("--> submitting value [{}] to [{}]", finalValue, leader);
        leader.submitValue(finalValue);
        cluster.stabilise(DEFAULT_CLUSTER_STATE_UPDATE_DELAY);
        final Map<ClusterNode, PublishClusterStateStats> postPublishStats = cluster.clusterNodes.stream().collect(Collectors.toMap(Function.identity(), cn -> cn.coordinator.stats().getPublishStats()));
        for (ClusterNode cn : cluster.clusterNodes) {
            assertThat(value(cn.getLastAppliedClusterState()), is(finalValue));
            assertEquals(cn.toString(), prePublishStats.get(cn).getFullClusterStateReceivedCount(), postPublishStats.get(cn).getFullClusterStateReceivedCount());
            assertEquals(cn.toString(), prePublishStats.get(cn).getCompatibleClusterStateDiffReceivedCount() + 1, postPublishStats.get(cn).getCompatibleClusterStateDiffReceivedCount());
            assertEquals(cn.toString(), prePublishStats.get(cn).getIncompatibleClusterStateDiffReceivedCount(), postPublishStats.get(cn).getIncompatibleClusterStateDiffReceivedCount());
        }
    }
}
Also used : ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) ElasticsearchException(org.elasticsearch.ElasticsearchException) LEADER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_TIMEOUT_SETTING) Arrays(java.util.Arrays) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) Matchers.not(org.hamcrest.Matchers.not) Level(org.apache.logging.log4j.Level) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) LogEvent(org.apache.logging.log4j.core.LogEvent) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) CANDIDATE(org.elasticsearch.cluster.coordination.Coordinator.Mode.CANDIDATE) DISCOVERY_FIND_PEERS_INTERVAL_SETTING(org.elasticsearch.discovery.PeerFinder.DISCOVERY_FIND_PEERS_INTERVAL_SETTING) Map(java.util.Map) Mode(org.elasticsearch.cluster.coordination.Coordinator.Mode) MockLogAppender(org.elasticsearch.test.MockLogAppender) FOLLOWER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_RETRY_COUNT_SETTING) LEADER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_INTERVAL_SETTING) Set(java.util.Set) Collectors(java.util.stream.Collectors) Matchers.startsWith(org.hamcrest.Matchers.startsWith) AbstractDiffable(org.elasticsearch.cluster.AbstractDiffable) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) LEADER_CHECK_RETRY_COUNT_SETTING(org.elasticsearch.cluster.coordination.LeaderChecker.LEADER_CHECK_RETRY_COUNT_SETTING) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) NO_MASTER_BLOCK_ALL(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_ALL) ClusterNode(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode) PUBLISH_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.Coordinator.PUBLISH_TIMEOUT_SETTING) Matchers.containsString(org.hamcrest.Matchers.containsString) NO_MASTER_BLOCK_WRITES(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_WRITES) DEFAULT_DELAY_VARIABILITY(org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.DEFAULT_DELAY_VARIABILITY) AwaitsFix(org.apache.lucene.util.LuceneTestCase.AwaitsFix) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) HashSet(java.util.HashSet) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) FOLLOWER_CHECK_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_TIMEOUT_SETTING) DiscoveryModule(org.elasticsearch.discovery.DiscoveryModule) Node(org.elasticsearch.node.Node) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Regex(org.elasticsearch.common.regex.Regex) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Loggers(org.elasticsearch.common.logging.Loggers) CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION(org.elasticsearch.cluster.coordination.Reconfigurator.CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION) IOException(java.io.IOException) ELECTION_INITIAL_TIMEOUT_SETTING(org.elasticsearch.cluster.coordination.ElectionSchedulerFactory.ELECTION_INITIAL_TIMEOUT_SETTING) FOLLOWER_CHECK_INTERVAL_SETTING(org.elasticsearch.cluster.coordination.FollowersChecker.FOLLOWER_CHECK_INTERVAL_SETTING) Matchers.hasItem(org.hamcrest.Matchers.hasItem) GatewayService(org.elasticsearch.gateway.GatewayService) NO_MASTER_BLOCK_SETTING(org.elasticsearch.cluster.coordination.NoMasterBlockService.NO_MASTER_BLOCK_SETTING) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Builder(org.elasticsearch.common.settings.Settings.Builder)

Aggregations

ClusterNode (org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode)35 Matchers.containsString (org.hamcrest.Matchers.containsString)8 VotingConfiguration (org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)5 MockLogAppender (org.elasticsearch.test.MockLogAppender)5 HashSet (java.util.HashSet)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 List (java.util.List)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Logger (org.apache.logging.log4j.Logger)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Level (org.apache.logging.log4j.Level)2 LogManager (org.apache.logging.log4j.LogManager)2