Search in sources :

Example 1 with PeersResponse

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

the class PeerFinderTests method testReceivesRequestsFromTransportService.

public void testReceivesRequestsFromTransportService() {
    final DiscoveryNode sourceNode = newDiscoveryNode("request-source");
    transportAddressConnector.addReachableNode(sourceNode);
    peerFinder.activate(lastAcceptedNodes);
    final AtomicBoolean responseReceived = new AtomicBoolean();
    transportService.sendRequest(localNode, REQUEST_PEERS_ACTION_NAME, new PeersRequest(sourceNode, Collections.emptyList()), new TransportResponseHandler<PeersResponse>() {

        @Override
        public PeersResponse read(StreamInput in) throws IOException {
            return new PeersResponse(in);
        }

        @Override
        public void handleResponse(PeersResponse response) {
            assertTrue(responseReceived.compareAndSet(false, true));
            assertFalse(response.getMasterNode().isPresent());
            // sourceNode is not yet known
            assertThat(response.getKnownPeers(), empty());
            assertThat(response.getTerm(), is(0L));
        }

        @Override
        public void handleException(TransportException exp) {
            throw new AssertionError("unexpected", exp);
        }

        @Override
        public String executor() {
            return Names.SAME;
        }
    });
    runAllRunnableTasks();
    assertTrue(responseReceived.get());
    assertFoundPeers(sourceNode);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse) StreamInput(org.elasticsearch.common.io.stream.StreamInput) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException)

Example 2 with PeersResponse

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

the class PeerFinderTests method testOnlyRequestsPeersOncePerRoundButDoesRetryNextRound.

public void testOnlyRequestsPeersOncePerRoundButDoesRetryNextRound() {
    final DiscoveryNode sourceNode = newDiscoveryNode("request-source");
    transportAddressConnector.addReachableNode(sourceNode);
    peerFinder.activate(lastAcceptedNodes);
    peerFinder.handlePeersRequest(new PeersRequest(sourceNode, emptyList()));
    runAllRunnableTasks();
    assertFoundPeers(sourceNode);
    respondToRequests(node -> {
        assertThat(node, is(sourceNode));
        return new PeersResponse(Optional.empty(), singletonList(sourceNode), randomNonNegativeLong());
    });
    peerFinder.handlePeersRequest(new PeersRequest(sourceNode, emptyList()));
    runAllRunnableTasks();
    respondToRequests(node -> {
        throw new AssertionError("there should have been no further requests");
    });
    final DiscoveryNode otherNode = newDiscoveryNode("otherNode");
    transportAddressConnector.addReachableNode(otherNode);
    deterministicTaskQueue.advanceTime();
    runAllRunnableTasks();
    respondToRequests(node -> {
        assertThat(node, is(sourceNode));
        return new PeersResponse(Optional.empty(), singletonList(otherNode), randomNonNegativeLong());
    });
    runAllRunnableTasks();
    assertFoundPeers(sourceNode, otherNode);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse)

Example 3 with PeersResponse

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

the class PeerFinderTests method testRespondsToRequestWhenActive.

public void testRespondsToRequestWhenActive() {
    final DiscoveryNode sourceNode = newDiscoveryNode("request-source");
    transportAddressConnector.addReachableNode(sourceNode);
    peerFinder.activate(lastAcceptedNodes);
    final PeersResponse peersResponse1 = peerFinder.handlePeersRequest(new PeersRequest(sourceNode, Collections.emptyList()));
    assertFalse(peersResponse1.getMasterNode().isPresent());
    // sourceNode is not yet known
    assertThat(peersResponse1.getKnownPeers(), empty());
    assertThat(peersResponse1.getTerm(), is(0L));
    runAllRunnableTasks();
    assertFoundPeers(sourceNode);
    final long updatedTerm = randomNonNegativeLong();
    peerFinder.setCurrentTerm(updatedTerm);
    final PeersResponse peersResponse2 = peerFinder.handlePeersRequest(new PeersRequest(sourceNode, Collections.emptyList()));
    assertFalse(peersResponse2.getMasterNode().isPresent());
    assertThat(peersResponse2.getKnownPeers(), contains(sourceNode));
    assertThat(peersResponse2.getTerm(), is(updatedTerm));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse)

Example 4 with PeersResponse

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

the class PeerFinderTests method testDelegatesRequestHandlingWhenInactive.

public void testDelegatesRequestHandlingWhenInactive() {
    final DiscoveryNode masterNode = newDiscoveryNode("master-node");
    final DiscoveryNode sourceNode = newDiscoveryNode("request-source");
    transportAddressConnector.addReachableNode(sourceNode);
    peerFinder.activate(DiscoveryNodes.EMPTY_NODES);
    final long term = randomNonNegativeLong();
    peerFinder.setCurrentTerm(term);
    peerFinder.deactivate(masterNode);
    final PeersResponse expectedResponse = new PeersResponse(Optional.of(masterNode), Collections.emptyList(), term);
    final PeersResponse peersResponse = peerFinder.handlePeersRequest(new PeersRequest(sourceNode, Collections.emptyList()));
    assertThat(peersResponse, equalTo(expectedResponse));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) PeersResponse(org.elasticsearch.cluster.coordination.PeersResponse)

Example 5 with PeersResponse

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

the class PeerFinderTests method testAddsReachableMasterFromResponse.

public void testAddsReachableMasterFromResponse() {
    final DiscoveryNode otherNode = newDiscoveryNode("node-from-hosts-list");
    providedAddresses.add(otherNode.getAddress());
    transportAddressConnector.addReachableNode(otherNode);
    peerFinder.activate(lastAcceptedNodes);
    runAllRunnableTasks();
    assertFoundPeers(otherNode);
    final DiscoveryNode discoveredMaster = newDiscoveryNode("discovered-master");
    respondToRequests(node -> {
        assertThat(node, is(otherNode));
        return new PeersResponse(Optional.of(discoveredMaster), emptyList(), randomNonNegativeLong());
    });
    transportAddressConnector.addReachableNode(discoveredMaster);
    runAllRunnableTasks();
    assertFoundPeers(otherNode, discoveredMaster);
    assertThat(peerFinder.discoveredMasterNode, nullValue());
    assertFalse(peerFinder.discoveredMasterTerm.isPresent());
}
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