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);
}
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);
}
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));
}
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));
}
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());
}
Aggregations