Search in sources :

Example 1 with CapturedRequest

use of org.opensearch.test.transport.CapturingTransport.CapturedRequest in project OpenSearch by opensearch-project.

the class JoinHelperTests method testJoinFailureOnUnhealthyNodes.

public void testJoinFailureOnUnhealthyNodes() {
    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(), TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> localNode, null, Collections.emptySet());
    AtomicReference<StatusInfo> nodeHealthServiceStatus = new AtomicReference<>(new StatusInfo(UNHEALTHY, "unhealthy-info"));
    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) -> {
    }, () -> nodeHealthServiceStatus.get());
    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 doesn't work
    Optional<Join> optionalJoin1 = randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node1, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node1, randomNonNegativeLong(), optionalJoin1);
    CapturedRequest[] capturedRequests1 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1.length, equalTo(0));
    assertFalse(joinHelper.isJoinPending());
    // check that sending a join to node2 doesn't work
    Optional<Join> optionalJoin2 = randomBoolean() ? Optional.empty() : Optional.of(new Join(localNode, node2, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    transportService.start();
    joinHelper.sendJoinRequest(node2, randomNonNegativeLong(), optionalJoin2);
    CapturedRequest[] capturedRequests2 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests2.length, equalTo(0));
    assertFalse(joinHelper.isJoinPending());
    nodeHealthServiceStatus.getAndSet(new StatusInfo(HEALTHY, "healthy-info"));
    // check that sending another join to node1 now works again
    joinHelper.sendJoinRequest(node1, 0L, optionalJoin1);
    CapturedRequest[] capturedRequests1a = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1a.length, equalTo(1));
    CapturedRequest capturedRequest1a = capturedRequests1a[0];
    assertEquals(node1, capturedRequest1a.node);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) CapturingTransport(org.opensearch.test.transport.CapturingTransport) AtomicReference(java.util.concurrent.atomic.AtomicReference) CapturedRequest(org.opensearch.test.transport.CapturingTransport.CapturedRequest) TransportService(org.opensearch.transport.TransportService) StatusInfo(org.opensearch.monitor.StatusInfo)

Example 2 with CapturedRequest

use of org.opensearch.test.transport.CapturingTransport.CapturedRequest in project OpenSearch by opensearch-project.

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(), TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> localNode, null, Collections.emptySet());
    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) -> {
    }, () -> new StatusInfo(HEALTHY, "info"));
    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, 0L, 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, 0L, 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, 0L, 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, 0L, 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, 0L, 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.opensearch.cluster.node.DiscoveryNode) TransportService(org.opensearch.transport.TransportService) StatusInfo(org.opensearch.monitor.StatusInfo) CapturingTransport(org.opensearch.test.transport.CapturingTransport) CapturedRequest(org.opensearch.test.transport.CapturingTransport.CapturedRequest)

Example 3 with CapturedRequest

use of org.opensearch.test.transport.CapturingTransport.CapturedRequest in project OpenSearch by opensearch-project.

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.opensearch.test.transport.CapturingTransport.CapturedRequest)

Example 4 with CapturedRequest

use of org.opensearch.test.transport.CapturingTransport.CapturedRequest in project OpenSearch by opensearch-project.

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.opensearch.cluster.node.DiscoveryNode) CapturedRequest(org.opensearch.test.transport.CapturingTransport.CapturedRequest)

Aggregations

CapturedRequest (org.opensearch.test.transport.CapturingTransport.CapturedRequest)4 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)3 StatusInfo (org.opensearch.monitor.StatusInfo)2 CapturingTransport (org.opensearch.test.transport.CapturingTransport)2 TransportService (org.opensearch.transport.TransportService)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1