Search in sources :

Example 1 with CapturedRequest

use of org.elasticsearch.test.transport.CapturingTransport.CapturedRequest in project crate by crate.

the class PeerFinderTests method testRequestsPeersIncludingKnownPeersInRequest.

public void testRequestsPeersIncludingKnownPeersInRequest() {
    final DiscoveryNode otherNode = newDiscoveryNode("node-from-hosts-list");
    providedAddresses.add(otherNode.getAddress());
    transportAddressConnector.addReachableNode(otherNode);
    peerFinder.activate(lastAcceptedNodes);
    runAllRunnableTasks();
    assertFoundPeers(otherNode);
    final CapturedRequest[] capturedRequests = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests.length, is(1));
    final PeersRequest peersRequest = (PeersRequest) capturedRequests[0].request;
    assertThat(peersRequest.getKnownPeers(), contains(otherNode));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) CapturedRequest(org.elasticsearch.test.transport.CapturingTransport.CapturedRequest)

Example 2 with CapturedRequest

use of org.elasticsearch.test.transport.CapturingTransport.CapturedRequest in project crate by crate.

the class PeerFinderTests method respondToRequests.

private void respondToRequests(Function<DiscoveryNode, PeersResponse> responseFactory) {
    final CapturedRequest[] capturedRequests = capturingTransport.getCapturedRequestsAndClear();
    for (final CapturedRequest capturedRequest : capturedRequests) {
        assertThat(capturedRequest.action, is(REQUEST_PEERS_ACTION_NAME));
        assertThat(capturedRequest.request, instanceOf(PeersRequest.class));
        final PeersRequest peersRequest = (PeersRequest) capturedRequest.request;
        assertThat(peersRequest.getSourceNode(), is(localNode));
        capturingTransport.handleResponse(capturedRequests[0].requestId, responseFactory.apply(capturedRequest.node));
    }
}
Also used : CapturedRequest(org.elasticsearch.test.transport.CapturingTransport.CapturedRequest)

Example 3 with CapturedRequest

use of org.elasticsearch.test.transport.CapturingTransport.CapturedRequest in project crate by crate.

the class JoinHelperTests method testJoinDeduplication.

public void testJoinDeduplication() {
    DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(Settings.builder().put(NODE_NAME_SETTING.getKey(), "node0").build(), random());
    CapturingTransport capturingTransport = new CapturingTransport();
    DiscoveryNode localNode = new DiscoveryNode("node0", buildNewFakeTransportAddress(), Version.CURRENT);
    TransportService transportService = capturingTransport.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), x -> localNode, null);
    JoinHelper joinHelper = new JoinHelper(Settings.EMPTY, null, null, transportService, () -> 0L, () -> null, (joinRequest, joinCallback) -> {
        throw new AssertionError();
    }, startJoinRequest -> {
        throw new AssertionError();
    }, Collections.emptyList(), (s, p, r) -> {
    });
    transportService.start();
    DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), Version.CURRENT);
    assertFalse(joinHelper.isJoinPending());
    // check that sending a join to node1 works
    Optional<Join> optionalJoin1 = randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node1, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    CapturedRequest[] capturedRequests1 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1.length, equalTo(1));
    CapturedRequest capturedRequest1 = capturedRequests1[0];
    assertEquals(node1, capturedRequest1.node);
    assertTrue(joinHelper.isJoinPending());
    // check that sending a join to node2 works
    Optional<Join> optionalJoin2 = randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node2, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node2, optionalJoin2);
    CapturedRequest[] capturedRequests2 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests2.length, equalTo(1));
    CapturedRequest capturedRequest2 = capturedRequests2[0];
    assertEquals(node2, capturedRequest2.node);
    // check that sending another join to node1 is a noop as the previous join is still in progress
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    assertThat(capturingTransport.getCapturedRequestsAndClear().length, equalTo(0));
    // complete the previous join to node1
    if (randomBoolean()) {
        capturingTransport.handleResponse(capturedRequest1.requestId, TransportResponse.Empty.INSTANCE);
    } else {
        capturingTransport.handleRemoteError(capturedRequest1.requestId, new CoordinationStateRejectedException("dummy"));
    }
    // check that sending another join to node1 now works again
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    CapturedRequest[] capturedRequests1a = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1a.length, equalTo(1));
    CapturedRequest capturedRequest1a = capturedRequests1a[0];
    assertEquals(node1, capturedRequest1a.node);
    // check that sending another join to node2 works if the optionalJoin is different
    Optional<Join> optionalJoin2a = optionalJoin2.isPresent() && randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node2, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node2, optionalJoin2a);
    CapturedRequest[] capturedRequests2a = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests2a.length, equalTo(1));
    CapturedRequest capturedRequest2a = capturedRequests2a[0];
    assertEquals(node2, capturedRequest2a.node);
    // complete all the joins and check that isJoinPending is updated
    assertTrue(joinHelper.isJoinPending());
    capturingTransport.handleRemoteError(capturedRequest2.requestId, new CoordinationStateRejectedException("dummy"));
    capturingTransport.handleRemoteError(capturedRequest1a.requestId, new CoordinationStateRejectedException("dummy"));
    capturingTransport.handleRemoteError(capturedRequest2a.requestId, new CoordinationStateRejectedException("dummy"));
    assertFalse(joinHelper.isJoinPending());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportService(org.elasticsearch.transport.TransportService) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) CapturedRequest(org.elasticsearch.test.transport.CapturingTransport.CapturedRequest)

Aggregations

CapturedRequest (org.elasticsearch.test.transport.CapturingTransport.CapturedRequest)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 CapturingTransport (org.elasticsearch.test.transport.CapturingTransport)1 TransportService (org.elasticsearch.transport.TransportService)1