Search in sources :

Example 6 with PeersResponse

use of org.elasticsearch.cluster.coordination.PeersResponse in project crate by crate.

the class PeerFinderTests method testTimesOutAndRetriesConnectionsToBlackholedNodes.

public void testTimesOutAndRetriesConnectionsToBlackholedNodes() {
    final DiscoveryNode otherNode = newDiscoveryNode("node-from-hosts-list");
    final DiscoveryNode nodeToFind = newDiscoveryNode("node-to-find");
    providedAddresses.add(otherNode.getAddress());
    transportAddressConnector.addReachableNode(otherNode);
    transportAddressConnector.addReachableNode(nodeToFind);
    peerFinder.activate(lastAcceptedNodes);
    while (true) {
        deterministicTaskQueue.advanceTime();
        // MockTransportAddressConnector verifies no multiple connection attempts
        runAllRunnableTasks();
        if (capturingTransport.getCapturedRequestsAndClear().length > 0) {
            break;
        }
    }
    final long timeoutAtMillis = deterministicTaskQueue.getCurrentTimeMillis() + PeerFinder.DISCOVERY_REQUEST_PEERS_TIMEOUT_SETTING.get(Settings.EMPTY).millis();
    while (deterministicTaskQueue.getCurrentTimeMillis() < timeoutAtMillis) {
        assertFoundPeers(otherNode);
        deterministicTaskQueue.advanceTime();
        runAllRunnableTasks();
    }
    // need to wait for the connection to timeout, then for another wakeup, before discovering the peer
    final long expectedTime = timeoutAtMillis + PeerFinder.DISCOVERY_FIND_PEERS_INTERVAL_SETTING.get(Settings.EMPTY).millis();
    while (deterministicTaskQueue.getCurrentTimeMillis() < expectedTime) {
        deterministicTaskQueue.advanceTime();
        runAllRunnableTasks();
    }
    respondToRequests(node -> {
        assertThat(node, is(otherNode));
        return new PeersResponse(Optional.empty(), singletonList(nodeToFind), randomNonNegativeLong());
    });
    deterministicTaskQueue.advanceTime();
    runAllRunnableTasks();
    assertFoundPeers(nodeToFind, otherNode);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse)

Example 7 with PeersResponse

use of org.elasticsearch.cluster.coordination.PeersResponse in project crate by crate.

the class PeerFinderTests method testAddsReachablePeersFromResponse.

public void testAddsReachablePeersFromResponse() {
    final DiscoveryNode otherNode = newDiscoveryNode("node-from-hosts-list");
    providedAddresses.add(otherNode.getAddress());
    transportAddressConnector.addReachableNode(otherNode);
    peerFinder.activate(lastAcceptedNodes);
    runAllRunnableTasks();
    assertFoundPeers(otherNode);
    final DiscoveryNode discoveredNode = newDiscoveryNode("discovered-node");
    transportAddressConnector.addReachableNode(discoveredNode);
    respondToRequests(node -> {
        assertThat(node, is(otherNode));
        return new PeersResponse(Optional.empty(), singletonList(discoveredNode), randomNonNegativeLong());
    });
    runAllRunnableTasks();
    assertFoundPeers(otherNode, discoveredNode);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse)

Example 8 with PeersResponse

use of org.elasticsearch.cluster.coordination.PeersResponse in project crate by crate.

the class PeerFinderTests method testHandlesDiscoveryOfMasterFromResponseFromMaster.

public void testHandlesDiscoveryOfMasterFromResponseFromMaster() {
    final DiscoveryNode otherNode = newDiscoveryNode("node-from-hosts-list");
    providedAddresses.add(otherNode.getAddress());
    transportAddressConnector.addReachableNode(otherNode);
    peerFinder.activate(lastAcceptedNodes);
    runAllRunnableTasks();
    assertFoundPeers(otherNode);
    final long term = randomNonNegativeLong();
    respondToRequests(node -> {
        assertThat(node, is(otherNode));
        return new PeersResponse(Optional.of(otherNode), emptyList(), term);
    });
    runAllRunnableTasks();
    assertFoundPeers(otherNode);
    assertThat(peerFinder.discoveredMasterNode, is(otherNode));
    assertThat(peerFinder.discoveredMasterTerm, is(OptionalLong.of(term)));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse)

Aggregations

PeersResponse (org.elasticsearch.cluster.coordination.PeersResponse)8 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)8 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1 TransportException (org.elasticsearch.transport.TransportException)1